protected function PathAliasTest::setUp in Freelinking 4.0.x
Same name and namespace in other branches
- 8.3 tests/src/Unit/Plugin/freelinking/PathAliasTest.php \Drupal\Tests\freelinking\Unit\Plugin\freelinking\PathAliasTest::setUp()
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ Plugin/ freelinking/ PathAliasTest.php, line 39
Class
- PathAliasTest
- Tests the path_alias plugin.
Namespace
Drupal\Tests\freelinking\Unit\Plugin\freelinkingCode
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(FALSE);
// Path alias manager service.
$aliasManagerProphet = $this
->prophesize('\\Drupal\\path_alias\\AliasManagerInterface');
$aliasManagerProphet
->getPathByAlias(Argument::any(), Argument::any())
->will(function ($args) {
return $args[0] === '/validalias' ? '/node/1' : '/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);
}