You are here

abstract class Redis_Tests_Path_PathUnitTestCase in Redis 7.3

Bugfixes made over time test class.

Hierarchy

Expanded class hierarchy of Redis_Tests_Path_PathUnitTestCase

1 string reference to 'Redis_Tests_Path_PathUnitTestCase'
PhpRedisPathUnitTestCase.test in lib/Redis/Tests/Path/PhpRedisPathUnitTestCase.test

File

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

View source
abstract class Redis_Tests_Path_PathUnitTestCase extends Redis_Tests_AbstractUnitTestCase {

  /**
   * @var Cache bin identifier
   */
  private static $id = 1;

  /**
   * Get cache backend
   *
   * @return Redis_Path_HashLookupInterface
   */
  protected final function getBackend($name = null) {
    if (null === $name) {

      // This is needed to avoid conflict between tests, each test
      // seems to use the same Redis namespace and conflicts are
      // possible.
      $name = 'cache' . self::$id++;
    }
    $className = Redis_Client::getClass(Redis_Client::REDIS_IMPL_PATH);
    $hashLookup = new $className(Redis_Client::getClient(), 'path', Redis_Client::getDefaultPrefix('path'));
    return $hashLookup;
  }

  /**
   * Tests basic functionnality
   */
  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);
  }

  /**
   * Tests https://www.drupal.org/node/2728831
   */
  public function testSomeEdgeCaseFalseNegative() {
    $backend = $this
      ->getBackend();
    $backend
      ->deleteLanguage('fr');
    $backend
      ->deleteLanguage('und');
    $backend
      ->saveAlias('node/123', 'node-123');

    // Language lookup should return the language neutral value if no value
    $source = $backend
      ->lookupSource('node-123', 'fr');
    $this
      ->assertIdentical($source, 'node/123');
    $source = $backend
      ->lookupAlias('node/123', 'fr');
    $this
      ->assertIdentical($source, 'node-123');

    // Now, let's consider we have an item we don't know if it exists or
    // not, per definition we should not return a strict FALSE but a NULL
    // value instead to tell "we don't know anything about this". In a
    // very specific use-case, if the language neutral value is a strict
    // "not exists" value, it should still return NULL instead of FALSE
    // if another language was asked for.
    // Store "value null" for the language neutral entry
    $backend
      ->saveAlias('node/456', Redis_Path_HashLookupInterface::VALUE_NULL);
    $source = $backend
      ->lookupAlias('node/456');
    $this
      ->assertIdentical(false, $source);
    $source = $backend
      ->lookupAlias('node/456', 'fr');
    $this
      ->assertIdentical(null, $source);
  }

  /**
   * Tests that lookup is case insensitive
   */
  public function testCaseInsensitivePathLookup() {
    $backend = $this
      ->getBackend();
    $backend
      ->saveAlias('node/1', 'Node-1-FR', 'fr');
    $source = $backend
      ->lookupSource('NODE-1-fr', 'fr');
    $this
      ->assertIdentical('node/1', $source);
    $source = $backend
      ->lookupSource('node-1-FR', 'fr');
    $this
      ->assertIdentical('node/1', $source);
    $alias = $backend
      ->lookupAlias('node/1', 'fr');
    $this
      ->assertIdentical('node-1-fr', strtolower($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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalUnitTestCase::__construct function Constructor for DrupalUnitTestCase. Overrides DrupalTestCase::__construct
Redis_Tests_AbstractUnitTestCase::$loaderEnabled protected static property
Redis_Tests_AbstractUnitTestCase::$originalConf private property Drupal $conf array backup
Redis_Tests_AbstractUnitTestCase::enableAutoload protected static function Enable the autoloader
Redis_Tests_AbstractUnitTestCase::getClientInterface abstract protected function Set up the Redis configuration. 21
Redis_Tests_AbstractUnitTestCase::prepareClientManager final private function Prepare client manager
Redis_Tests_AbstractUnitTestCase::prepareDrupalEnvironment final private function Prepare Drupal environmment for testing
Redis_Tests_AbstractUnitTestCase::restoreClientManager final private function Restore client manager
Redis_Tests_AbstractUnitTestCase::restoreDrupalEnvironment final private function Restore Drupal environment after testing.
Redis_Tests_AbstractUnitTestCase::setUp public function Sets up unit test environment. Overrides DrupalUnitTestCase::setUp 1
Redis_Tests_AbstractUnitTestCase::tearDown public function Overrides DrupalUnitTestCase::tearDown 2
Redis_Tests_Path_PathUnitTestCase::$id private static property
Redis_Tests_Path_PathUnitTestCase::getBackend final protected function Get cache backend
Redis_Tests_Path_PathUnitTestCase::testCaseInsensitivePathLookup public function Tests that lookup is case insensitive
Redis_Tests_Path_PathUnitTestCase::testPathLookup public function Tests basic functionnality
Redis_Tests_Path_PathUnitTestCase::testSomeEdgeCaseFalseNegative public function Tests https://www.drupal.org/node/2728831