public function AuthcacheEnumKeysTestCase::testCustomAuthenticatedKeys in Authenticated User Page Caching (Authcache) 7.2
Test authenticated key customization.
File
- modules/
authcache_enum/ lib/ Drupal/ authcache_enum/ Tests/ AuthcacheEnumKeysTestCase.php, line 141 - Defines a test case covering _authcache_enum_cartesian.
Class
- AuthcacheEnumKeysTestCase
- Unit tests for _authcache_enum_comb.
Namespace
Drupal\authcache_enum\TestsCode
public function testCustomAuthenticatedKeys() {
global $base_root;
$rid1 = (int) $this
->drupalCreateRole(array());
$rid2 = (int) $this
->drupalCreateRole(array());
variable_set('authcache_roles', array(
DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID,
DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
$rid1 => $rid1,
$rid2 => $rid2,
));
// Data for hook_authcache_enum_key_property_info().
$custom_property_info = array(
'js' => array(
'name' => t('Browser supports JavaScript'),
'choices' => array(
TRUE,
FALSE,
),
),
);
// Data for hook_authcache_enum_key_property_info_alter().
// Remove roles and customize choices on base_root property.
$base_roots = array(
'http://www.' . $this
->randomName(6) . '.com',
'http://www.' . $this
->randomName(7) . '.com',
);
$property_info_alter = array(
'delete' => array(
'roles' => TRUE,
),
'insert' => array(
'base_root' => array(
'name' => t('The root URL of the host, excluding the path'),
'choices' => $base_roots,
),
),
);
$expect_properties = array(
array(
'base_root' => $base_roots[0],
'js' => FALSE,
),
array(
'base_root' => $base_roots[0],
'js' => TRUE,
),
array(
'base_root' => $base_roots[1],
'js' => FALSE,
),
array(
'base_root' => $base_roots[1],
'js' => TRUE,
),
);
$user_keys = array_map('authcache_user_key', $expect_properties);
$expect_alter = array_combine($user_keys, $expect_properties);
ksort($expect_alter);
$expect_keys = $user_keys;
$expect_keys[] = $base_root;
$infostub = $this->stubmod
->hook('authcache_enum_key_property_info', $custom_property_info);
$infoalterstub = $this->stubmod
->hook('authcache_enum_key_property_info_alter', $property_info_alter);
$keyalterstub = $this->stubmod
->hook('authcache_enum_key_properties_alter');
$result = authcache_enum_keys();
$this
->assertStub($infostub, \HookStub::once());
$default_property_info = authcache_enum_authcache_enum_key_property_info();
$this
->assertStub($infoalterstub, \HookStub::once());
$this
->assertStub($infoalterstub, \HookStub::args(array(
$default_property_info + $custom_property_info,
NULL,
NULL,
NULL,
), 0, FALSE));
$this
->assertStub($keyalterstub, \HookStub::once());
$this
->assertStub($keyalterstub, \HookStub::args(array(
$expect_alter,
NULL,
NULL,
NULL,
), 0, FALSE));
sort($result);
sort($expect_keys);
$this
->assertEqual($expect_keys, $result);
}