|
3 | 3 | /*
|
4 | 4 | * This file is part of the Symfony CMF package.
|
5 | 5 | *
|
6 |
| - * (c) 2011-2017 Symfony CMF |
| 6 | + * (c) Symfony CMF |
7 | 7 | *
|
8 | 8 | * For the full copyright and license information, please view the LICENSE
|
9 | 9 | * file that was distributed with this source code.
|
10 | 10 | */
|
11 | 11 |
|
12 | 12 | namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\Doctrine\Orm;
|
13 | 13 |
|
14 |
| -use Symfony\Cmf\Bundle\RoutingBundle\Tests\Functional\BaseTestCase; |
15 |
| -use Symfony\Cmf\Component\Routing\RedirectRouteInterface; |
16 |
| -use Symfony\Cmf\Bundle\RoutingBundle\Model\RedirectRoute; |
| 14 | +use Symfony\Cmf\Bundle\RoutingBundle\Controller\RedirectController; |
| 15 | +use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\RedirectRoute; |
| 16 | +use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route; |
| 17 | +use Symfony\Component\HttpFoundation\RedirectResponse; |
17 | 18 |
|
18 | 19 | class RedirectRouteTest extends OrmTestCase
|
19 | 20 | {
|
20 | 21 | private $repository;
|
21 | 22 |
|
| 23 | + private $controller; |
| 24 | + |
22 | 25 | public function setUp()
|
23 | 26 | {
|
24 | 27 | parent::setUp();
|
25 | 28 | $this->clearDb(Route::class);
|
26 | 29 | $this->clearDb(RedirectRoute::class);
|
27 | 30 |
|
28 | 31 | $this->repository = $this->getContainer()->get('cmf_routing.route_provider');
|
| 32 | + $this->controller = new RedirectController($this->getContainer()->get('router')); |
29 | 33 | }
|
30 | 34 |
|
31 | 35 | public function testRedirectDoctrine()
|
32 | 36 | {
|
33 | 37 | $route = $this->createRoute('route1', '/test');
|
34 | 38 |
|
35 | 39 | $redirectRouteDoc = new RedirectRoute();
|
36 |
| - $redirectRouteDoc->setRouteName("redirect1"); |
| 40 | + $redirectRouteDoc->setRouteName('redirect1'); |
37 | 41 | $redirectRouteDoc->setRouteTarget($route);
|
38 | 42 | $redirectRouteDoc->setPermanent(true);
|
39 | 43 |
|
| 44 | + $this->getDm()->persist($redirectRouteDoc); |
40 | 45 | $this->getDm()->flush();
|
41 | 46 |
|
42 |
| - $redirectRoute = new Route(); |
43 |
| - $redirectRoute->setName("redirect1"); |
44 |
| - $redirectRoute->setStaticPrefix('/redirect'); |
| 47 | + $redirectRoute = $this->createRoute('redirect1', '/redirect'); |
45 | 48 | $redirectRoute->setContent($redirectRouteDoc);
|
46 | 49 |
|
47 | 50 | $this->getDm()->flush();
|
48 | 51 | $this->getDm()->clear();
|
49 | 52 |
|
50 |
| - $route1 = $this->repository->getRouteByName('route1'); |
51 |
| - $redirect1 = $this->repository->getRouteByName('redirect1'); |
52 |
| - $this->assertInstanceOf(Route::class, $route1); |
53 |
| - $this->assertInstanceOf(RedirectRouteInterface::class, $redirect1); |
| 53 | + $response = $this->controller->redirectAction($redirectRoute->getContent()); |
54 | 54 |
|
55 |
| - $this->assertSame($route1, $redirect1->getContent()->getRouteTarget()); |
| 55 | + $this->assertInstanceOf(RedirectResponse::class, $response); |
| 56 | + $this->assertSame(301, $response->getStatusCode()); |
| 57 | + $this->assertSame('http://localhost/test', $response->getTargetUrl()); |
56 | 58 | }
|
57 |
| - |
58 | 59 | }
|
0 commit comments