function ShortcutLinksTest::testShortcutQuickLink
Same name in other branches
- 9 core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testShortcutQuickLink()
- 8.9.x core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testShortcutQuickLink()
- 11.x core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testShortcutQuickLink()
Tests that the "add to shortcut" and "remove from shortcut" links work.
File
-
core/
modules/ shortcut/ tests/ src/ Functional/ ShortcutLinksTest.php, line 172
Class
- ShortcutLinksTest
- Create, view, edit, delete, and change shortcut links.
Namespace
Drupal\Tests\shortcut\FunctionalCode
public function testShortcutQuickLink() : void {
\Drupal::service('theme_installer')->install([
'claro',
]);
$this->config('system.theme')
->set('admin', 'claro')
->save();
$this->config('node.settings')
->set('use_admin_theme', '1')
->save();
$this->container
->get('router.builder')
->rebuild();
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/config/system/cron');
// Test the "Add to shortcuts" link.
$this->clickLink('Add to Default shortcuts');
$this->assertSession()
->pageTextContains('Added a shortcut for Cron.');
$this->assertSession()
->linkExists('Cron', 0, 'Shortcut link found on page');
$this->drupalGet('admin/structure');
$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->assertSession()
->pageTextContains('The shortcut Cron has been deleted.');
$this->assertSession()
->linkNotExists('Cron', 'Shortcut link removed from page');
$this->drupalGet('admin/structure');
$this->assertSession()
->linkNotExists('Cron', 'Shortcut link removed from different page');
$this->drupalGet('admin/people');
// Test the "Add to shortcuts" link for a page generated by views.
$this->clickLink('Add to Default shortcuts');
$this->assertSession()
->pageTextContains('Added a shortcut for People.');
$this->assertShortcutQuickLink('Remove from Default shortcuts');
// Test the "Remove from shortcuts" link for a page generated by views.
$this->clickLink('Remove from Default shortcuts');
$this->assertSession()
->pageTextContains('The shortcut People has been deleted.');
$this->assertShortcutQuickLink('Add to Default shortcuts');
// Test two pages which use same route name but different route parameters.
$this->drupalGet('node/add/page');
// Add Shortcut for Basic Page.
$this->clickLink('Add to Default shortcuts');
$this->assertSession()
->pageTextContains('Added a shortcut for Create Basic page.');
// Assure that Article does not have its shortcut indicated as set.
$this->drupalGet('node/add/article');
$this->assertSession()
->elementNotExists('xpath', "//a[normalize-space()='Remove from Default shortcuts']");
// Add Shortcut for Article.
$this->clickLink('Add to Default shortcuts');
$this->assertSession()
->pageTextContains('Added a shortcut for Create Article.');
$this->config('system.theme')
->set('default', 'claro')
->save();
$this->drupalGet('node/' . $this->node
->id());
$title = $this->node
->getTitle();
// Test the "Add to shortcuts" link for node view route.
$this->clickLink('Add to Default shortcuts');
$this->assertSession()
->pageTextContains("Added a shortcut for {$title}.");
$this->assertShortcutQuickLink('Remove from Default shortcuts');
// Test the "Remove from shortcuts" link for node view route.
$this->clickLink('Remove from Default shortcuts');
$this->assertSession()
->pageTextContains("The shortcut {$title} has been deleted.");
$this->assertShortcutQuickLink('Add to Default shortcuts');
\Drupal::service('module_installer')->install([
'block_content',
]);
$this->adminUser
->addRole($this->drupalCreateRole([
'administer block types',
]))
->save();
BlockContentType::create([
'id' => 'basic',
'label' => 'Basic block',
'revision' => FALSE,
])->save();
// Test page with HTML tags in title.
$this->drupalGet('admin/structure/block-content/manage/basic');
$page_title = "Edit Basic block block type";
$this->assertSession()
->pageTextContains($page_title);
// Add shortcut to this page.
$this->clickLink('Add to Default shortcuts');
$this->assertSession()
->pageTextContains("Added a shortcut for {$page_title}.");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.