You are here

public function ShortcutLinksTest::testShortcutQuickLink in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::testShortcutQuickLink()
  2. 9 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 150

Class

ShortcutLinksTest
Create, view, edit, delete, and change shortcut links.

Namespace

Drupal\Tests\shortcut\Functional

Code

public function testShortcutQuickLink() {
  \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->rootUser);
  $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',
  ]);
  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 = "Edit Basic block custom 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}.");
}