55use CodeIgniter \Config \Factories ;
66use CodeIgniter \I18n \Time ;
77use CodeIgniter \Shield \Authentication \Actions \Email2FA ;
8+ use CodeIgniter \Shield \Config \Auth ;
89use CodeIgniter \Test \DatabaseTestTrait ;
910use CodeIgniter \Test \FeatureTestTrait ;
1011use 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