function ParamConverterManagerTest::testConvert

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php \Drupal\Tests\Core\ParamConverter\ParamConverterManagerTest::testConvert()
  2. 10 core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php \Drupal\Tests\Core\ParamConverter\ParamConverterManagerTest::testConvert()
  3. 11.x 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\ParamConverter

Code

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.