class PathHooksTest
Same name and namespace in other branches
- 11.x core/modules/path_alias/tests/src/Kernel/PathHooksTest.php \Drupal\Tests\path_alias\Kernel\PathHooksTest
- 10 core/modules/path_alias/tests/src/Kernel/PathHooksTest.php \Drupal\Tests\path_alias\Kernel\PathHooksTest
- 8.9.x core/modules/path_alias/tests/src/Kernel/PathHooksTest.php \Drupal\Tests\path_alias\Kernel\PathHooksTest
@coversDefaultClass \Drupal\path_alias\Entity\PathAlias
@group path_alias
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\path_alias\Kernel\PathHooksTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of PathHooksTest
File
-
core/
modules/ path_alias/ tests/ src/ Kernel/ PathHooksTest.php, line 15
Namespace
Drupal\Tests\path_alias\KernelView source
class PathHooksTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'path_alias',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installEntitySchema('path_alias');
}
/**
* Tests that the PathAlias entity clears caches correctly.
*
* @covers ::postSave
* @covers ::postDelete
*/
public function testPathHooks() {
$path_alias = PathAlias::create([
'path' => '/' . $this->randomMachineName(),
'alias' => '/' . $this->randomMachineName(),
]);
// Check \Drupal\path_alias\Entity\PathAlias::postSave() for new path alias
// entities.
$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();
// Check \Drupal\path_alias\Entity\PathAlias::postSave() for existing path
// alias entities.
$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();
// Check \Drupal\path_alias\Entity\PathAlias::postDelete().
$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();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.