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