You are here

public function AuthcacheAuthenticatedKeysTestCase::testKeyAbbreviation in Authenticated User Page Caching (Authcache) 7.2

Test key abbreviation (variable authcache_key_abbrev).

File

./authcache.test, line 1605
Tests for system.module.

Class

AuthcacheAuthenticatedKeysTestCase
Test key computation and handling.

Code

public function testKeyAbbreviation() {

  // No abbreviation.
  $this
    ->setupConfig(array(
    'authcache_key_abbrev' => FALSE,
  ));
  $this
    ->resetTestVariables();
  $this
    ->drupalLogin($this->plainUser);
  $noabbrev_key = $this
    ->drupalGet('authcache-test-get-key');
  $this
    ->drupalLogout();
  $this
    ->assertEqual(40, strlen($noabbrev_key));

  // Standard abbreviation (7 digits).
  $this
    ->setupConfig();
  $this
    ->resetTestVariables();
  $this
    ->drupalLogin($this->plainUser);
  $default_key = $this
    ->drupalGet('authcache-test-get-key');
  $this
    ->drupalLogout();
  $this
    ->assertEqual(7, strlen($default_key));

  // Custom abbreviation (4 digits).
  $this
    ->setupConfig(array(
    'authcache_key_abbrev' => 4,
  ));
  $this
    ->resetTestVariables();
  $this
    ->drupalLogin($this->plainUser);
  $short_key = $this
    ->drupalGet('authcache-test-get-key');
  $this
    ->drupalLogout();
  $this
    ->assertEqual(4, strlen($short_key));

  // Ensure that stdandard and custom abbreviated keys are substrings of the
  // long one.
  $this
    ->assertIdentical(strpos($noabbrev_key, $default_key), 0);
  $this
    ->assertIdentical(strpos($noabbrev_key, $short_key), 0);
}