4 * This file is part of the Symfony CMF package.
6 * (c) 2011-2015 Symfony CMF
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Cmf\Component\Routing\Tests\Enhancer;
14 use Symfony\Component\HttpFoundation\Request;
15 use Symfony\Cmf\Component\Routing\Enhancer\RouteContentEnhancer;
16 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
17 use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
19 class RouteContentEnhancerTest extends CmfUnitTestCase
22 * @var RouteContentEnhancer
28 public function setUp()
30 $this->document = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Enhancer\RouteObject',
31 array('getContent', 'getRouteDefaults', 'getUrl'));
33 $this->mapper = new RouteContentEnhancer(RouteObjectInterface::ROUTE_OBJECT, '_content');
35 $this->request = Request::create('/test');
38 public function testContent()
40 $targetDocument = new TargetDocument();
41 $this->document->expects($this->once())
42 ->method('getContent')
43 ->will($this->returnValue($targetDocument));
45 $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document);
46 $expected = array(RouteObjectInterface::ROUTE_OBJECT => $this->document, '_content' => $targetDocument);
48 $this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
51 public function testFieldAlreadyThere()
53 $this->document->expects($this->never())
54 ->method('getContent')
57 $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document, '_content' => 'foo');
59 $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
62 public function testNoContent()
64 $this->document->expects($this->once())
65 ->method('getContent')
66 ->will($this->returnValue(null));
68 $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document);
69 $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
72 public function testNoCmfRoute()
74 $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->buildMock('Symfony\Component\Routing\Route'));
75 $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));