public function ParamConverterManagerTest::testConvert in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php \Drupal\Tests\Core\ParamConverter\ParamConverterManagerTest::testConvert()
@covers ::convert
File
- core/
tests/ Drupal/ Tests/ Core/ ParamConverter/ ParamConverterManagerTest.php, line 171
Class
- ParamConverterManagerTest
- @coversDefaultClass \Drupal\Core\ParamConverter\ParamConverterManager @group ParamConverter
Namespace
Drupal\Tests\Core\ParamConverterCode
public function testConvert() {
$route = new Route('/test/{id}/{literal}/{null}');
$parameters = [
'id' => [
'converter' => 'test_convert',
],
'literal' => [],
'null' => [],
];
$route
->setOption('parameters', $parameters);
$defaults = [
RouteObjectInterface::ROUTE_OBJECT => $route,
RouteObjectInterface::ROUTE_NAME => 'test_route',
'id' => 1,
'literal' => 'this is a literal',
'null' => NULL,
];
$expected = $defaults;
$expected['id'] = 'something_better!';
$converter = $this
->createMock('Drupal\\Core\\ParamConverter\\ParamConverterInterface');
$converter
->expects($this
->any())
->method('convert')
->with(1, $this
->isType('array'), 'id', $this
->isType('array'))
->will($this
->returnValue('something_better!'));
$this->manager
->addConverter($converter, 'test_convert');
$result = $this->manager
->convert($defaults);
$this
->assertEquals($expected, $result);
}