Backup of db before drupal security update
[yaffs-website] / vendor / symfony-cmf / routing / Tests / Enhancer / RouteContentEnhancerTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony CMF package.
5  *
6  * (c) 2011-2015 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\Component\Routing\Tests\Enhancer;
13
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;
18
19 class RouteContentEnhancerTest extends CmfUnitTestCase
20 {
21     /**
22      * @var RouteContentEnhancer
23      */
24     private $mapper;
25     private $document;
26     private $request;
27
28     public function setUp()
29     {
30         $this->document = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Enhancer\RouteObject',
31                                             array('getContent', 'getRouteDefaults', 'getUrl'));
32
33         $this->mapper = new RouteContentEnhancer(RouteObjectInterface::ROUTE_OBJECT, '_content');
34
35         $this->request = Request::create('/test');
36     }
37
38     public function testContent()
39     {
40         $targetDocument = new TargetDocument();
41         $this->document->expects($this->once())
42             ->method('getContent')
43             ->will($this->returnValue($targetDocument));
44
45         $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document);
46         $expected = array(RouteObjectInterface::ROUTE_OBJECT => $this->document, '_content' => $targetDocument);
47
48         $this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
49     }
50
51     public function testFieldAlreadyThere()
52     {
53         $this->document->expects($this->never())
54             ->method('getContent')
55         ;
56
57         $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document, '_content' => 'foo');
58
59         $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
60     }
61
62     public function testNoContent()
63     {
64         $this->document->expects($this->once())
65             ->method('getContent')
66             ->will($this->returnValue(null));
67
68         $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document);
69         $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
70     }
71
72     public function testNoCmfRoute()
73     {
74         $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->buildMock('Symfony\Component\Routing\Route'));
75         $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
76     }
77 }
78
79 class TargetDocument
80 {
81 }
82
83 class UnknownDocument
84 {
85 }