This commit is contained in:
2020-07-13 17:09:59 +02:00
parent 03559a7b76
commit 3a082e23cc
492 changed files with 4129 additions and 982 deletions
@@ -26,6 +26,7 @@
*
* @param $account
* The user account whose default shortcut set is being requested.
*
* @return string
* The name of the shortcut set that this module recommends for that user, if
* there is one.
@@ -117,7 +117,7 @@ class ShortcutCacheTagsTest extends EntityCacheTagsTestBase {
// Verify that users without the 'access shortcuts' permission can't see the
// shortcuts.
$this->drupalLogin($this->drupalCreateUser(['access toolbar']));
$this->assertNoLink('Shortcuts');
$this->assertSession()->linkNotExists('Shortcuts');
$this->verifyDynamicPageCache($test_page_url, 'MISS');
$this->verifyDynamicPageCache($test_page_url, 'HIT');
@@ -129,8 +129,8 @@ class ShortcutCacheTagsTest extends EntityCacheTagsTestBase {
]));
$this->verifyDynamicPageCache($test_page_url, 'MISS');
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertLink('Shortcuts');
$this->assertNoLink('Cron');
$this->assertSession()->linkExists('Shortcuts');
$this->assertSession()->linkNotExists('Cron');
// Create a role with access to shortcuts as well as the necessary
// permissions to see specific shortcuts.
@@ -155,14 +155,14 @@ class ShortcutCacheTagsTest extends EntityCacheTagsTestBase {
$this->verifyDynamicPageCache($test_page_url, 'MISS');
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertCacheContexts(['user', 'url.query_args:_wrapper_format']);
$this->assertLink('Shortcuts');
$this->assertLink('Cron');
$this->assertSession()->linkExists('Shortcuts');
$this->assertSession()->linkExists('Cron');
$this->drupalLogin($site_configuration_user2);
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertCacheContexts(['user', 'url.query_args:_wrapper_format']);
$this->assertLink('Shortcuts');
$this->assertLink('Cron');
$this->assertSession()->linkExists('Shortcuts');
$this->assertSession()->linkExists('Cron');
// Add another shortcut.
$shortcut = Shortcut::create([
@@ -176,21 +176,21 @@ class ShortcutCacheTagsTest extends EntityCacheTagsTestBase {
// The shortcuts are displayed in a lazy builder, so the page is still a
// cache HIT but shows the new shortcut immediately.
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertLink('Cron');
$this->assertLink('Llama');
$this->assertSession()->linkExists('Cron');
$this->assertSession()->linkExists('Llama');
// Update the shortcut title and assert that it is updated.
$shortcut->set('title', 'Alpaca');
$shortcut->save();
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertLink('Cron');
$this->assertLink('Alpaca');
$this->assertSession()->linkExists('Cron');
$this->assertSession()->linkExists('Alpaca');
// Delete the shortcut and assert that the link is gone.
$shortcut->delete();
$this->verifyDynamicPageCache($test_page_url, 'HIT');
$this->assertLink('Cron');
$this->assertNoLink('Alpaca');
$this->assertSession()->linkExists('Cron');
$this->assertSession()->linkNotExists('Alpaca');
}
}
@@ -87,10 +87,10 @@ class ShortcutLinksTest extends ShortcutTestBase {
$this->assertContains('internal:' . $test_path, $paths, 'Shortcut created: ' . $test_path);
if (in_array($test_path, $test_cases_non_access)) {
$this->assertNoLink($title, new FormattableMarkup('Shortcut link %url not accessible on the page.', ['%url' => $test_path]));
$this->assertSession()->linkNotExists($title, new FormattableMarkup('Shortcut link %url not accessible on the page.', ['%url' => $test_path]));
}
else {
$this->assertLink($title, 0, new FormattableMarkup('Shortcut link %url found on the page.', ['%url' => $test_path]));
$this->assertSession()->linkExists($title, 0, new FormattableMarkup('Shortcut link %url found on the page.', ['%url' => $test_path]));
}
}
$saved_set = ShortcutSet::load($set->id());
@@ -121,7 +121,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
'link[0][uri]' => '/node',
];
$this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save'));
$this->assertLink($title, 0, 'Shortcut link found on the page.');
$this->assertSession()->linkExists($title, 0, 'Shortcut link found on the page.');
// Create a new shortcut set and add a link to it.
$this->drupalLogin($this->adminUser);
@@ -154,19 +154,19 @@ class ShortcutLinksTest extends ShortcutTestBase {
// Test the "Add to shortcuts" link.
$this->clickLink('Add to Default shortcuts');
$this->assertText('Added a shortcut for Cron.');
$this->assertLink('Cron', 0, 'Shortcut link found on page');
$this->assertSession()->linkExists('Cron', 0, 'Shortcut link found on page');
$this->drupalGet('admin/structure');
$this->assertLink('Cron', 0, 'Shortcut link found on different page');
$this->assertSession()->linkExists('Cron', 0, 'Shortcut link found on different page');
// Test the "Remove from shortcuts" link.
$this->clickLink('Cron');
$this->clickLink('Remove from Default shortcuts');
$this->assertText('The shortcut Cron has been deleted.');
$this->assertNoLink('Cron', 'Shortcut link removed from page');
$this->assertSession()->linkNotExists('Cron', 'Shortcut link removed from page');
$this->drupalGet('admin/structure');
$this->assertNoLink('Cron', 'Shortcut link removed from different page');
$this->assertSession()->linkNotExists('Cron', 'Shortcut link removed from different page');
$this->drupalGet('admin/people');
@@ -240,7 +240,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
$saved_set = ShortcutSet::load($set->id());
$titles = $this->getShortcutInformation($saved_set, 'title');
$this->assertContains($new_link_name, $titles, 'Shortcut renamed: ' . $new_link_name);
$this->assertLink($new_link_name, 0, 'Renamed shortcut link appears on the page.');
$this->assertSession()->linkExists($new_link_name, 0, 'Renamed shortcut link appears on the page.');
$this->assertText(t('The shortcut @link has been updated.', ['@link' => $new_link_name]));
}
@@ -352,13 +352,16 @@ class ShortcutLinksTest extends ShortcutTestBase {
// Verify that users without the 'access shortcuts' permission can't see the
// shortcuts.
$this->drupalLogin($this->drupalCreateUser(['access toolbar']));
$this->assertNoLink('Shortcuts', 'Shortcut link not found on page.');
$this->assertSession()->linkNotExists('Shortcuts', 'Shortcut link not found on page.');
// Verify that users without the 'administer site configuration' permission
// can't see the cron shortcuts but can see shortcuts.
$this->drupalLogin($this->drupalCreateUser(['access toolbar', 'access shortcuts']));
$this->assertLink('Shortcuts');
$this->assertNoLink('Cron', 'Cron shortcut link not found on page.');
$this->drupalLogin($this->drupalCreateUser([
'access toolbar',
'access shortcuts',
]));
$this->assertSession()->linkExists('Shortcuts');
$this->assertSession()->linkNotExists('Cron', 'Cron shortcut link not found on page.');
// Verify that users with the 'access shortcuts' permission can see the
// shortcuts.
@@ -366,7 +369,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
'access toolbar', 'access shortcuts', 'administer site configuration',
]));
$this->clickLink('Shortcuts', 0, 'Shortcut link found on page.');
$this->assertLink('Cron', 0, 'Cron shortcut link found on page.');
$this->assertSession()->linkExists('Cron', 0, 'Cron shortcut link found on page.');
$this->verifyAccessShortcutsPermissionForEditPages();
}
@@ -376,7 +379,12 @@ class ShortcutLinksTest extends ShortcutTestBase {
*/
public function testShortcutLinkOrder() {
// Ensure to give permissions to access the shortcuts.
$this->drupalLogin($this->drupalCreateUser(['access toolbar', 'access shortcuts', 'access content overview', 'administer content types']));
$this->drupalLogin($this->drupalCreateUser([
'access toolbar',
'access shortcuts',
'access content overview',
'administer content types',
]));
$this->drupalGet(Url::fromRoute('<front>'));
$shortcuts = $this->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a');
$this->assertEqual($shortcuts[0]->getText(), 'Add content');
@@ -83,7 +83,7 @@ class ShortcutSetsTest extends ShortcutTestBase {
$title = $shortcut->getTitle();
// Confirm that a link to the shortcut is found within the table.
$this->assertLink($title);
$this->assertSession()->linkExists($title);
// Look for a test shortcut weight select form element.
$this->assertFieldByName('shortcuts[links][' . $shortcut->id() . '][weight]');
@@ -78,8 +78,23 @@ abstract class ShortcutTestBase extends BrowserTestBase {
}
// Create users.
$this->adminUser = $this->drupalCreateUser(['access toolbar', 'administer shortcuts', 'view the administration theme', 'create article content', 'create page content', 'access content overview', 'administer users', 'link to any page', 'edit any article content']);
$this->shortcutUser = $this->drupalCreateUser(['customize shortcut links', 'switch shortcut sets', 'access shortcuts', 'access content']);
$this->adminUser = $this->drupalCreateUser([
'access toolbar',
'administer shortcuts',
'view the administration theme',
'create article content',
'create page content',
'access content overview',
'administer users',
'link to any page',
'edit any article content',
]);
$this->shortcutUser = $this->drupalCreateUser([
'customize shortcut links',
'switch shortcut sets',
'access shortcuts',
'access content',
]);
// Create a node.
$this->node = $this->drupalCreateNode(['type' => 'article']);