You are here

function PathAliasTest::testPathCache in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/path/src/Tests/PathAliasTest.php \Drupal\path\Tests\PathAliasTest::testPathCache()

Tests the path cache.

File

core/modules/path/src/Tests/PathAliasTest.php, line 40
Contains \Drupal\path\Tests\PathAliasTest.

Class

PathAliasTest
Add, edit, delete, and change alias and verify its consistency in the database.

Namespace

Drupal\path\Tests

Code

function testPathCache() {

  // Create test node.
  $node1 = $this
    ->drupalCreateNode();

  // Create alias.
  $edit = array();
  $edit['source'] = '/node/' . $node1
    ->id();
  $edit['alias'] = '/' . $this
    ->randomMachineName(8);
  $this
    ->drupalPostForm('admin/config/search/path/add', $edit, t('Save'));

  // Check the path alias whitelist cache.
  $whitelist = \Drupal::cache()
    ->get('path_alias_whitelist');
  $this
    ->assertTrue($whitelist->data['node']);
  $this
    ->assertFalse($whitelist->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['source'], '/'), array(
    'alias' => TRUE,
  ));
  $this
    ->assertTrue(\Drupal::cache('data')
    ->get('preload-paths:' . $edit['source']), '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'], '/'));
  $this
    ->assertTrue(\Drupal::cache('data')
    ->get('preload-paths:' . $edit['source']), 'Cache entry was created.');
}