function PathAliasTest::testPathCache
Same name in other branches
- 9 core/modules/path/tests/src/Functional/PathAliasTest.php \Drupal\Tests\path\Functional\PathAliasTest::testPathCache()
- 8.9.x core/modules/path/tests/src/Functional/PathAliasTest.php \Drupal\Tests\path\Functional\PathAliasTest::testPathCache()
- 10 core/modules/path/tests/src/Functional/PathAliasTest.php \Drupal\Tests\path\Functional\PathAliasTest::testPathCache()
Tests the path cache.
File
-
core/
modules/ path/ tests/ src/ Functional/ PathAliasTest.php, line 56
Class
- PathAliasTest
- Tests modifying path aliases from the UI.
Namespace
Drupal\Tests\path\FunctionalCode
public function testPathCache() : void {
// Create test node.
$node1 = $this->drupalCreateNode();
// Create alias.
$edit = [];
$edit['path[0][value]'] = '/node/' . $node1->id();
$edit['alias[0][value]'] = '/' . $this->randomMachineName(8);
$this->drupalGet('admin/config/search/path/add');
$this->submitForm($edit, 'Save');
// Check the path alias prefix list cache.
$prefix_list = \Drupal::cache('bootstrap')->get('path_alias_prefix_list');
$this->assertTrue($prefix_list->data['node']);
$this->assertFalse($prefix_list->data['admin']);
// Visit the system path for the node and confirm a cache entry is
// created.
\Drupal::cache('data')->deleteAll();
// Make sure the path is not converted to the alias.
$this->drupalGet(trim($edit['path[0][value]'], '/'), [
'alias' => TRUE,
]);
$this->assertNotEmpty(\Drupal::cache('data')->get('preload-paths:' . $edit['path[0][value]']), 'Cache entry was created.');
// Visit the alias for the node and confirm a cache entry is created.
\Drupal::cache('data')->deleteAll();
// @todo Remove this once https://www.drupal.org/node/2480077 lands.
Cache::invalidateTags([
'rendered',
]);
$this->drupalGet(trim($edit['alias[0][value]'], '/'));
$this->assertNotEmpty(\Drupal::cache('data')->get('preload-paths:' . $edit['path[0][value]']), 'Cache entry was created.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.