You are here

public function Redis_Tests_Path_PathUnitTestCase::testPathLookup in Redis 7.3

Tests basic functionnality

File

lib/Redis/Tests/Path/PathUnitTestCase.php, line 36

Class

Redis_Tests_Path_PathUnitTestCase
Bugfixes made over time test class.

Code

public function testPathLookup() {
  $backend = $this
    ->getBackend();
  $source = $backend
    ->lookupSource('node-1-fr', 'fr');
  $this
    ->assertIdentical(null, $source);
  $alias = $backend
    ->lookupAlias('node/1', 'fr');
  $this
    ->assertIdentical(null, $source);
  $backend
    ->saveAlias('node/1', 'node-1-fr', 'fr');
  $source = $backend
    ->lookupSource('node-1-fr', 'fr');
  $source = $backend
    ->lookupSource('node-1-fr', 'fr');
  $this
    ->assertIdentical('node/1', $source);
  $alias = $backend
    ->lookupAlias('node/1', 'fr');
  $this
    ->assertIdentical('node-1-fr', $alias);

  // Delete and ensure it does not exist anymore.
  $backend
    ->deleteAlias('node/1', 'node-1-fr', 'fr');
  $source = $backend
    ->lookupSource('node-1-fr', 'fr');
  $this
    ->assertIdentical(null, $source);
  $alias = $backend
    ->lookupAlias('node/1', 'fr');
  $this
    ->assertIdentical(null, $source);

  // Set more than one aliases and ensure order at loading.
  $backend
    ->saveAlias('node/1', 'node-1-fr-1', 'fr');
  $backend
    ->saveAlias('node/1', 'node-1-fr-2', 'fr');
  $backend
    ->saveAlias('node/1', 'node-1-fr-3', 'fr');
  $alias = $backend
    ->lookupAlias('node/1', 'fr');
  $this
    ->assertIdentical('node-1-fr-3', $alias);

  // Add another alias to test the delete language feature.
  // Also add some other languages aliases.
  $backend
    ->saveAlias('node/1', 'node-1');
  $backend
    ->saveAlias('node/2', 'node-2-en', 'en');
  $backend
    ->saveAlias('node/3', 'node-3-ca', 'ca');

  // Ok, delete fr and tests every other are still there.
  $backend
    ->deleteLanguage('fr');
  $alias = $backend
    ->lookupAlias('node/1');
  $this
    ->assertIdentical('node-1', $alias);
  $alias = $backend
    ->lookupAlias('node/2', 'en');
  $this
    ->assertIdentical('node-2-en', $alias);
  $alias = $backend
    ->lookupAlias('node/3', 'ca');
  $this
    ->assertIdentical('node-3-ca', $alias);

  // Now create back a few entries in some langage and
  // ensure fallback to no language also works.
  $backend
    ->saveAlias('node/4', 'node-4');
  $backend
    ->saveAlias('node/4', 'node-4-es', 'es');
  $alias = $backend
    ->lookupAlias('node/4');
  $this
    ->assertIdentical('node-4', $alias);
  $alias = $backend
    ->lookupAlias('node/4', 'es');
  $this
    ->assertIdentical('node-4-es', $alias);
  $alias = $backend
    ->lookupAlias('node/4', 'fr');
  $this
    ->assertIdentical('node-4', $alias);
}