PathHooksTest.php in Drupal 8
File
core/modules/path_alias/tests/src/Kernel/PathHooksTest.php
View source
<?php
namespace Drupal\Tests\path_alias\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\path_alias\AliasManagerInterface;
use Drupal\path_alias\Entity\PathAlias;
use Prophecy\Argument;
class PathHooksTest extends KernelTestBase {
public static $modules = [
'path_alias',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('path_alias');
}
public function testPathHooks() {
$path_alias = PathAlias::create([
'path' => '/' . $this
->randomMachineName(),
'alias' => '/' . $this
->randomMachineName(),
]);
$alias_manager = $this
->prophesize(AliasManagerInterface::class);
$alias_manager
->cacheClear(Argument::any())
->shouldBeCalledTimes(1);
$alias_manager
->cacheClear($path_alias
->getPath())
->shouldBeCalledTimes(1);
\Drupal::getContainer()
->set('path_alias.manager', $alias_manager
->reveal());
$path_alias
->save();
$new_source = '/' . $this
->randomMachineName();
$alias_manager = $this
->prophesize(AliasManagerInterface::class);
$alias_manager
->cacheClear(Argument::any())
->shouldBeCalledTimes(2);
$alias_manager
->cacheClear($path_alias
->getPath())
->shouldBeCalledTimes(1);
$alias_manager
->cacheClear($new_source)
->shouldBeCalledTimes(1);
\Drupal::getContainer()
->set('path_alias.manager', $alias_manager
->reveal());
$path_alias
->setPath($new_source);
$path_alias
->save();
$alias_manager = $this
->prophesize(AliasManagerInterface::class);
$alias_manager
->cacheClear(Argument::any())
->shouldBeCalledTimes(1);
$alias_manager
->cacheClear($new_source)
->shouldBeCalledTimes(1);
\Drupal::getContainer()
->set('path_alias.manager', $alias_manager
->reveal());
$path_alias
->delete();
}
}