class PathAliasSearchTest in Freelinking 8.3
Same name and namespace in other branches
- 4.0.x tests/src/Unit/Plugin/freelinking/PathAliasSearchTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\PathAliasSearchTest
Tests the path_alias plugin.
@group freelinking
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\freelinking\Unit\Plugin\freelinking\PathAliasSearchTest
Expanded class hierarchy of PathAliasSearchTest
File
- tests/
src/ Unit/ Plugin/ freelinking/ PathAliasSearchTest.php, line 17
Namespace
Drupal\Tests\freelinking\Unit\Plugin\freelinkingView source
class PathAliasSearchTest extends UnitTestCase {
/**
* The container.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* String translation mock.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected $translationInterfaceMock;
/**
* {@inheritdoc}
*/
protected function setUp() {
// Mock string translation service.
$tProphet = $this
->prophesize('\\Drupal\\Core\\StringTranslation\\TranslationInterface');
$tProphet
->translateString(Argument::any())
->willReturn('Click to view a local node.');
$this->translationInterfaceMock = $tProphet
->reveal();
// Mock module handler service.
$moduleHandlerProphet = $this
->prophesize('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
$moduleHandlerProphet
->moduleExists('search')
->willReturn(TRUE);
// Path alias manager service.
$aliasManagerProphet = $this
->prophesize('\\Drupal\\path_alias\\AliasManagerInterface');
$aliasManagerProphet
->getPathByAlias('/invalidalias', Argument::any())
->willReturn('/invalidalias');
// Path validator service.
$pathValidatorProphet = $this
->prophesize('\\Drupal\\Core\\Path\\PathValidatorInterface');
$this->container = new ContainerBuilder();
$this->container
->set('string_translation', $this->translationInterfaceMock);
$this->container
->set('module_handler', $moduleHandlerProphet
->reveal());
$this->container
->set('path_alias.manager', $aliasManagerProphet
->reveal());
$this->container
->set('path.validator', $pathValidatorProphet
->reveal());
\Drupal::setContainer($this->container);
}
/**
* Get plugin instance.
*
* @param string $failoverOption
* The failover option.
*
* @return \Drupal\freelinking\Plugin\freelinking\PathAlias
* A plugin instance.
*/
protected function getPlugin($failoverOption = 'search') {
$configuration = [
'settings' => [
'failover' => $failoverOption,
],
];
$plugin_definition = [
'id' => 'path_alias',
'title' => 'Path Alias',
'hidden' => FALSE,
'weight' => 0,
] + $configuration;
return PathAlias::create($this->container, $configuration, 'path_alias', $plugin_definition);
}
/**
* Asserts that buildLink is functional for search failover.
*/
public function testBuildLink() {
$target = [
'text' => 'A valid path alias',
'dest' => 'invalidalias',
'target' => 'alias:invalidalias|A valid path alias',
'language' => NULL,
];
$plugin = $this
->getPlugin('search');
$expected = [
'#type' => 'link',
'#title' => 'A valid path alias',
'#url' => Url::fromUri('base:search', [
'query' => [
'keys' => '/invalidalias',
],
'language' => NULL,
]),
'#attributes' => [
'title' => new TranslatableMarkup('Click to view a local node.', [], [], $this->translationInterfaceMock),
],
];
$this
->assertEquals($expected, $plugin
->buildLink($target));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PathAliasSearchTest:: |
protected | property | The container. | |
PathAliasSearchTest:: |
protected | property | String translation mock. | |
PathAliasSearchTest:: |
protected | function | Get plugin instance. | |
PathAliasSearchTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PathAliasSearchTest:: |
public | function | Asserts that buildLink is functional for search failover. | |
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. |