class ParamConversionEnhancerTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Enhancer/ParamConversionEnhancerTest.php \Drupal\Tests\Core\Enhancer\ParamConversionEnhancerTest
@coversDefaultClass \Drupal\Core\Routing\Enhancer\ParamConversionEnhancer @group Enhancer
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Enhancer\ParamConversionEnhancerTest
Expanded class hierarchy of ParamConversionEnhancerTest
File
- core/
tests/ Drupal/ Tests/ Core/ Enhancer/ ParamConversionEnhancerTest.php, line 21 - Contains \Drupal\Tests\Core\Enhancer\ParamConversionEnhancerTest.
Namespace
Drupal\Tests\Core\EnhancerView source
class ParamConversionEnhancerTest extends UnitTestCase {
/**
* @var \Drupal\Core\Routing\Enhancer\ParamConversionEnhancer
*/
protected $paramConversionEnhancer;
/**
* @var \Drupal\Core\ParamConverter\ParamConverterManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $paramConverterManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->paramConverterManager = $this
->getMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
$this->paramConversionEnhancer = new ParamConversionEnhancer($this->paramConverterManager);
}
/**
* @covers ::enhance
*/
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);
// Now run with the results as the new defaults to ensure that the
// conversion is just run once.
$result = $this->paramConversionEnhancer
->enhance($result, new Request());
$this
->assertEquals($expected, $result);
}
/**
* @covers ::copyRawVariables
*/
public function testCopyRawVariables() {
$route = new Route('/test/{id}');
$defaults = array(
RouteObjectInterface::ROUTE_OBJECT => $route,
'id' => '1',
);
// Set one default to mirror another by reference.
$defaults['bar'] =& $defaults['id'];
$this->paramConverterManager
->expects($this
->any())
->method('convert')
->with($this
->isType('array'))
->will($this
->returnCallback(function ($defaults) {
// Convert the mirrored default to another value.
$defaults['bar'] = '2';
return $defaults;
}));
$expected = new ParameterBag(array(
'id' => 1,
));
$result = $this->paramConversionEnhancer
->enhance($defaults, new Request());
$this
->assertEquals($result['_raw_variables'], $expected);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ParamConversionEnhancerTest:: |
protected | property | ||
ParamConversionEnhancerTest:: |
protected | property | ||
ParamConversionEnhancerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ParamConversionEnhancerTest:: |
public | function | @covers ::copyRawVariables | |
ParamConversionEnhancerTest:: |
public | function | @covers ::enhance | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |