You are here

public function ParamConversionEnhancerTest::testEnhance in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 46
Contains \Drupal\Tests\Core\Enhancer\ParamConversionEnhancerTest.

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 = array(
    'id' => 1,
    'literal' => 'this is a literal',
    'null' => NULL,
  );
  $defaults = array(
    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);
}