function PathAliasTest::testPathCache

Tests the path cache.

File

drupal/core/modules/path/lib/Drupal/path/Tests/PathAliasTest.php, line 41
Definition of Drupal\path\Tests\PathAliasTest.

Class

PathAliasTest
Tests path alias functionality.

Namespace

Drupal\path\Tests

Code

function testPathCache() {

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

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

  // Check the path alias whitelist cache.
  $whitelist = 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.
  cache('path')
    ->deleteAll();

  // Make sure the path is not converted to the alias.
  $this
    ->drupalGet($edit['source'], array(
    'alias' => TRUE,
  ));
  $this
    ->assertTrue(cache('path')
    ->get($edit['source']), 'Cache entry was created.');

  // Visit the alias for the node and confirm a cache entry is created.
  cache('path')
    ->deleteAll();
  $this
    ->drupalGet($edit['alias']);
  $this
    ->assertTrue(cache('path')
    ->get($edit['source']), 'Cache entry was created.');
}