fcc56a1bf594ef0910d6aa0757ed972a46d23ae2
[yaffs-website] / vendor / symfony-cmf / routing / Tests / Enhancer / FieldByClassEnhancerTest.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\Test\CmfUnitTestCase;
16 use Symfony\Cmf\Component\Routing\Enhancer\FieldByClassEnhancer;
17
18 class FieldByClassEnhancerTest extends CmfUnitTestCase
19 {
20     private $request;
21     /**
22      * @var FieldByClassEnhancer
23      */
24     private $mapper;
25     private $document;
26
27     public function setUp()
28     {
29         $this->document = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Enhancer\RouteObject');
30
31         $mapping = array('Symfony\Cmf\Component\Routing\Tests\Enhancer\RouteObject' => 'cmf_content.controller:indexAction');
32
33         $this->mapper = new FieldByClassEnhancer('_content', '_controller', $mapping);
34
35         $this->request = Request::create('/test');
36     }
37
38     public function testClassFoundInMapping()
39     {
40         // this is the mock, thus a child class to make sure we properly check with instanceof
41         $defaults = array('_content' => $this->document);
42         $expected = array(
43             '_content' => $this->document,
44             '_controller' => 'cmf_content.controller:indexAction',
45         );
46         $this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
47     }
48
49     public function testFieldAlreadyThere()
50     {
51         $defaults = array(
52             '_content' => $this->document,
53             '_controller' => 'custom.controller:indexAction',
54         );
55         $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
56     }
57
58     public function testClassNotFoundInMapping()
59     {
60         $defaults = array('_content' => $this);
61         $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
62     }
63
64     public function testNoClass()
65     {
66         $defaults = array('foo' => 'bar');
67         $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
68     }
69 }