function ParamConversionEnhancerTest::testEnhance

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Enhancer/ParamConversionEnhancerTest.php \Drupal\Tests\Core\Enhancer\ParamConversionEnhancerTest::testEnhance()
  2. 10 core/tests/Drupal/Tests/Core/Enhancer/ParamConversionEnhancerTest.php \Drupal\Tests\Core\Enhancer\ParamConversionEnhancerTest::testEnhance()
  3. 11.x core/tests/Drupal/Tests/Core/Enhancer/ParamConversionEnhancerTest.php \Drupal\Tests\Core\Enhancer\ParamConversionEnhancerTest::testEnhance()

@covers ::enhance

File

core/tests/Drupal/Tests/Core/Enhancer/ParamConversionEnhancerTest.php, line 41

Class

ParamConversionEnhancerTest
@coversDefaultClass \Drupal\Core\Routing\Enhancer\ParamConversionEnhancer @group Enhancer

Namespace

Drupal\Tests\Core\Enhancer

Code

public function testEnhance() {
    $route = new Route('/test/{id}/{literal}/{null}');
    $raw_variables = [
        'id' => 1,
        'literal' => 'this is a literal',
        'null' => NULL,
    ];
    $defaults = [
        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);
}

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