Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
@ -0,0 +1,430 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\toolbar\Functional;
|
||||
|
||||
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\user\RoleInterface;
|
||||
|
||||
/**
|
||||
* Tests the caching of the admin menu subtree items.
|
||||
*
|
||||
* The cache of the admin menu subtree items will be invalidated if the
|
||||
* following hooks are invoked.
|
||||
*
|
||||
* toolbar_modules_enabled()
|
||||
* toolbar_modules_disabled()
|
||||
* toolbar_menu_link_update()
|
||||
* toolbar_user_update()
|
||||
* toolbar_user_role_update()
|
||||
*
|
||||
* Each hook invocation is simulated and then the previous hash of the admin
|
||||
* menu subtrees is compared to the new hash.
|
||||
*
|
||||
* @group toolbar
|
||||
*/
|
||||
class ToolbarAdminMenuTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* A user with permission to access the administrative toolbar.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* A second user with permission to access the administrative toolbar.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser2;
|
||||
|
||||
/**
|
||||
* The current admin menu subtrees hash for adminUser.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $hash;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node', 'block', 'menu_ui', 'user', 'taxonomy', 'toolbar', 'language', 'test_page_test', 'locale'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$perms = [
|
||||
'access toolbar',
|
||||
'access administration pages',
|
||||
'administer site configuration',
|
||||
'bypass node access',
|
||||
'administer themes',
|
||||
'administer nodes',
|
||||
'access content overview',
|
||||
'administer blocks',
|
||||
'administer menu',
|
||||
'administer modules',
|
||||
'administer permissions',
|
||||
'administer users',
|
||||
'access user profiles',
|
||||
'administer taxonomy',
|
||||
'administer languages',
|
||||
'translate interface',
|
||||
];
|
||||
|
||||
// Create an administrative user and log it in.
|
||||
$this->adminUser = $this->drupalCreateUser($perms);
|
||||
$this->adminUser2 = $this->drupalCreateUser($perms);
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Assert that the toolbar is present in the HTML.
|
||||
$this->assertRaw('id="toolbar-administration"');
|
||||
|
||||
// Store the adminUser admin menu subtrees hash for comparison later.
|
||||
$this->hash = $this->getSubtreesHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the toolbar_modules_installed() and toolbar_modules_uninstalled() hook
|
||||
* implementations.
|
||||
*/
|
||||
public function testModuleStatusChangeSubtreesHashCacheClear() {
|
||||
// Uninstall a module.
|
||||
$edit = [];
|
||||
$edit['uninstall[taxonomy]'] = TRUE;
|
||||
$this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
|
||||
// Confirm the uninstall form.
|
||||
$this->drupalPostForm(NULL, [], t('Uninstall'));
|
||||
$this->rebuildContainer();
|
||||
|
||||
// Assert that the subtrees hash has been altered because the subtrees
|
||||
// structure changed.
|
||||
$this->assertDifferentHash();
|
||||
|
||||
// Enable a module.
|
||||
$edit = [];
|
||||
$edit['modules[taxonomy][enable]'] = TRUE;
|
||||
$this->drupalPostForm('admin/modules', $edit, t('Install'));
|
||||
$this->rebuildContainer();
|
||||
|
||||
// Assert that the subtrees hash has been altered because the subtrees
|
||||
// structure changed.
|
||||
$this->assertDifferentHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests toolbar cache tags implementation.
|
||||
*/
|
||||
public function testMenuLinkUpdateSubtreesHashCacheClear() {
|
||||
// The ID of a (any) admin menu link.
|
||||
$admin_menu_link_id = 'system.admin_config_development';
|
||||
|
||||
// Disable the link.
|
||||
$edit = [];
|
||||
$edit['enabled'] = FALSE;
|
||||
$this->drupalPostForm("admin/structure/menu/link/" . $admin_menu_link_id . "/edit", $edit, t('Save'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('The menu link has been saved.');
|
||||
|
||||
// Assert that the subtrees hash has been altered because the subtrees
|
||||
// structure changed.
|
||||
$this->assertDifferentHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exercises the toolbar_user_role_update() and toolbar_user_update() hook
|
||||
* implementations.
|
||||
*/
|
||||
public function testUserRoleUpdateSubtreesHashCacheClear() {
|
||||
// Find the new role ID.
|
||||
$all_rids = $this->adminUser->getRoles();
|
||||
unset($all_rids[array_search(RoleInterface::AUTHENTICATED_ID, $all_rids)]);
|
||||
$rid = reset($all_rids);
|
||||
|
||||
$edit = [];
|
||||
$edit[$rid . '[administer taxonomy]'] = FALSE;
|
||||
$this->drupalPostForm('admin/people/permissions', $edit, t('Save permissions'));
|
||||
|
||||
// Assert that the subtrees hash has been altered because the subtrees
|
||||
// structure changed.
|
||||
$this->assertDifferentHash();
|
||||
|
||||
// Test that assigning a user an extra role only affects that single user.
|
||||
// Get the hash for a second user.
|
||||
$this->drupalLogin($this->adminUser2);
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Assert that the toolbar is present in the HTML.
|
||||
$this->assertRaw('id="toolbar-administration"');
|
||||
|
||||
$admin_user_2_hash = $this->getSubtreesHash();
|
||||
|
||||
// Log in the first admin user again.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Assert that the toolbar is present in the HTML.
|
||||
$this->assertRaw('id="toolbar-administration"');
|
||||
|
||||
$this->hash = $this->getSubtreesHash();
|
||||
|
||||
$rid = $this->drupalCreateRole(['administer content types']);
|
||||
|
||||
// Assign the role to the user.
|
||||
$this->drupalPostForm('user/' . $this->adminUser->id() . '/edit', ["roles[$rid]" => $rid], t('Save'));
|
||||
$this->assertText(t('The changes have been saved.'));
|
||||
|
||||
// Assert that the subtrees hash has been altered because the subtrees
|
||||
// structure changed.
|
||||
$this->assertDifferentHash();
|
||||
|
||||
// Log in the second user again and assert that their subtrees hash did not
|
||||
// change.
|
||||
$this->drupalLogin($this->adminUser2);
|
||||
|
||||
// Request a new page to refresh the drupalSettings object.
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertResponse(200);
|
||||
$new_subtree_hash = $this->getSubtreesHash();
|
||||
|
||||
// Assert that the old admin menu subtree hash and the new admin menu
|
||||
// subtree hash are the same.
|
||||
$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.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that changes to a user account by another user clears the changed
|
||||
* account's toolbar cached, not the user's who took the action.
|
||||
*/
|
||||
public function testNonCurrentUserAccountUpdates() {
|
||||
$admin_user_id = $this->adminUser->id();
|
||||
$this->hash = $this->getSubtreesHash();
|
||||
|
||||
// adminUser2 will add a role to adminUser.
|
||||
$this->drupalLogin($this->adminUser2);
|
||||
$rid = $this->drupalCreateRole(['administer content types']);
|
||||
|
||||
// Get the subtree hash for adminUser2 to check later that it has not
|
||||
// changed. Request a new page to refresh the drupalSettings object.
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertResponse(200);
|
||||
$admin_user_2_hash = $this->getSubtreesHash();
|
||||
|
||||
// Assign the role to the user.
|
||||
$this->drupalPostForm('user/' . $admin_user_id . '/edit', ["roles[$rid]" => $rid], t('Save'));
|
||||
$this->assertText(t('The changes have been saved.'));
|
||||
|
||||
// Log in adminUser and assert that the subtrees hash has changed.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->assertDifferentHash();
|
||||
|
||||
// Log in adminUser2 to check that its subtrees hash has not changed.
|
||||
$this->drupalLogin($this->adminUser2);
|
||||
$new_subtree_hash = $this->getSubtreesHash();
|
||||
|
||||
// Assert that the old adminUser subtree hash and the new adminUser
|
||||
// subtree hash are the same.
|
||||
$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.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that toolbar cache is cleared when string translations are made.
|
||||
*/
|
||||
public function testLocaleTranslationSubtreesHashCacheClear() {
|
||||
$admin_user = $this->adminUser;
|
||||
// User to translate and delete string.
|
||||
$translate_user = $this->drupalCreateUser(['translate interface', 'access administration pages']);
|
||||
|
||||
// Create a new language with the langcode 'xx'.
|
||||
$langcode = 'xx';
|
||||
// The English name for the language. This will be translated.
|
||||
$name = $this->randomMachineName(16);
|
||||
// This will be the translation of $name.
|
||||
$translation = $this->randomMachineName(16);
|
||||
|
||||
// Add custom language.
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = [
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => $langcode,
|
||||
'label' => $name,
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
t($name, [], ['langcode' => $langcode]);
|
||||
// Reset locale cache.
|
||||
$this->container->get('string_translation')->reset();
|
||||
$this->assertRaw('"edit-languages-' . $langcode . '-weight"', 'Language code found.');
|
||||
$this->assertText(t($name), 'Test language added.');
|
||||
|
||||
// Have the adminUser request a page in the new language.
|
||||
$this->drupalGet($langcode . '/test-page');
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Get a baseline hash for the admin menu subtrees before translating one
|
||||
// of the menu link items.
|
||||
$original_subtree_hash = $this->getSubtreesHash();
|
||||
$this->assertTrue($original_subtree_hash, 'A valid hash value for the admin menu subtrees was created.');
|
||||
$this->drupalLogout();
|
||||
|
||||
// Translate the string 'Search and metadata' in the xx language. This
|
||||
// string appears in a link in the admin menu subtrees. Changing the string
|
||||
// should create a new menu hash if the toolbar subtrees cache is correctly
|
||||
// invalidated.
|
||||
$this->drupalLogin($translate_user);
|
||||
$search = [
|
||||
'string' => 'Search and metadata',
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'untranslated',
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
$this->assertNoText(t('No strings available'));
|
||||
$this->assertText($name, 'Search found the string as untranslated.');
|
||||
|
||||
// Assume this is the only result.
|
||||
// Translate the string to a random string.
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea->getAttribute('name');
|
||||
$edit = [
|
||||
$lid => $translation,
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
$this->assertText(t('The strings have been saved.'), 'The strings have been saved.');
|
||||
$this->assertUrl(\Drupal::url('locale.translate_page', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
|
||||
$this->drupalLogout();
|
||||
|
||||
// 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
|
||||
// translated.
|
||||
$this->drupalLogin($admin_user);
|
||||
// Have the adminUser request a page in the new language.
|
||||
$this->drupalGet($langcode . '/test-page');
|
||||
$this->assertResponse(200);
|
||||
$new_subtree_hash = $this->getSubtreesHash();
|
||||
|
||||
// Assert that the old admin menu subtrees hash and the new admin menu
|
||||
// subtrees hash are different.
|
||||
$this->assertTrue($new_subtree_hash, 'A valid hash value for the admin menu subtrees was created.');
|
||||
$this->assertNotEqual($original_subtree_hash, $new_subtree_hash, 'The user-specific subtree menu hash has been updated.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the 'toolbar/subtrees/{hash}' is reachable and correct.
|
||||
*/
|
||||
public function testSubtreesJsonRequest() {
|
||||
$admin_user = $this->adminUser;
|
||||
$this->drupalLogin($admin_user);
|
||||
// Request a new page to refresh the drupalSettings object.
|
||||
$subtrees_hash = $this->getSubtreesHash();
|
||||
|
||||
$this->drupalGet('toolbar/subtrees/' . $subtrees_hash, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']], ['X-Requested-With: XMLHttpRequest']);
|
||||
$ajax_result = json_decode($this->getSession()->getPage()->getContent(), TRUE);
|
||||
$this->assertEqual($ajax_result[0]['command'], 'setToolbarSubtrees', 'Subtrees response uses the correct command.');
|
||||
$this->assertEqual(array_keys($ajax_result[0]['subtrees']), ['system-admin_content', 'system-admin_structure', 'system-themes_page', 'system-modules_list', 'system-admin_config', 'entity-user-collection', 'front'], 'Correct subtrees returned.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that subtrees hashes vary by the language of the page.
|
||||
*/
|
||||
public function testLanguageSwitching() {
|
||||
// Create a new language with the langcode 'xx'.
|
||||
$langcode = 'xx';
|
||||
$language = ConfigurableLanguage::createFromLangcode($langcode);
|
||||
$language->save();
|
||||
// The language path processor is just registered for more than one
|
||||
// configured language, so rebuild the container now that we are
|
||||
// multilingual.
|
||||
$this->rebuildContainer();
|
||||
|
||||
// Get a page with the new language langcode in the URL.
|
||||
$this->drupalGet('test-page', ['language' => $language]);
|
||||
// Assert different hash.
|
||||
$new_subtree_hash = $this->getSubtreesHash();
|
||||
|
||||
// Assert that the old admin menu subtree hash and the new admin menu
|
||||
// subtree hash are different.
|
||||
$this->assertTrue($new_subtree_hash, 'A valid hash value for the admin menu subtrees was created.');
|
||||
$this->assertNotEqual($this->hash, $new_subtree_hash, 'The user-specific subtree menu hash has been updated.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that back to site link exists on admin pages, not on content pages.
|
||||
*/
|
||||
public function testBackToSiteLink() {
|
||||
// Back to site link should exist in the markup.
|
||||
$this->drupalGet('test-page');
|
||||
$back_link = $this->cssSelect('.home-toolbar-tab');
|
||||
$this->assertTrue($back_link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that external links added to the menu appear in the toolbar.
|
||||
*/
|
||||
public function testExternalLink() {
|
||||
$edit = [
|
||||
'title[0][value]' => 'External URL',
|
||||
'link[0][uri]' => 'http://example.org',
|
||||
'menu_parent' => 'admin:system.admin',
|
||||
'description[0][value]' => 'External URL & escaped',
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/menu/manage/admin/add', $edit, 'Save');
|
||||
|
||||
// Assert that the new menu link is shown on the menu link listing.
|
||||
$this->drupalGet('admin/structure/menu/manage/admin');
|
||||
$this->assertText('External URL');
|
||||
|
||||
// Assert that the new menu link is shown in the toolbar on a regular page.
|
||||
$this->drupalGet(Url::fromRoute('<front>'));
|
||||
$this->assertText('External URL');
|
||||
// Ensure the description is escaped as expected.
|
||||
$this->assertRaw('title="External URL & escaped"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hash value from the admin menu subtrees route path.
|
||||
*
|
||||
* @return string
|
||||
* The hash value from the admin menu subtrees route path.
|
||||
*/
|
||||
private function getSubtreesHash() {
|
||||
$settings = $this->getDrupalSettings();
|
||||
// The toolbar module defines a route '/toolbar/subtrees/{hash}' that
|
||||
// returns JSON for the rendered subtrees. This hash is provided to the
|
||||
// client in drupalSettings.
|
||||
return $settings['toolbar']['subtreesHash'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts the subtrees hash on a fresh page GET is different from the hash
|
||||
* from the previous page GET.
|
||||
*/
|
||||
private function assertDifferentHash() {
|
||||
// Request a new page to refresh the drupalSettings object.
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertResponse(200);
|
||||
$new_subtree_hash = $this->getSubtreesHash();
|
||||
|
||||
// Assert that the old admin menu subtree hash and the new admin menu
|
||||
// subtree hash are different.
|
||||
$this->assertTrue($new_subtree_hash, 'A valid hash value for the admin menu subtrees was created.');
|
||||
$this->assertNotEqual($this->hash, $new_subtree_hash, 'The user-specific subtree menu hash has been updated.');
|
||||
|
||||
// Save the new subtree hash as the original.
|
||||
$this->hash = $new_subtree_hash;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\toolbar\Functional;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
|
||||
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the cache contexts for toolbar.
|
||||
*
|
||||
* @group toolbar
|
||||
*/
|
||||
class ToolbarCacheContextsTest extends BrowserTestBase {
|
||||
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['toolbar', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* An authenticated user to use for testing.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* An authenticated user to use for testing.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser2;
|
||||
|
||||
/**
|
||||
* A list of default permissions for test users.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $perms = [
|
||||
'access toolbar',
|
||||
'access administration pages',
|
||||
'administer site configuration',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser($this->perms);
|
||||
$this->adminUser2 = $this->drupalCreateUser($this->perms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests toolbar cache integration.
|
||||
*/
|
||||
public function testCacheIntegration() {
|
||||
$this->installExtraModules(['dynamic_page_cache']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertSame('MISS', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache'));
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertSame('HIT', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests toolbar cache contexts.
|
||||
*/
|
||||
public function testToolbarCacheContextsCaller() {
|
||||
// Test with default combination and permission to see toolbar.
|
||||
$this->assertToolbarCacheContexts(['user'], 'Expected cache contexts found for default combination and permission to see toolbar.');
|
||||
|
||||
// Test without user toolbar tab. User module is a required module so we have to
|
||||
// manually remove the user toolbar tab.
|
||||
$this->installExtraModules(['toolbar_disable_user_toolbar']);
|
||||
$this->assertToolbarCacheContexts(['user.permissions'], 'Expected cache contexts found without user toolbar tab.');
|
||||
|
||||
// Test with the toolbar and contextual enabled.
|
||||
$this->installExtraModules(['contextual']);
|
||||
$this->adminUser2 = $this->drupalCreateUser(array_merge($this->perms, ['access contextual links']));
|
||||
$this->assertToolbarCacheContexts(['user.permissions'], 'Expected cache contexts found with contextual module enabled.');
|
||||
\Drupal::service('module_installer')->uninstall(['contextual']);
|
||||
|
||||
// Test with the tour module enabled.
|
||||
$this->installExtraModules(['tour']);
|
||||
$this->adminUser2 = $this->drupalCreateUser(array_merge($this->perms, ['access tour']));
|
||||
$this->assertToolbarCacheContexts(['user.permissions'], 'Expected cache contexts found with tour module enabled.');
|
||||
\Drupal::service('module_installer')->uninstall(['tour']);
|
||||
|
||||
// Test with shortcut module enabled.
|
||||
$this->installExtraModules(['shortcut']);
|
||||
$this->adminUser2 = $this->drupalCreateUser(array_merge($this->perms, ['access shortcuts', 'administer shortcuts']));
|
||||
$this->assertToolbarCacheContexts(['user'], 'Expected cache contexts found with shortcut module enabled.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that cache contexts are applied for both users.
|
||||
*
|
||||
* @param string[] $cache_contexts
|
||||
* Expected cache contexts for both users.
|
||||
* @param string $message
|
||||
* (optional) A verbose message to output.
|
||||
*
|
||||
* @return
|
||||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertToolbarCacheContexts(array $cache_contexts, $message = NULL) {
|
||||
// Default cache contexts that should exist on all test cases.
|
||||
$default_cache_contexts = [
|
||||
'languages:language_interface',
|
||||
'theme',
|
||||
'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT,
|
||||
];
|
||||
$cache_contexts = Cache::mergeContexts($default_cache_contexts, $cache_contexts);
|
||||
|
||||
// Assert contexts for user1 which has only default permissions.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalGet('test-page');
|
||||
$return = $this->assertCacheContexts($cache_contexts);
|
||||
$this->drupalLogout();
|
||||
|
||||
// Assert contexts for user2 which has some additional permissions.
|
||||
$this->drupalLogin($this->adminUser2);
|
||||
$this->drupalGet('test-page');
|
||||
$return = $return && $this->assertCacheContexts($cache_contexts);
|
||||
|
||||
if ($return) {
|
||||
$this->pass($message);
|
||||
}
|
||||
else {
|
||||
$this->fail($message);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a given list of modules and rebuilds the cache.
|
||||
*
|
||||
* @param string[] $module_list
|
||||
* An array of module names.
|
||||
*/
|
||||
protected function installExtraModules(array $module_list) {
|
||||
\Drupal::service('module_installer')->install($module_list);
|
||||
|
||||
// Installing modules updates the container and needs a router rebuild.
|
||||
$this->container = \Drupal::getContainer();
|
||||
$this->container->get('router.builder')->rebuildIfNeeded();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\toolbar\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that the toolbar icon class remains for translated menu items.
|
||||
*
|
||||
* @group toolbar
|
||||
*/
|
||||
class ToolbarMenuTranslationTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* A user with permission to access the administrative toolbar.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['toolbar', 'toolbar_test', 'locale', 'locale_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create an administrative user and log it in.
|
||||
$this->adminUser = $this->drupalCreateUser(['access toolbar', 'translate interface', 'administer languages', 'access administration pages']);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that toolbar classes don't change when adding a translation.
|
||||
*/
|
||||
public function testToolbarClasses() {
|
||||
$langcode = 'es';
|
||||
|
||||
// Add Spanish.
|
||||
$edit['predefined_langcode'] = $langcode;
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
|
||||
// The menu item 'Structure' in the toolbar will be translated.
|
||||
$menu_item = 'Structure';
|
||||
|
||||
// Visit a page that has the string on it so it can be translated.
|
||||
$this->drupalGet($langcode . '/admin/structure');
|
||||
|
||||
// Search for the menu item.
|
||||
$search = [
|
||||
'string' => $menu_item,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'untranslated',
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
// Make sure will be able to translate the menu item.
|
||||
$this->assertNoText('No strings available.', 'Search found the menu item as untranslated.');
|
||||
|
||||
// Check that the class is on the item before we translate it.
|
||||
$xpath = $this->xpath('//a[contains(@class, "icon-system-admin-structure")]');
|
||||
$this->assertEqual(count($xpath), 1, 'The menu item class ok before translation.');
|
||||
|
||||
// Translate the menu item.
|
||||
$menu_item_translated = $this->randomMachineName();
|
||||
$textarea = current($this->xpath('//textarea'));
|
||||
$lid = (string) $textarea->getAttribute('name');
|
||||
$edit = [
|
||||
$lid => $menu_item_translated,
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
|
||||
|
||||
// Search for the translated menu item.
|
||||
$search = [
|
||||
'string' => $menu_item,
|
||||
'langcode' => $langcode,
|
||||
'translation' => 'translated',
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
|
||||
// Make sure the menu item string was translated.
|
||||
$this->assertText($menu_item_translated, 'Search found the menu item as translated: ' . $menu_item_translated . '.');
|
||||
|
||||
// Go to another page in the custom language and make sure the menu item
|
||||
// was translated.
|
||||
$this->drupalGet($langcode . '/admin/structure');
|
||||
$this->assertText($menu_item_translated, 'Found the menu translated.');
|
||||
|
||||
// Toolbar icons are included based on the presence of a specific class on
|
||||
// the menu item. Ensure that class also exists for a translated menu item.
|
||||
$xpath = $this->xpath('//a[contains(@class, "icon-system-admin-structure")]');
|
||||
$this->assertEqual(count($xpath), 1, 'The menu item class is the same.');
|
||||
}
|
||||
|
||||
}
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace Drupal\Tests\toolbar\FunctionalJavascript;
|
||||
|
||||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
|
||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||
|
||||
/**
|
||||
* Tests the JavaScript functionality of the toolbar.
|
||||
*
|
||||
* @group toolbar
|
||||
*/
|
||||
class ToolbarIntegrationTest extends JavascriptTestBase {
|
||||
class ToolbarIntegrationTest extends WebDriverTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -27,7 +27,12 @@ class ToolbarIntegrationTest extends JavascriptTestBase {
|
|||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// Set size for horizontal toolbar.
|
||||
$this->getSession()->resizeWindow(1200, 600);
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertNotEmpty($this->assertSession()->waitForElement('css', 'body.toolbar-horizontal'));
|
||||
$this->assertNotEmpty($this->assertSession()->waitForElementVisible('css', '.toolbar-tray'));
|
||||
|
||||
$page = $this->getSession()->getPage();
|
||||
|
||||
// Test that it is possible to toggle the toolbar tray.
|
||||
|
|
Reference in a new issue