|
27 | 27 | use Authentication\Test\TestCase\AuthenticationTestCase as TestCase; |
28 | 28 | use Cake\Controller\ComponentRegistry; |
29 | 29 | use Cake\Controller\Controller; |
| 30 | +use Cake\Core\Configure; |
30 | 31 | use Cake\Event\Event; |
31 | 32 | use Cake\Event\EventManager; |
32 | 33 | use Cake\Http\ServerRequestFactory; |
33 | 34 | use Cake\ORM\Entity; |
| 35 | +use Cake\Routing\Router; |
34 | 36 | use InvalidArgumentException; |
35 | 37 | use TestApp\Authentication\InvalidAuthenticationService; |
36 | 38 | use UnexpectedValueException; |
@@ -357,18 +359,33 @@ public function testLogout() |
357 | 359 | */ |
358 | 360 | public function testGetLoginRedirect() |
359 | 361 | { |
| 362 | + Configure::write('App.base', '/cakephp'); |
| 363 | + $url = ['controller' => 'Users', 'action' => 'dashboard']; |
| 364 | + Router::createRouteBuilder('/') |
| 365 | + ->connect('/dashboard', $url); |
| 366 | + |
360 | 367 | $this->service->setConfig('queryParam', 'redirect'); |
361 | 368 | $request = $this->request |
362 | 369 | ->withAttribute('identity', $this->identity) |
363 | | - ->withAttribute('authentication', $this->service) |
364 | | - ->withQueryParams(['redirect' => 'ok/path?value=key']); |
| 370 | + ->withAttribute('authentication', $this->service); |
| 371 | + |
| 372 | + $controller = new Controller($request); |
| 373 | + $registry = new ComponentRegistry($controller); |
| 374 | + $component = new AuthenticationComponent($registry); |
| 375 | + |
| 376 | + $result = $component->getLoginRedirect($url); |
| 377 | + $this->assertSame('/dashboard', $result); |
| 378 | + |
| 379 | + $request = $request->withQueryParams(['redirect' => 'ok/path?value=key']); |
365 | 380 |
|
366 | 381 | $controller = new Controller($request); |
367 | 382 | $registry = new ComponentRegistry($controller); |
368 | 383 | $component = new AuthenticationComponent($registry); |
369 | 384 |
|
370 | | - $result = $component->getLoginRedirect(); |
| 385 | + $result = $component->getLoginRedirect($url); |
371 | 386 | $this->assertSame('/ok/path?value=key', $result); |
| 387 | + |
| 388 | + Configure::delete('App.base'); |
372 | 389 | } |
373 | 390 |
|
374 | 391 | /** |
|
0 commit comments