Commit 1d29fd0a authored by alexpott's avatar alexpott

Issue #2387973 by tibbsa, hussainweb: Clean-up toolbar module test members -...

Issue #2387973 by tibbsa, hussainweb: Clean-up toolbar module test members - ensure property definition and use of camelCase naming convention
parent 057b0cab
...@@ -33,19 +33,19 @@ class ToolbarAdminMenuTest extends WebTestBase { ...@@ -33,19 +33,19 @@ class ToolbarAdminMenuTest extends WebTestBase {
/** /**
* A user with permission to access the administrative toolbar. * A user with permission to access the administrative toolbar.
* *
* @var object * @var \Drupal\user\UserInterface
*/ */
protected $admin_user; protected $adminUser;
/** /**
* A second user with permission to access the administrative toolbar. * A second user with permission to access the administrative toolbar.
* *
* @var object * @var \Drupal\user\UserInterface
*/ */
protected $admin_user_2; protected $adminUser2;
/** /**
* The current admin menu subtrees hash for admin_user. * The current admin menu subtrees hash for adminUser.
* *
* @var string * @var string
*/ */
...@@ -81,10 +81,10 @@ protected function setUp() { ...@@ -81,10 +81,10 @@ protected function setUp() {
); );
// Create an administrative user and log it in. // Create an administrative user and log it in.
$this->admin_user = $this->drupalCreateUser($perms); $this->adminUser = $this->drupalCreateUser($perms);
$this->admin_user_2 = $this->drupalCreateUser($perms); $this->adminUser2 = $this->drupalCreateUser($perms);
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->adminUser);
$this->drupalGet('test-page'); $this->drupalGet('test-page');
$this->assertResponse(200); $this->assertResponse(200);
...@@ -92,7 +92,7 @@ protected function setUp() { ...@@ -92,7 +92,7 @@ protected function setUp() {
// Assert that the toolbar is present in the HTML. // Assert that the toolbar is present in the HTML.
$this->assertRaw('id="toolbar-administration"'); $this->assertRaw('id="toolbar-administration"');
// Store the admin_user admin menu subtrees hash for comparison later. // Store the adminUser admin menu subtrees hash for comparison later.
$this->hash = $this->getSubtreesHash(); $this->hash = $this->getSubtreesHash();
} }
...@@ -149,7 +149,7 @@ function testMenuLinkUpdateSubtreesHashCacheClear() { ...@@ -149,7 +149,7 @@ function testMenuLinkUpdateSubtreesHashCacheClear() {
*/ */
function testUserRoleUpdateSubtreesHashCacheClear() { function testUserRoleUpdateSubtreesHashCacheClear() {
// Find the new role ID. // Find the new role ID.
$all_rids = $this->admin_user->getRoles(); $all_rids = $this->adminUser->getRoles();
unset($all_rids[array_search(DRUPAL_AUTHENTICATED_RID, $all_rids)]); unset($all_rids[array_search(DRUPAL_AUTHENTICATED_RID, $all_rids)]);
$rid = reset($all_rids); $rid = reset($all_rids);
...@@ -163,7 +163,7 @@ function testUserRoleUpdateSubtreesHashCacheClear() { ...@@ -163,7 +163,7 @@ function testUserRoleUpdateSubtreesHashCacheClear() {
// Test that assigning a user an extra role only affects that single user. // Test that assigning a user an extra role only affects that single user.
// Get the hash for a second user. // Get the hash for a second user.
$this->drupalLogin($this->admin_user_2); $this->drupalLogin($this->adminUser2);
$this->drupalGet('test-page'); $this->drupalGet('test-page');
$this->assertResponse(200); $this->assertResponse(200);
...@@ -173,7 +173,7 @@ function testUserRoleUpdateSubtreesHashCacheClear() { ...@@ -173,7 +173,7 @@ function testUserRoleUpdateSubtreesHashCacheClear() {
$admin_user_2_hash = $this->getSubtreesHash(); $admin_user_2_hash = $this->getSubtreesHash();
// Log in the first admin user again. // Log in the first admin user again.
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->adminUser);
$this->drupalGet('test-page'); $this->drupalGet('test-page');
$this->assertResponse(200); $this->assertResponse(200);
...@@ -185,7 +185,7 @@ function testUserRoleUpdateSubtreesHashCacheClear() { ...@@ -185,7 +185,7 @@ function testUserRoleUpdateSubtreesHashCacheClear() {
$rid = $this->drupalCreateRole(array('administer content types',)); $rid = $this->drupalCreateRole(array('administer content types',));
// Assign the role to the user. // Assign the role to the user.
$this->drupalPostForm('user/' . $this->admin_user->id() . '/edit', array("roles[$rid]" => $rid), t('Save')); $this->drupalPostForm('user/' . $this->adminUser->id() . '/edit', array("roles[$rid]" => $rid), t('Save'));
$this->assertText(t('The changes have been saved.')); $this->assertText(t('The changes have been saved.'));
// Assert that the subtrees hash has been altered because the subtrees // Assert that the subtrees hash has been altered because the subtrees
...@@ -194,7 +194,7 @@ function testUserRoleUpdateSubtreesHashCacheClear() { ...@@ -194,7 +194,7 @@ function testUserRoleUpdateSubtreesHashCacheClear() {
// Log in the second user again and assert that their subtrees hash did not // Log in the second user again and assert that their subtrees hash did not
// change. // change.
$this->drupalLogin($this->admin_user_2); $this->drupalLogin($this->adminUser2);
// Request a new page to refresh the drupalSettings object. // Request a new page to refresh the drupalSettings object.
$this->drupalGet('test-page'); $this->drupalGet('test-page');
...@@ -214,17 +214,17 @@ function testUserRoleUpdateSubtreesHashCacheClear() { ...@@ -214,17 +214,17 @@ function testUserRoleUpdateSubtreesHashCacheClear() {
function testCacheClearByCacheTag() { function testCacheClearByCacheTag() {
// Test that the toolbar admin menu subtrees cache is invalidated for a user // Test that the toolbar admin menu subtrees cache is invalidated for a user
// across multiple languages. // across multiple languages.
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->adminUser);
$toolbarCache = $this->container->get('cache.toolbar'); $toolbarCache = $this->container->get('cache.toolbar');
$admin_user_id = $this->admin_user->id(); $admin_user_id = $this->adminUser->id();
$admin_user_2_id = $this->admin_user_2->id(); $admin_user_2_id = $this->adminUser2->id();
// Assert that a cache tag in the toolbar cache under the key "user" exists // Assert that a cache tag in the toolbar cache under the key "user" exists
// for admin_user against the language "en". // for adminUser against the language "en".
$cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'en'); $cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'en');
$this->assertEqual($cache->tags[2], 'user:' . $admin_user_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user against the language "en".'); $this->assertEqual($cache->tags[2], 'user:' . $admin_user_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user against the language "en".');
// Assert that no toolbar cache exists for admin_user against the // Assert that no toolbar cache exists for adminUser against the
// language "fr". // language "fr".
$cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'fr'); $cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'fr');
$this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "fr".'); $this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "fr".');
...@@ -240,20 +240,20 @@ function testCacheClearByCacheTag() { ...@@ -240,20 +240,20 @@ function testCacheClearByCacheTag() {
$this->assertResponse(200); $this->assertResponse(200);
// Assert that a cache tag in the toolbar cache under the key "user" exists // Assert that a cache tag in the toolbar cache under the key "user" exists
// for admin_user against the language "fr". // for adminUser against the language "fr".
$cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'fr'); $cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . 'fr');
$this->assertEqual($cache->tags[2], 'user:' . $admin_user_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user against the language "fr".'); $this->assertEqual($cache->tags[2], 'user:' . $admin_user_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user against the language "fr".');
// Log in the admin_user_2 user. We will use this user as a control to // Log in the adminUser2 user. We will use this user as a control to
// verify that clearing a cache tag for admin_user does not clear the cache // verify that clearing a cache tag for adminUser does not clear the cache
// for admin_user_2. // for adminUser2.
$this->drupalLogin($this->admin_user_2); $this->drupalLogin($this->adminUser2);
// Request a page in 'en' to create the cache. // Request a page in 'en' to create the cache.
$this->drupalGet('test-page'); $this->drupalGet('test-page');
$this->assertResponse(200); $this->assertResponse(200);
// Assert that a cache tag in the toolbar cache under the key "user" exists // Assert that a cache tag in the toolbar cache under the key "user" exists
// for admin_user_2 against the language "en". // for adminUser2 against the language "en".
$cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'en'); $cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'en');
$this->assertEqual($cache->tags[2], 'user:' . $admin_user_2_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "en".'); $this->assertEqual($cache->tags[2], 'user:' . $admin_user_2_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "en".');
...@@ -261,34 +261,34 @@ function testCacheClearByCacheTag() { ...@@ -261,34 +261,34 @@ function testCacheClearByCacheTag() {
$this->drupalGet('fr/test-page'); $this->drupalGet('fr/test-page');
$this->assertResponse(200); $this->assertResponse(200);
// Assert that a cache tag in the toolbar cache under the key "user" exists // Assert that a cache tag in the toolbar cache under the key "user" exists
// for admin_user against the language "fr". // for adminUser against the language "fr".
$cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'fr'); $cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'fr');
$this->assertEqual($cache->tags[2], 'user:' . $admin_user_2_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "fr".'); $this->assertEqual($cache->tags[2], 'user:' . $admin_user_2_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "fr".');
// Log in admin_user and clear the caches for this user using a tag. // Log in adminUser and clear the caches for this user using a tag.
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->adminUser);
Cache::deleteTags(array('user:' . $admin_user_id)); Cache::deleteTags(array('user:' . $admin_user_id));
// Assert that no toolbar cache exists for admin_user against the // Assert that no toolbar cache exists for adminUser against the
// language "en". // language "en".
$cache = $toolbarCache->get($admin_user_id . ':' . 'en'); $cache = $toolbarCache->get($admin_user_id . ':' . 'en');
$this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "en".'); $this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "en".');
// Assert that no toolbar cache exists for admin_user against the // Assert that no toolbar cache exists for adminUser against the
// language "fr". // language "fr".
$cache = $toolbarCache->get($admin_user_id . ':' . 'fr'); $cache = $toolbarCache->get($admin_user_id . ':' . 'fr');
$this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "fr".'); $this->assertFalse($cache, 'No toolbar cache exists for admin_user against the language "fr".');
// Log in admin_user_2 and verify that this user's caches still exist. // Log in adminUser2 and verify that this user's caches still exist.
$this->drupalLogin($this->admin_user_2); $this->drupalLogin($this->adminUser2);
// Assert that a cache tag in the toolbar cache under the key "user" exists // Assert that a cache tag in the toolbar cache under the key "user" exists
// for admin_user_2 against the language "en". // for adminUser2 against the language "en".
$cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'en'); $cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'en');
$this->assertEqual($cache->tags[2], 'user:' . $admin_user_2_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "en".'); $this->assertEqual($cache->tags[2], 'user:' . $admin_user_2_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "en".');
// Assert that a cache tag in the toolbar cache under the key "user" exists // Assert that a cache tag in the toolbar cache under the key "user" exists
// for admin_user_2 against the language "fr". // for adminUser2 against the language "fr".
$cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'fr'); $cache = $toolbarCache->get('toolbar_' . $admin_user_2_id . ':' . 'fr');
$this->assertEqual($cache->tags[2], 'user:' . $admin_user_2_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "fr".'); $this->assertEqual($cache->tags[2], 'user:' . $admin_user_2_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user_2 against the language "fr".');
} }
...@@ -299,15 +299,15 @@ function testCacheClearByCacheTag() { ...@@ -299,15 +299,15 @@ function testCacheClearByCacheTag() {
*/ */
function testNonCurrentUserAccountUpdates() { function testNonCurrentUserAccountUpdates() {
$toolbarCache = $this->container->get('cache.toolbar'); $toolbarCache = $this->container->get('cache.toolbar');
$admin_user_id = $this->admin_user->id(); $admin_user_id = $this->adminUser->id();
$admin_user_2_id = $this->admin_user_2->id(); $admin_user_2_id = $this->adminUser2->id();
$this->hash = $this->getSubtreesHash(); $this->hash = $this->getSubtreesHash();
// admin_user_2 will add a role to admin_user. // adminUser2 will add a role to adminUser.
$this->drupalLogin($this->admin_user_2); $this->drupalLogin($this->adminUser2);
$rid = $this->drupalCreateRole(array('administer content types',)); $rid = $this->drupalCreateRole(array('administer content types',));
// Get the subtree hash for admin_user_2 to check later that it has not // Get the subtree hash for adminUser2 to check later that it has not
// changed. Request a new page to refresh the drupalSettings object. // changed. Request a new page to refresh the drupalSettings object.
$this->drupalGet('test-page'); $this->drupalGet('test-page');
$this->assertResponse(200); $this->assertResponse(200);
...@@ -317,15 +317,15 @@ function testNonCurrentUserAccountUpdates() { ...@@ -317,15 +317,15 @@ function testNonCurrentUserAccountUpdates() {
$this->drupalPostForm('user/' . $admin_user_id . '/edit', array("roles[$rid]" => $rid), t('Save')); $this->drupalPostForm('user/' . $admin_user_id . '/edit', array("roles[$rid]" => $rid), t('Save'));
$this->assertText(t('The changes have been saved.')); $this->assertText(t('The changes have been saved.'));
// Log in admin_user and assert that the subtrees hash has changed. // Log in adminUser and assert that the subtrees hash has changed.
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->adminUser);
$this->assertDifferentHash(); $this->assertDifferentHash();
// Log in admin_user_2 to check that its subtrees hash has not changed. // Log in adminUser2 to check that its subtrees hash has not changed.
$this->drupalLogin($this->admin_user_2); $this->drupalLogin($this->adminUser2);
$new_subtree_hash = $this->getSubtreesHash(); $new_subtree_hash = $this->getSubtreesHash();
// Assert that the old admin_user subtree hash and the new admin_user // Assert that the old adminUser subtree hash and the new adminUser
// subtree hash are the same. // subtree hash are the same.
$this->assertTrue($new_subtree_hash, 'A valid hash value for the admin menu subtrees was created.'); $this->assertTrue($new_subtree_hash, 'A valid hash value for the admin menu subtrees was created.');
$this->assertEqual($admin_user_2_hash, $new_subtree_hash, 'The user-specific subtree menu hash has not been updated.'); $this->assertEqual($admin_user_2_hash, $new_subtree_hash, 'The user-specific subtree menu hash has not been updated.');
...@@ -336,8 +336,8 @@ function testNonCurrentUserAccountUpdates() { ...@@ -336,8 +336,8 @@ function testNonCurrentUserAccountUpdates() {
*/ */
function testLocaleTranslationSubtreesHashCacheClear() { function testLocaleTranslationSubtreesHashCacheClear() {
$toolbarCache = $this->container->get('cache.toolbar'); $toolbarCache = $this->container->get('cache.toolbar');
$admin_user = $this->admin_user; $admin_user = $this->adminUser;
$admin_user_id = $this->admin_user->id(); $admin_user_id = $this->adminUser->id();
// User to translate and delete string. // User to translate and delete string.
$translate_user = $this->drupalCreateUser(array('translate interface', 'access administration pages')); $translate_user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
...@@ -367,12 +367,12 @@ function testLocaleTranslationSubtreesHashCacheClear() { ...@@ -367,12 +367,12 @@ function testLocaleTranslationSubtreesHashCacheClear() {
$this->assertRaw('"edit-languages-' . $langcode .'-weight"', 'Language code found.'); $this->assertRaw('"edit-languages-' . $langcode .'-weight"', 'Language code found.');
$this->assertText(t($name), 'Test language added.'); $this->assertText(t($name), 'Test language added.');
// Have the admin_user request a page in the new language. // Have the adminUser request a page in the new language.
$this->drupalGet($langcode . '/test-page'); $this->drupalGet($langcode . '/test-page');
$this->assertResponse(200); $this->assertResponse(200);
// Assert that a cache tag in the toolbar cache under the key "user" exists // Assert that a cache tag in the toolbar cache under the key "user" exists
// for admin_user against the language "xx". // for adminUser against the language "xx".
$cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . $langcode); $cache = $toolbarCache->get('toolbar_' . $admin_user_id . ':' . $langcode);
$this->assertEqual($cache->tags[2], 'user:' . $admin_user_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user against the language "xx".'); $this->assertEqual($cache->tags[2], 'user:' . $admin_user_id, 'A cache tag in the toolbar cache under the key "user" exists for admin_user against the language "xx".');
...@@ -407,11 +407,11 @@ function testLocaleTranslationSubtreesHashCacheClear() { ...@@ -407,11 +407,11 @@ function testLocaleTranslationSubtreesHashCacheClear() {
$this->assertUrl(\Drupal::url('locale.translate_page', [], ['absolute' => TRUE]), [], 'Correct page redirection.'); $this->assertUrl(\Drupal::url('locale.translate_page', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
$this->drupalLogout(); $this->drupalLogout();
// Log in the admin_user. Check the admin menu subtrees hash now that one // Log in the adminUser. Check the admin menu subtrees hash now that one
// of the link items in the Structure tree (Menus) has had its text // of the link items in the Structure tree (Menus) has had its text
// translated. // translated.
$this->drupalLogin($admin_user); $this->drupalLogin($admin_user);
// Have the admin_user request a page in the new language. // Have the adminUser request a page in the new language.
$this->drupalGet($langcode . '/test-page'); $this->drupalGet($langcode . '/test-page');
$this->assertResponse(200); $this->assertResponse(200);
$new_subtree_hash = $this->getSubtreesHash(); $new_subtree_hash = $this->getSubtreesHash();
...@@ -426,7 +426,7 @@ function testLocaleTranslationSubtreesHashCacheClear() { ...@@ -426,7 +426,7 @@ function testLocaleTranslationSubtreesHashCacheClear() {
* Tests that the 'toolbar/subtrees/{hash}' is reachable. * Tests that the 'toolbar/subtrees/{hash}' is reachable.
*/ */
function testSubtreesJsonRequest() { function testSubtreesJsonRequest() {
$admin_user = $this->admin_user; $admin_user = $this->adminUser;
$this->drupalLogin($admin_user); $this->drupalLogin($admin_user);
// Request a new page to refresh the drupalSettings object. // Request a new page to refresh the drupalSettings object.
$subtrees_hash = $this->getSubtreesHash(); $subtrees_hash = $this->getSubtreesHash();
......
...@@ -16,6 +16,13 @@ ...@@ -16,6 +16,13 @@
*/ */
class ToolbarHookToolbarTest extends WebTestBase { class ToolbarHookToolbarTest extends WebTestBase {
/**
* A user with permission to access the administrative toolbar.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/** /**
* Modules to enable. * Modules to enable.
* *
...@@ -27,8 +34,8 @@ protected function setUp() { ...@@ -27,8 +34,8 @@ protected function setUp() {
parent::setUp(); parent::setUp();
// Create an administrative user and log it in. // Create an administrative user and log it in.
$this->admin_user = $this->drupalCreateUser(array('access toolbar')); $this->adminUser = $this->drupalCreateUser(array('access toolbar'));
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->adminUser);
} }
/** /**
......
...@@ -16,6 +16,13 @@ ...@@ -16,6 +16,13 @@
*/ */
class ToolbarMenuTranslationTest extends WebTestBase { class ToolbarMenuTranslationTest extends WebTestBase {
/**
* A user with permission to access the administrative toolbar.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/** /**
* Modules to enable. * Modules to enable.
* *
...@@ -27,8 +34,8 @@ protected function setUp() { ...@@ -27,8 +34,8 @@ protected function setUp() {
parent::setUp(); parent::setUp();
// Create an administrative user and log it in. // Create an administrative user and log it in.
$this->admin_user = $this->drupalCreateUser(array('access toolbar', 'translate interface', 'administer languages', 'access administration pages')); $this->adminUser = $this->drupalCreateUser(array('access toolbar', 'translate interface', 'administer languages', 'access administration pages'));
$this->drupalLogin($this->admin_user); $this->drupalLogin($this->adminUser);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment