class AliasPathProcessorTest in Drupal 8
Same name and namespace in other branches
- 9 core/modules/path_alias/tests/src/Unit/PathProcessor/AliasPathProcessorTest.php \Drupal\Tests\path_alias\Unit\PathProcessor\AliasPathProcessorTest
@coversDefaultClass \Drupal\path_alias\PathProcessor\AliasPathProcessor @group PathProcessor @group path_alias
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\path_alias\Unit\PathProcessor\AliasPathProcessorTest
Expanded class hierarchy of AliasPathProcessorTest
File
- core/
modules/ path_alias/ tests/ src/ Unit/ PathProcessor/ AliasPathProcessorTest.php, line 16
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;
protected function 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() {
$this->aliasManager
->expects($this
->exactly(2))
->method('getPathByAlias')
->will($this
->returnValueMap([
[
'urlalias',
NULL,
'internal-url',
],
[
'url',
NULL,
'url',
],
]));
$request = Request::create('/urlalias');
$this
->assertEquals('internal-url', $this->pathProcessor
->processInbound('urlalias', $request));
$request = Request::create('/url');
$this
->assertEquals('url', $this->pathProcessor
->processInbound('url', $request));
}
/**
* @covers ::processOutbound
*
* @dataProvider providerTestProcessOutbound
*/
public function testProcessOutbound($path, array $options, $expected_path) {
$this->aliasManager
->expects($this
->any())
->method('getAliasByPath')
->will($this
->returnValueMap([
[
'internal-url',
NULL,
'urlalias',
],
[
'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);
}
/**
* @return array
*/
public function providerTestProcessOutbound() {
return [
[
'internal-url',
[],
'urlalias',
],
[
'internal-url',
[
'alias' => TRUE,
],
'internal-url',
],
[
'url',
[],
'url',
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AliasPathProcessorTest:: |
protected | property | The mocked alias manager. | |
AliasPathProcessorTest:: |
protected | property | The tested path processor. | |
AliasPathProcessorTest:: |
public | function | ||
AliasPathProcessorTest:: |
protected | function |
Overrides UnitTestCase:: |
|
AliasPathProcessorTest:: |
public | function | Tests the processInbound method. | |
AliasPathProcessorTest:: |
public | function | @covers ::processOutbound | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |