@@ -46,6 +46,7 @@ public function test_authorization_view_is_presented()
4646 $ session ->shouldReceive ('put ' )->withSomeOfArgs ('authToken ' );
4747 $ session ->shouldReceive ('put ' )->with ('authRequest ' , $ authRequest );
4848 $ request ->shouldReceive ('user ' )->andReturn ($ user = m::mock ());
49+ $ request ->shouldReceive ('get ' )->with ('prompt ' )->andReturn (null );
4950
5051 $ authRequest ->shouldReceive ('getClient->getIdentifier ' )->andReturn (1 );
5152 $ authRequest ->shouldReceive ('getScopes ' )->andReturn ([new Scope ('scope-1 ' )]);
@@ -116,18 +117,21 @@ public function test_request_is_approved_if_valid_token_exists()
116117 $ request ->shouldReceive ('user ' )->once ()->andReturn ($ user = m::mock ());
117118 $ user ->shouldReceive ('getAuthIdentifier ' )->andReturn (1 );
118119 $ request ->shouldNotReceive ('session ' );
120+ $ request ->shouldReceive ('get ' )->with ('prompt ' )->andReturn (null );
119121
120122 $ authRequest ->shouldReceive ('getClient->getIdentifier ' )->once ()->andReturn (1 );
121123 $ authRequest ->shouldReceive ('getScopes ' )->once ()->andReturn ([new Scope ('scope-1 ' )]);
122124 $ authRequest ->shouldReceive ('setUser ' )->once ()->andReturnNull ();
123125 $ authRequest ->shouldReceive ('setAuthorizationApproved ' )->once ()->with (true );
124126
125127 $ clients = m::mock (ClientRepository::class);
126- $ clients ->shouldReceive ('find ' )->with (1 )->andReturn ('client ' );
128+ $ clients ->shouldReceive ('find ' )->with (1 )->andReturn ($ client = m::mock (Client::class));
129+
130+ $ client ->shouldReceive ('skipsAuthorization ' )->andReturn (false );
127131
128132 $ tokens = m::mock (TokenRepository::class);
129133 $ tokens ->shouldReceive ('findValidToken ' )
130- ->with ($ user , ' client ' )
134+ ->with ($ user , $ client )
131135 ->andReturn ($ token = m::mock (Token::class));
132136 $ token ->shouldReceive ('getAttribute ' )->with ('scopes ' )->andReturn (['scope-1 ' ]);
133137
@@ -158,6 +162,7 @@ public function test_request_is_approved_if_client_can_skip_authorization()
158162 $ request ->shouldReceive ('user ' )->once ()->andReturn ($ user = m::mock ());
159163 $ user ->shouldReceive ('getAuthIdentifier ' )->andReturn (1 );
160164 $ request ->shouldNotReceive ('session ' );
165+ $ request ->shouldReceive ('get ' )->with ('prompt ' )->andReturn (null );
161166
162167 $ authRequest ->shouldReceive ('getClient->getIdentifier ' )->once ()->andReturn (1 );
163168 $ authRequest ->shouldReceive ('getScopes ' )->once ()->andReturn ([new Scope ('scope-1 ' )]);
@@ -178,4 +183,48 @@ public function test_request_is_approved_if_client_can_skip_authorization()
178183 m::mock (ServerRequestInterface::class), $ request , $ clients , $ tokens
179184 )->getContent ());
180185 }
186+
187+ public function test_authorization_view_is_presented_if_request_has_prompt_equals_to_consent ()
188+ {
189+ Passport::tokensCan ([
190+ 'scope-1 ' => 'description ' ,
191+ ]);
192+
193+ $ server = m::mock (AuthorizationServer::class);
194+ $ response = m::mock (ResponseFactory::class);
195+
196+ $ controller = new AuthorizationController ($ server , $ response );
197+ $ server ->shouldReceive ('validateAuthorizationRequest ' )
198+ ->andReturn ($ authRequest = m::mock (AuthorizationRequest::class));
199+
200+ $ request = m::mock (Request::class);
201+ $ request ->shouldReceive ('session ' )->andReturn ($ session = m::mock ());
202+ $ session ->shouldReceive ('put ' )->withSomeOfArgs ('authToken ' );
203+ $ session ->shouldReceive ('put ' )->with ('authRequest ' , $ authRequest );
204+ $ request ->shouldReceive ('user ' )->andReturn ($ user = m::mock ());
205+ $ request ->shouldReceive ('get ' )->with ('prompt ' )->andReturn ('consent ' );
206+
207+ $ authRequest ->shouldReceive ('getClient->getIdentifier ' )->once ()->andReturn (1 );
208+ $ authRequest ->shouldReceive ('getScopes ' )->once ()->andReturn ([new Scope ('scope-1 ' )]);
209+
210+ $ clients = m::mock (ClientRepository::class);
211+ $ clients ->shouldReceive ('find ' )->with (1 )->andReturn ($ client = m::mock (Client::class));
212+ $ client ->shouldReceive ('skipsAuthorization ' )->andReturn (false );
213+
214+ $ tokens = m::mock (TokenRepository::class);
215+ $ tokens ->shouldNotReceive ('findValidToken ' );
216+
217+ $ response ->shouldReceive ('view ' )->once ()->andReturnUsing (function ($ view , $ data ) use ($ client , $ user ) {
218+ $ this ->assertSame ('passport::authorize ' , $ view );
219+ $ this ->assertEquals ($ client , $ data ['client ' ]);
220+ $ this ->assertEquals ($ user , $ data ['user ' ]);
221+ $ this ->assertSame ('description ' , $ data ['scopes ' ][0 ]->description );
222+
223+ return 'view ' ;
224+ });
225+
226+ $ this ->assertSame ('view ' , $ controller ->authorize (
227+ m::mock (ServerRequestInterface::class), $ request , $ clients , $ tokens
228+ ));
229+ }
181230}
0 commit comments