Skip to content

Commit

Permalink
apply suggestions from code review: removed testForceGlobalPasswordRe…
Browse files Browse the repository at this point in the history
…set() from UserIdentityModelTest
  • Loading branch information
sammyskills committed Jan 16, 2023
1 parent 44a7e59 commit b30dd31
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
26 changes: 26 additions & 0 deletions tests/Authentication/ForcePasswordResetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use CodeIgniter\Shield\Models\UserModel;
use CodeIgniter\Shield\Test\AuthenticationTesting;
use CodeIgniter\Test\DatabaseTestTrait;
use CodeIgniter\Test\Fabricator;
use CodeIgniter\Test\FeatureTestTrait;
use Config\Services;
use Tests\Support\TestCase;
Expand Down Expand Up @@ -100,4 +101,29 @@ public function testRequiresPasswordResetRedirect(): void
$result->assertStatus(302);
$result->assertRedirectTo(config('Auth')->forcePasswordResetRedirect());
}

public function testForceGlobalPasswordReset(): void
{
/**
* @phpstan-var User
*/
$user = fake(UserModel::class);
$user->createEmailIdentity(['email' => 'foo@example.com', 'password' => 'secret123']);
$this->actingAs($user);

/**
* @phpstan-var Fabricator
*/
$fabricator = new Fabricator(UserIdentityModel::class);
$fabricator->create(100);

/**
* @phpstan-var UserIdentityModel
*/
$identities = model(UserIdentityModel::class);

$response = $identities->forceGlobalPasswordReset();
$this->assertTrue($response);
$this->assertFalse($user->requiresPasswordReset());
}
}
27 changes: 0 additions & 27 deletions tests/Unit/UserIdentityModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use CodeIgniter\Shield\Models\DatabaseException;
use CodeIgniter\Shield\Models\UserIdentityModel;
use CodeIgniter\Shield\Models\UserModel;
use CodeIgniter\Shield\Test\AuthenticationTesting;
use CodeIgniter\Test\DatabaseTestTrait;
use CodeIgniter\Test\Fabricator;
use Tests\Support\TestCase;
Expand All @@ -20,7 +19,6 @@
final class UserIdentityModelTest extends TestCase
{
use DatabaseTestTrait;
use AuthenticationTesting;

protected $namespace;
protected $refresh = true;
Expand Down Expand Up @@ -98,29 +96,4 @@ public function testForceMultiplePasswordReset(): void
$response = $identities->forceMultiplePasswordReset($userIds);
$this->assertTrue($response);
}

public function testforceGlobalPasswordReset(): void
{
/**
* @phpstan-var User
*/
$user = fake(UserModel::class);
$user->createEmailIdentity(['email' => 'foo@example.com', 'password' => 'secret123']);
$this->actingAs($user);

/**
* @phpstan-var Fabricator
*/
$fabricator = new Fabricator(UserIdentityModel::class);
$fabricator->create(100);

/**
* @phpstan-var UserIdentityModel
*/
$identities = model(UserIdentityModel::class);

$response = $identities->forceGlobalPasswordReset();
$this->assertTrue($response);
$this->assertFalse($user->requiresPasswordReset());
}
}

0 comments on commit b30dd31

Please sign in to comment.