class AliasPathProcessorTest
Tests Drupal\path_alias\PathProcessor\AliasPathProcessor.
Attributes
#[CoversClass(AliasPathProcessor::class)]
#[Group('PathProcessor')]
#[Group('path_alias')]
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\path_alias\Unit\PathProcessor\AliasPathProcessorTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of AliasPathProcessorTest
File
-
core/
modules/ path_alias/ tests/ src/ Unit/ PathProcessor/ AliasPathProcessorTest.php, line 19
Namespace
Drupal\Tests\path_alias\Unit\PathProcessorView source
class AliasPathProcessorTest extends UnitTestCase {
/**
* The mocked alias manager.
*
* @var \Drupal\path_alias\AliasManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $aliasManager;
/**
* The tested path processor.
*
* @var \Drupal\path_alias\PathProcessor\AliasPathProcessor
*/
protected $pathProcessor;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->aliasManager = $this->createMock('Drupal\\path_alias\\AliasManagerInterface');
$this->pathProcessor = new AliasPathProcessor($this->aliasManager);
}
/**
* Tests the processInbound method.
*
* @see \Drupal\path_alias\PathProcessor\AliasPathProcessor::processInbound
*/
public function testProcessInbound() : void {
$this->aliasManager
->expects($this->exactly(2))
->method('getPathByAlias')
->willReturnMap([
[
'url-alias',
NULL,
'internal-url',
],
[
'url',
NULL,
'url',
],
]);
$request = Request::create('/url-alias');
$this->assertEquals('internal-url', $this->pathProcessor
->processInbound('url-alias', $request));
$request = Request::create('/url');
$this->assertEquals('url', $this->pathProcessor
->processInbound('url', $request));
}
/**
* Tests process outbound.
*
* @legacy-covers ::processOutbound
*/
public function testProcessOutbound($path, array $options, $expected_path) : void {
$this->aliasManager
->expects($this->any())
->method('getAliasByPath')
->willReturnMap([
[
'internal-url',
NULL,
'url-alias',
],
[
'url',
NULL,
'url',
],
]);
$bubbleable_metadata = new BubbleableMetadata();
$this->assertEquals($expected_path, $this->pathProcessor
->processOutbound($path, $options, NULL, $bubbleable_metadata));
// Cacheability of paths replaced with path aliases is permanent.
// @todo https://www.drupal.org/node/2480077
$this->assertEquals((new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT), $bubbleable_metadata);
}
/**
* Provides data for testing outbound processing.
*
* @return array
* The data provider for testProcessOutbound.
*/
public static function providerTestProcessOutbound() {
return [
[
'internal-url',
[],
'url-alias',
],
[
'internal-url',
[
'alias' => TRUE,
],
'internal-url',
],
[
'url',
[],
'url',
],
];
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
|---|---|---|---|---|
| AliasPathProcessorTest::$aliasManager | protected | property | The mocked alias manager. | |
| AliasPathProcessorTest::$pathProcessor | protected | property | The tested path processor. | |
| AliasPathProcessorTest::providerTestProcessOutbound | public static | function | Provides data for testing outbound processing. | |
| AliasPathProcessorTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
| AliasPathProcessorTest::testProcessInbound | public | function | Tests the processInbound method. | |
| AliasPathProcessorTest::testProcessOutbound | public | function | Tests process outbound. | |
| 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. | |
| 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.