@@ -25,7 +25,7 @@ public function testRegistration()
2525 $ this ->assertTrue (app ()->register ('Adldap\Laravel\AdldapAuthServiceProvider ' ));
2626 }
2727
28- public function testAuth ()
28+ public function testAuthPasses ()
2929 {
3030 // Get around E Strict warning about mockery's __call signature being different
3131 if (defined ('E_STRICT ' )) error_reporting ('E_ALL ^ E_STRICT ' );
@@ -52,11 +52,62 @@ public function testAuth()
5252 Adldap::shouldReceive ('users ' )->once ()->andReturn ($ mockedUsers );
5353 Adldap::shouldReceive ('authenticate ' )->once ()->andReturn (true );
5454
55- Auth::attempt (['mail ' => 'jdoe@email.com ' , 'password ' => '12345 ' ]);
55+ $ this -> assertTrue ( Auth::attempt (['mail ' => 'jdoe@email.com ' , 'password ' => '12345 ' ]) );
5656
5757 $ user = \DB ::table ('users ' )->where ('id ' , '= ' , 1 )->first ();
5858
5959 $ this ->assertEquals ('jdoe@email.com ' , $ user ->email );
6060 $ this ->assertTrue (\Hash::check ('12345 ' , $ user ->password ));
6161 }
62+
63+ public function testAuthFails ()
64+ {
65+ // Get around E Strict warning about mockery's __call signature being different
66+ if (defined ('E_STRICT ' )) error_reporting ('E_ALL ^ E_STRICT ' );
67+
68+ $ mockedBuilder = Mockery::mock ('Adldap\Query\Builder ' );
69+
70+ $ mockedSearch = Mockery::mock ('Adldap\Classes\Search ' );
71+
72+ $ mockedUsers = Mockery::mock ('Adldap\Classes\Users ' );
73+
74+ $ mockedSearch ->shouldReceive ('first ' )->once ()->andReturn (null );
75+ $ mockedSearch ->shouldReceive ('whereEquals ' )->once ()->andReturn ($ mockedBuilder );
76+
77+ $ mockedUsers ->shouldReceive ('search ' )->once ()->andReturn ($ mockedSearch );
78+
79+ Adldap::shouldReceive ('users ' )->once ()->andReturn ($ mockedUsers );
80+
81+ $ this ->assertFalse (Auth::attempt (['mail ' => 'jdoe@email.com ' , 'password ' => '12345 ' ]));
82+ }
83+
84+ public function testAuthFailsWhenUserFound ()
85+ {
86+ // Get around E Strict warning about mockery's __call signature being different
87+ if (defined ('E_STRICT ' )) error_reporting ('E_ALL ^ E_STRICT ' );
88+
89+ $ mockedBuilder = Mockery::mock ('Adldap\Query\Builder ' );
90+
91+ $ rawAttributes = [
92+ 'samaccountname ' => ['jdoe ' ],
93+ 'mail ' => ['jdoe@email.com ' ],
94+ 'cn ' => ['John Doe ' ],
95+ ];
96+
97+ $ adUser = (new User ([], $ mockedBuilder ))->setRawAttributes ($ rawAttributes );
98+
99+ $ mockedSearch = Mockery::mock ('Adldap\Classes\Search ' );
100+
101+ $ mockedUsers = Mockery::mock ('Adldap\Classes\Users ' );
102+
103+ $ mockedSearch ->shouldReceive ('first ' )->once ()->andReturn ($ adUser );
104+ $ mockedSearch ->shouldReceive ('whereEquals ' )->once ()->andReturn ($ mockedBuilder );
105+
106+ $ mockedUsers ->shouldReceive ('search ' )->once ()->andReturn ($ mockedSearch );
107+
108+ Adldap::shouldReceive ('users ' )->once ()->andReturn ($ mockedUsers );
109+ Adldap::shouldReceive ('authenticate ' )->once ()->andReturn (false );
110+
111+ $ this ->assertFalse (Auth::attempt (['mail ' => 'jdoe@email.com ' , 'password ' => '12345 ' ]));
112+ }
62113}
0 commit comments