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\Test\CmfUnitTestCase;
16 use Symfony\Cmf\Component\Routing\Enhancer\FieldByClassEnhancer;
18 class FieldByClassEnhancerTest extends CmfUnitTestCase
22 * @var FieldByClassEnhancer
27 public function setUp()
29 $this->document = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Enhancer\RouteObject');
31 $mapping = array('Symfony\Cmf\Component\Routing\Tests\Enhancer\RouteObject' => 'cmf_content.controller:indexAction');
33 $this->mapper = new FieldByClassEnhancer('_content', '_controller', $mapping);
35 $this->request = Request::create('/test');
38 public function testClassFoundInMapping()
40 // this is the mock, thus a child class to make sure we properly check with instanceof
41 $defaults = array('_content' => $this->document);
43 '_content' => $this->document,
44 '_controller' => 'cmf_content.controller:indexAction',
46 $this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
49 public function testFieldAlreadyThere()
52 '_content' => $this->document,
53 '_controller' => 'custom.controller:indexAction',
55 $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
58 public function testClassNotFoundInMapping()
60 $defaults = array('_content' => $this);
61 $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
64 public function testNoClass()
66 $defaults = array('foo' => 'bar');
67 $this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));