function ParamConverterManagerTest::testSetRouteParameterConverters

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php \Drupal\Tests\Core\ParamConverter\ParamConverterManagerTest::testSetRouteParameterConverters()
  2. 8.9.x core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php \Drupal\Tests\Core\ParamConverter\ParamConverterManagerTest::testSetRouteParameterConverters()
  3. 11.x core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php \Drupal\Tests\Core\ParamConverter\ParamConverterManagerTest::testSetRouteParameterConverters()

@covers ::setRouteParameterConverters

@dataProvider providerTestSetRouteParameterConverters

File

core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php, line 132

Class

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

Namespace

Drupal\Tests\Core\ParamConverter

Code

public function testSetRouteParameterConverters($path, $parameters = NULL, $expected = NULL) : void {
    $converter = $this->createMock('Drupal\\Core\\ParamConverter\\ParamConverterInterface');
    $converter->expects($this->any())
        ->method('applies')
        ->with($this->anything(), 'id', $this->anything())
        ->willReturn(TRUE);
    $this->manager
        ->addConverter($converter, 'applied');
    $route = new Route($path);
    if ($parameters) {
        $route->setOption('parameters', $parameters);
    }
    $collection = new RouteCollection();
    $collection->add('test_route', $route);
    $this->manager
        ->setRouteParameterConverters($collection);
    foreach ($collection as $route) {
        $result = $route->getOption('parameters');
        if ($expected) {
            $this->assertSame($expected, $result['id']['converter']);
        }
        else {
            $this->assertNull($result);
        }
    }
}

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