You are here

public function ParamConverterManagerTest::testConvert in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 176
Contains \Drupal\Tests\Core\ParamConverter\ParamConverterManagerTest.

Class

ParamConverterManagerTest
@coversDefaultClass \Drupal\Core\ParamConverter\ParamConverterManager @group ParamConverter

Namespace

Drupal\Tests\Core\ParamConverter

Code

public function testConvert() {
  $route = new Route('/test/{id}/{literal}/{null}');
  $parameters = array(
    'id' => array(
      'converter' => 'test_convert',
    ),
    'literal' => array(),
    'null' => array(),
  );
  $route
    ->setOption('parameters', $parameters);
  $defaults = array(
    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
    ->getMock('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);
}