function ParamConversionEnhancerTest::testCopyRawVariables

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

@covers ::copyRawVariables

File

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

Class

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

Namespace

Drupal\Tests\Core\Enhancer

Code

public function testCopyRawVariables() : void {
    $route = new Route('/test/{id}');
    $route->setDefault('node_type', 'page');
    $defaults = [
        RouteObjectInterface::ROUTE_OBJECT => $route,
        'id' => '1',
    ];
    // Set one default to mirror another by reference.
    $defaults['bar'] =& $defaults['id'];
    $this->paramConverterManager
        ->expects($this->any())
        ->method('convert')
        ->with($this->isType('array'))
        ->willReturnCallback(function ($defaults) {
        // Convert the mirrored default to another value.
        $defaults['bar'] = '2';
        return $defaults;
    });
    $expected = new InputBag([
        'id' => '1',
        'node_type' => 'page',
    ]);
    $result = $this->paramConversionEnhancer
        ->enhance($defaults, new Request());
    $this->assertEquals($result['_raw_variables'], $expected);
}

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