function ShortcutLinksTest::testShortcutQuickLink
Same name in other branches
- 9 core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testShortcutQuickLink()
- 10 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 145
Class
- ShortcutLinksTest
- Create, view, edit, delete, and change shortcut links.
Namespace
Drupal\Tests\shortcut\FunctionalCode
public function testShortcutQuickLink() {
\Drupal::service('theme_installer')->install([
'seven',
]);
$this->config('system.theme')
->set('admin', 'seven')
->save();
$this->config('node.settings')
->set('use_admin_theme', '1')
->save();
$this->container
->get('router.builder')
->rebuild();
$this->drupalLogin($this->rootUser);
$this->drupalGet('admin/config/system/cron');
// Test the "Add to shortcuts" link.
$this->clickLink('Add to Default shortcuts');
$this->assertText('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->assertText('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->assertText('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->assertText('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->assertText('Added a shortcut for Create Basic page.');
// Assure that Article does not have its shortcut indicated as set.
$this->drupalGet('node/add/article');
$link = $this->xpath('//a[normalize-space()=:label]', [
':label' => 'Remove from Default shortcuts',
]);
$this->assertTrue(empty($link), 'Link Remove to Default shortcuts not found for Create Article page.');
// Add Shortcut for Article.
$this->clickLink('Add to Default shortcuts');
$this->assertText('Added a shortcut for Create Article.');
$this->config('system.theme')
->set('default', 'seven')
->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->assertText(new FormattableMarkup('Added a shortcut for @title.', [
'@title' => $title,
]));
$this->assertShortcutQuickLink('Remove from Default shortcuts');
// Test the "Remove from shortcuts" link for node view route.
$this->clickLink('Remove from Default shortcuts');
$this->assertText(new FormattableMarkup('The shortcut @title has been deleted.', [
'@title' => $title,
]));
$this->assertShortcutQuickLink('Add to Default shortcuts');
\Drupal::service('module_installer')->install([
'block_content',
]);
BlockContentType::create([
'id' => 'basic',
'label' => 'Basic block',
'revision' => FALSE,
])->save();
// Test page with HTML tags in title.
$this->drupalGet('admin/structure/block/block-content/manage/basic');
$page_title = new FormattableMarkup('Edit %label custom block type', [
'%label' => 'Basic block',
]);
$this->assertRaw($page_title);
// Add shortcut to this page.
$this->clickLink('Add to Default shortcuts');
$this->assertRaw(new FormattableMarkup('Added a shortcut for %title.', [
'%title' => trim(strip_tags($page_title)),
]));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.