1.20.x path.test PathTestCase::testPathCache()

Tests the path cache.

File

modules/path/tests/path.test, line 33
Tests for the Path module.

Class

PathTestCase
Provides a base class for testing the Path module.

Code

function testPathCache() {
  // Create test node.
  $node1 = $this->backdropCreateNode();

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

  // Visit the system path for the node and confirm a cache entry is
  // created.
  cache('path')->flush();
  $this->backdropGet($edit['source']);
  sleep(3); // Path cache is set in the background. Wait for it to populate.
  $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')->flush();
  $this->backdropGet($edit['alias']);
  sleep(3); // Path cache is set in the background. Wait for it to populate.
  $this->assertTrue(cache('path')->get($edit['source']), 'Cache entry was created.');
}