Skip to content

Commit 7691e50

Browse files
committed
update login test
1 parent 2b0c09f commit 7691e50

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

tests/Controllers/LoginTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use CodeIgniter\Config\Factories;
66
use CodeIgniter\I18n\Time;
77
use CodeIgniter\Shield\Authentication\Actions\Email2FA;
8+
use CodeIgniter\Shield\Config\Auth;
89
use CodeIgniter\Test\DatabaseTestTrait;
910
use CodeIgniter\Test\FeatureTestTrait;
1011
use Config\Services;
@@ -73,6 +74,7 @@ public function testLoginActionEmailSuccess(): void
7374
'password' => 'secret123',
7475
]);
7576

77+
$result->assertSessionHas('user', ['id' => 1]);
7678
$result->assertStatus(302);
7779
$result->assertRedirect();
7880
$this->assertSame(site_url(), $result->getRedirectUrl());
@@ -109,6 +111,14 @@ public function testAfterLoggedInNotDesplayLoginPage(): void
109111

110112
public function testLoginActionUsernameSuccess(): void
111113
{
114+
// Change the validation rules
115+
$config = new Auth();
116+
$config->loginRules = [
117+
'username' => 'required|max_length[30]|alpha_numeric_space|min_length[3]',
118+
'password' => 'required',
119+
];
120+
Factories::injectMock('config', 'Auth', $config);
121+
112122
$this->user->createEmailIdentity([
113123
'email' => 'foo@example.com',
114124
'password' => 'secret123',
@@ -119,6 +129,7 @@ public function testLoginActionUsernameSuccess(): void
119129
'password' => 'secret123',
120130
]);
121131

132+
$result->assertSessionHas('user', ['id' => 1]);
122133
$result->assertStatus(302);
123134
$result->assertRedirect();
124135
$this->assertSame(site_url(), $result->getRedirectUrl());

0 commit comments

Comments
 (0)