ParamConversionEnhancerTest.php in Zircon Profile 8.0
File
core/tests/Drupal/Tests/Core/Enhancer/ParamConversionEnhancerTest.php
View source
<?php
namespace Drupal\Tests\Core\Enhancer;
use Drupal\Core\Routing\Enhancer\ParamConversionEnhancer;
use Drupal\Tests\UnitTestCase;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
class ParamConversionEnhancerTest extends UnitTestCase {
protected $paramConversionEnhancer;
protected $paramConverterManager;
protected function setUp() {
parent::setUp();
$this->paramConverterManager = $this
->getMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
$this->paramConversionEnhancer = new ParamConversionEnhancer($this->paramConverterManager);
}
public function testEnhance() {
$route = new Route('/test/{id}/{literal}/{null}');
$raw_variables = array(
'id' => 1,
'literal' => 'this is a literal',
'null' => NULL,
);
$defaults = array(
RouteObjectInterface::ROUTE_OBJECT => $route,
) + $raw_variables;
$expected = $defaults;
$expected['id'] = 'something_better!';
$expected['_raw_variables'] = new ParameterBag($raw_variables);
$this->paramConverterManager
->expects($this
->once())
->method('convert')
->with($this
->isType('array'))
->will($this
->returnValue($expected));
$result = $this->paramConversionEnhancer
->enhance($defaults, new Request());
$this
->assertEquals($expected, $result);
$result = $this->paramConversionEnhancer
->enhance($result, new Request());
$this
->assertEquals($expected, $result);
}
public function testCopyRawVariables() {
$route = new Route('/test/{id}');
$defaults = array(
RouteObjectInterface::ROUTE_OBJECT => $route,
'id' => '1',
);
$defaults['bar'] =& $defaults['id'];
$this->paramConverterManager
->expects($this
->any())
->method('convert')
->with($this
->isType('array'))
->will($this
->returnCallback(function ($defaults) {
$defaults['bar'] = '2';
return $defaults;
}));
$expected = new ParameterBag(array(
'id' => 1,
));
$result = $this->paramConversionEnhancer
->enhance($defaults, new Request());
$this
->assertEquals($result['_raw_variables'], $expected);
}
}