<commit_before><?php

use App\Models\Access\User\User;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification;
use App\Events\Backend\Access\User\UserCreated;
use App\Events\Backend\Access\User\UserUpdated;
use App\Events\Backend\Access\User\UserDeleted;
use App\Events\Backend\Access\User\UserPasswordChanged;
use App\Notifications\Frontend\Auth\UserNeedsConfirmation;

/**
 * Class UserFormTest
 */
class UserFormTest extends TestCase
{
	public function testCreateUserRequiredFields() {
		$this->actingAs($this->admin)
			->visit('/admin/access/user/create')
			->type('', 'name')
			->type('', 'email')
			->type('', 'password')
			->type('', 'password_confirmation')
			->press('Create')
			->see('The name field is required.')
			->see('The email field is required.')
			->see('The password field is required.');
	}

	public function testCreateUserPasswordsDoNotMatch() {
		$this->actingAs($this->admin)
			->visit('/admin/access/user/create')
			->type('Test User', 'name')
			->type('<EMAIL>', 'email')
			->type('123456', 'password')
			->type('1234567', 'password_confirmation')
			->press('Create')
			->see('The password confirmation does not match.');
	}

	public function testCreateUserConfirmedForm() {
		// Make sure our events are fired
		Event::fake();

		// Create any needed resources
		$faker = Faker\Factory::create();
		$name = $faker->name;
		$email = $faker->safeEmail;
		$password = $faker->password(8);
    $userTable = config('access.users_table');
    $roleUserTable = config('access.role_user_table');

    $this->actingAs($this->admin)
			->visit('/admin/access/user/create')
			->type($name, 'name')
			->type($email, 'email')
			->type($password, 'password')
			->type($password, 'password_confirmation')
			->seeIsChecked('status')
			->seeIsChecked('confirmed')
			->dontSeeIsChecked('confirmation_email')
			->check('assignees_roles[2]')
			->check('assignees_roles[3]')
			->press('Create')
			->seePageIs('/admin/access/user')
			->see('The user was successfully created.')
			->seeInDatabase($userTable, ['name' => $name, 'email' => $email, 'status' => 1, 'confirmed' => 1])
			->seeInDatabase($roleUserTable, ['user_id' => 40, 'role_id' => 2])
			->seeInDatabase($roleUserTable, ['user_id' => 40, 'role_id' => 3]);

		Event::assertFired(UserCreated::class);
	}

	public function testCreateUserUnconfirmedForm() {
		// Make sure our events are fired
		Event::fake();

		// Make sure our notifications are sent
		Notification::fake();

		// Create any needed resources
		$faker = Faker\Factory::create();
		$name = $faker->name;
		$email = $faker->safeEmail;
		$password = $<PASSWORD>(8);

		$this->actingAs($this->admin)
			->visit('/admin/access/user/create')
			->type($name, 'name')
			->type($email, 'email')
			->type($password, 'password')
			->type($password, '<PASSWORD>')
			->seeIsChecked('status')
			->uncheck('confirmed')
			->check('confirmation_email')
			->check('assignees_roles[2]')
			->check('assignees_roles[3]')
			->press('Create')
			->seePageIs('/admin/access/user')
			->see('The user was successfully created.')
			->seeInDatabase($this->userTable, ['name' => $name, 'email' => $email, 'status' => 1, 'confirmed' => 0])
			->seeInDatabase($this->roleUserTable, ['user_id' => 41, 'role_id' => 2])
			->seeInDatabase($this->roleUserTable, ['user_id' => 41, 'role_id' => 3]);

		// Get the user that was inserted into the database
		$user = User::where('email', $email)->first();

		// Check that the user was sent the confirmation email
		Notification::assertSentTo(
			[$user], UserNeedsConfirmation::class
		);

		Event::assertFired(UserCreated::class);
	}

	public function testCreateUserFailsIfNameExists() {
    $this->markTestSkipped('must be revisited.');
		$this->actingAs($this->admin)
			->visit('/admin/access/user/create')
			->type('User', 'name')
			->type('<EMAIL>', 'email')
			->type('123456', 'password')
			->type('123456', 'password_confirmation')
        ->check('assignees_roles[3]')
			->press('Create')
			->seePageIs('/admin/access/user/create')
			->see('The email has already been taken.');
	}

