You are here

public function ParamConversionEnhancerTest::testCopyRawVariables in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Enhancer/ParamConversionEnhancerTest.php \Drupal\Tests\Core\Enhancer\ParamConversionEnhancerTest::testCopyRawVariables()
  2. 9 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 76

Class

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

Namespace

Drupal\Tests\Core\Enhancer

Code

public function testCopyRawVariables() {
  $route = new Route('/test/{id}');
  $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,
  ]);
  $result = $this->paramConversionEnhancer
    ->enhance($defaults, new Request());
  $this
    ->assertEquals($result['_raw_variables'], $expected);
}