<commit_before><?php

namespace ProcessWire\GraphQL\Test\Fields\Auth;

use ProcessWire\GraphQL\Test\GraphQLTestCase;
use ProcessWire\GraphQL\Utils;

class LoginFieldTest extends GraphQLTestCase {

  public function tearDown()
  {
    Utils::session()->logout();
  }

  public function testLoginCredentials()
  {
    $config = Utils::config();
    Utils::session()->login('admin', $config->testUsers['admin']);
    $user = Utils::user();
    $this->assertEquals('admin', $user->name, 'Unable to login via $session->login()');
  }

  public function testLoginSuccess()
  {
    $config = Utils::config();
    $pass = $config->testUsers['admin'];
    $query = "{
      login(username:\"admin\", password:\"<PASSWORD>\") {
        statusCode
        message
      }
    }";
    $res = self::execute($query);
    $this->assertEquals(200, $res->data->login->statusCode, 'Unable to login via GraphQL');
  }

  public function testLoginFailure()
  {
    $config = Utils::config();
    $pass = '<PASSWORD>';
    $query = "{
      login(username:\"admin\", password:\"<PASSWORD>\") {<commit_msg>Fix login tests.<commit_after><?php

namespace ProcessWire\GraphQL\Test\Fields\Auth;

use ProcessWire\GraphQL\Test\GraphQLTestCase;
use ProcessWire\GraphQL\Utils;

class LoginFieldTest extends GraphQLTestCase {

  public function tearDown()
  {
    Utils::session()->logout();
  }

  public function testLoginCredentials()
  {
    $config = Utils::config();
    Utils::session()->login('admin', $config->testUsers['admin']);
    $user = Utils::user();
    $this->assertEquals('admin', $user->name, 'Unable to login via $session->login()');
  }

  public function testLoginSuccess()
  {
    $config = Utils::config();
    $pass = $config->testUsers['admin'];
    $query = "{
      login(name:\"admin\", pass:\"<PASSWORD>\") {
        statusCode
        message
      }
    }";
    $res = self::execute($query);
    $this->assertEquals(200, $res->data->login->statusCode, 'Unable to login via GraphQL');
  }

  public function testLoginFailure()
  {
    $config = Utils::config();
    $pass = '<PASSWORD>';
    $query = "{
      login(name:\"admin\", pass:\"<PASSWORD>\") {
{'fraction_non_alphanumeric': 0.1814385150812065, 'fraction_numerical': 0.0027842227378190253, 'mean_word_length': 3.6266094420600856, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2957977', 'n_tokens_mistral': 677, 'n_tokens_neox': 658, 'n_words': 126}