class ParamConversionEnhancerTest
Tests Drupal\Core\Routing\Enhancer\ParamConversionEnhancer.
Attributes
#[CoversClass(ParamConversionEnhancer::class)]
#[Group('Enhancer')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Enhancer\ParamConversionEnhancerTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of ParamConversionEnhancerTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Enhancer/ ParamConversionEnhancerTest.php, line 19
Namespace
Drupal\Tests\Core\EnhancerView source
class ParamConversionEnhancerTest extends UnitTestCase {
/**
* @var \Drupal\Core\Routing\Enhancer\ParamConversionEnhancer
*/
protected $paramConversionEnhancer;
/**
* @var \Drupal\Core\ParamConverter\ParamConverterManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $paramConverterManager;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->paramConverterManager = $this->createMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
$this->paramConversionEnhancer = new ParamConversionEnhancer($this->paramConverterManager);
}
/**
* Tests enhance.
*
* @legacy-covers ::enhance
*/
public function testEnhance() : void {
$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 InputBag($raw_variables);
$this->paramConverterManager
->expects($this->once())
->method('convert')
->with($this->isType('array'))
->willReturn($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);
}
/**
* Tests copy raw variables.
*
* @legacy-covers ::copyRawVariables
*/
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);
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
|---|---|---|---|---|
| ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
| ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
| ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
| ParamConversionEnhancerTest::$paramConversionEnhancer | protected | property | ||
| ParamConversionEnhancerTest::$paramConverterManager | protected | property | ||
| ParamConversionEnhancerTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
| ParamConversionEnhancerTest::testCopyRawVariables | public | function | Tests copy raw variables. | |
| ParamConversionEnhancerTest::testEnhance | public | function | Tests enhance. | |
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
| UnitTestCase::$root | protected | property | The app root. | |
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.