diff --git a/modules/authcache_enum/authcache_enum.api.php b/modules/authcache_enum/authcache_enum.api.php index c90d50f..cd87487 100644 --- a/modules/authcache_enum/authcache_enum.api.php +++ b/modules/authcache_enum/authcache_enum.api.php @@ -60,15 +60,15 @@ function hook_authcache_enum_key_property_info() { * * @see hook_authcache_enum_key_property_info(). */ -function hook_authcache_enum_key_property_info_alter(&$info) { +function hook_authcache_enum_key_property_info_alter(&$property_info) { } /** - * Modify available keys and property info records. + * Modify available keys and property records. * - * @param array &$properties_info + * @param array &$properties * An associative array where keys correspond to authcache keys and values * represent the property record the key is derived from. */ -function hook_authcache_enum_key_properties_alter(&$properties_info) { +function hook_authcache_enum_key_properties_alter(&$properties) { } diff --git a/modules/authcache_enum/lib/Drupal/authcache_enum/Tests/AuthcacheEnumKeysTestCase.php b/modules/authcache_enum/lib/Drupal/authcache_enum/Tests/AuthcacheEnumKeysTestCase.php index d822c7e..22c2634 100644 --- a/modules/authcache_enum/lib/Drupal/authcache_enum/Tests/AuthcacheEnumKeysTestCase.php +++ b/modules/authcache_enum/lib/Drupal/authcache_enum/Tests/AuthcacheEnumKeysTestCase.php @@ -150,6 +150,103 @@ class AuthcacheEnumKeysTestCase extends \DrupalWebTestCase { $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, + ))); + + $this->assertStub($keyalterstub, \HookStub::once()); + $this->assertStub($keyalterstub, \HookStub::args(array( + $expect_alter, + NULL, + NULL, + NULL, + ))); + + sort($result); + sort($expect_keys); + $this->assertEqual($expect_keys, $result); + } + + /** + * Test deprecated authenticated key customization. + */ + public function testDeprecatedCustomAuthenticatedKeys() { + 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, + )); + $property_info = array( 'js' => array( 'name' => t('Browser supports JavaScript'), diff --git a/modules/authcache_enum/tests/authcache_enum_test.module b/modules/authcache_enum/tests/authcache_enum_test.module index 4d26b68..d8ddd92 100644 --- a/modules/authcache_enum/tests/authcache_enum_test.module +++ b/modules/authcache_enum/tests/authcache_enum_test.module @@ -33,7 +33,24 @@ function authcache_enum_test_authcache_enum_key_properties() { /** * Implements hook_authcache_enum_key_properties_alter() */ -function authcache_enum_test_authcache_enum_key_properties_alter(&$properties_info) { - ksort($properties_info); +function authcache_enum_test_authcache_enum_key_properties_alter(&$properties) { + ksort($properties); return HookStub::record(__FUNCTION__, func_get_args()); } + +/** + * Implements hook_authcache_enum_key_property_info() + */ +function authcache_enum_test_authcache_enum_key_property_info() { + return HookStub::record(__FUNCTION__, func_get_args()); +} + +/** + * Implements hook_authcache_enum_key_property_info_alter() + */ +function authcache_enum_test_authcache_enum_key_property_info_alter(&$property_info) { + if (($alter = HookStub::record(__FUNCTION__, func_get_args()))) { + $property_info = array_diff_key($property_info, $alter['delete']); + $property_info = $alter['insert'] + $property_info; + } +}