	public function testUpdateUserRequiredFields() {
		$this->actingAs($this->admin)<commit_msg>fix userFormTest<commit_after><?php

use App\Models\Access\User\User;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification;
use App\Events\Backend\Access\User\UserCreated;
use App\Events\Backend\Access\User\UserUpdated;
use App\Events\Backend\Access\User\UserDeleted;
use App\Events\Backend\Access\User\UserPasswordChanged;
use App\Notifications\Frontend\Auth\UserNeedsConfirmation;

/**
 * Class UserFormTest
 */
class UserFormTest extends TestCase
{
	public function testCreateUserRequiredFields() {
		$this->actingAs($this->admin)
			->visit('/admin/access/user/create')
			->type('', 'name')
			->type('', 'email')
			->type('', 'password')
			->type('', 'password_confirmation')
			->press('Create')
			->see('The name field is required.')
			->see('The email field is required.')
			->see('The password field is required.');
	}

	public function testCreateUserPasswordsDoNotMatch() {
		$this->actingAs($this->admin)
			->visit('/admin/access/user/create')
			->type('Test User', 'name')
			->type('<EMAIL>', 'email')
			->type('123456', 'password')
			->type('1234567', 'password_confirmation')
			->press('Create')
			->see('The password confirmation does not match.');
	}

	public function testCreateUserConfirmedForm() {
		// Make sure our events are fired
		Event::fake();

		// Create any needed resources
		$faker = Faker\Factory::create();
		$name = $faker->name;
		$email = $faker->safeEmail;
		$password = $<PASSWORD>(8);
    $userTable = config('access.users_table');
    $roleUserTable = config('access.role_user_table');

    $this->actingAs($this->admin)
			->visit('/admin/access/user/create')
			->type($name, 'name')
			->type($email, 'email')
			->type($password, 'password')
			->type($password, 'password_confirmation')
			->seeIsChecked('status')
			->seeIsChecked('confirmed')
			->dontSeeIsChecked('confirmation_email')
			->check('assignees_roles[2]')
			->check('assignees_roles[3]')
			->press('Create')
			->seePageIs('/admin/access/user')
			->see('The user was successfully created.')
			->seeInDatabase($userTable, ['name' => $name, 'email' => $email, 'status' => 1, 'confirmed' => 1])
			->seeInDatabase($roleUserTable, ['user_id' => 40, 'role_id' => 2])
			->seeInDatabase($roleUserTable, ['user_id' => 40, 'role_id' => 3]);

		Event::assertFired(UserCreated::class);
	}

	public function testCreateUserUnconfirmedForm() {
		// Make sure our events are fired
		Event::fake();

		// Make sure our notifications are sent
		Notification::fake();

		// Create any needed resources
		$faker = Faker\Factory::create();
		$name = $faker->name;
		$email = $faker->safeEmail;
		$password = $<PASSWORD>->password(8);

		$this->actingAs($this->admin)
			->visit('/admin/access/user/create')
			->type($name, 'name')
			->type($email, 'email')
			->type($password, 'password')
			->type($password, 'password_confirmation')
			->seeIsChecked('status')
			->uncheck('confirmed')
			->check('confirmation_email')
			->check('assignees_roles[2]')
			->check('assignees_roles[3]')
			->press('Create')
			->seePageIs('/admin/access/user')
			->see('The user was successfully created.')
			->seeInDatabase($this->userTable, ['name' => $name, 'email' => $email, 'status' => 1, 'confirmed' => 0])
			->seeInDatabase($this->roleUserTable, ['user_id' => 41, 'role_id' => 2])
			->seeInDatabase($this->roleUserTable, ['user_id' => 41, 'role_id' => 3]);

		// Get the user that was inserted into the database
		$user = User::where('email', $email)->first();

		// Check that the user was sent the confirmation email
		Notification::assertSentTo(
			[$user], UserNeedsConfirmation::class
		);

		Event::assertFired(UserCreated::class);
	}


  public function testCreateUserFailsIfNameExists()
  {
//    $this->markTestSkipped('Must be revisited:');
    $this->actingAs($this->admin)
        ->visit('/admin/access/user/create')
        ->type('defaultuser', 'name')
        ->type('<EMAIL>', 'email')
        ->type('123456', 'password')
        ->type('<PASSWORD>', 'password_confirmation')
        ->check('assignees_roles[3]');
    $this->press('Create');
    $this->seePageIs('/admin/access/user/create')
        ->see('The name has already been taken.');
  }

	public function testUpdateUserRequiredFields() {
		$this->actingAs($this->admin)
{'fraction_non_alphanumeric': 0.19477154969382948, 'fraction_numerical': 0.010598210080075365, 'mean_word_length': 4.402671755725191, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 202, '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': '1216486', 'n_tokens_mistral': 3114, 'n_tokens_neox': 2741, 'n_words': 530}