diff -u b/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module --- b/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -309,9 +309,14 @@ $link = Url::fromRouteMatch(\Drupal::routeMatch())->getInternalPath(); $route_match = \Drupal::routeMatch(); + // Use the route's title instead of $variables['title'] since + // $variables['title'] may have been changed and may contains extraneous + // markup. + $title = \Drupal::service('title_resolver')->getTitle(\Drupal::request(), $route_match->getRouteObject()); + $query = array( 'link' => $link, - 'name' => trim(strip_tags($variables['title'])), + 'name' => SafeMarkup::checkPlain($title), ); $query += \Drupal::destination()->getAsArray(); diff -u b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php --- b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php @@ -141,18 +141,13 @@ // 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.'); - // Due to the structure of the markup in the link ::assertLink() doesn't - // works here. - $link = $this->xpath('//a[normalize-space()=:label]', array(':label' => 'Remove from Default shortcuts')); - $this->assertTrue(!empty($link), 'Link Remove from Default shortcuts found.'); + $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.'); - // Due to the structure of the markup in the link ::assertLink() doesn't - // works here. - $link = $this->xpath('//a[normalize-space()=:label]', array(':label' => 'Add to Default shortcuts')); - $this->assertTrue(!empty($link), 'Link Add to Default shortcuts found.'); + $this->assertShortcutQuickLink('Add to Default shortcuts'); + $this->config('system.theme')->set('default', 'seven')->save(); $this->drupalGet('node/' . $this->node->id()); @@ -162,18 +157,12 @@ // Test the "Add to shortcuts" link for node view route. $this->clickLink('Add to Default shortcuts'); $this->assertText(format_string('Added a shortcut for @title.', array('@title' => $title))); - // Due to the structure of the markup in the link ::assertLink() doesn't - // works here. - $link = $this->xpath('//a[normalize-space()=:label]', array(':label' => 'Remove from Default shortcuts')); - $this->assertTrue(!empty($link), 'Link Remove from Default shortcuts found.'); + $this->assertShortcutQuickLink('Remove from Default shortcuts'); // Test the "Remove from shortcuts" link for node view route. $this->clickLink('Remove from Default shortcuts'); $this->assertText(format_string('The shortcut @title has been deleted.', array('@title' => $title))); - // Due to the structure of the markup in the link ::assertLink() doesn't - // works here. - $link = $this->xpath('//a[normalize-space()=:label]', array(':label' => 'Add to Default shortcuts')); - $this->assertTrue(!empty($link), 'Link Add to Default shortcuts found.'); + $this->assertShortcutQuickLink('Add to Default shortcuts'); } /** @@ -394,2 +383,30 @@ + /** + * Passes if a shortcut quick link with the specified label is found. + * + * An optional link index may be passed. + * + * @param string $label + * Text between the anchor tags. + * @param int $index + * Link position counting from zero. + * @param string $message + * (optional) A message to display with the assertion. Do not translate + * messages: use format_string() to embed variables in the message text, not + * t(). If left blank, a default message will be displayed. + * @param string $group + * (optional) The group this message is in, which is displayed in a column + * in test output. Use 'Debug' to indicate this is debugging output. Do not + * translate this string. Defaults to 'Other'; most tests do not override + * this default. + * + * @return bool + * TRUE if the assertion succeeded, FALSE otherwise. + */ + protected function assertShortcutQuickLink($label, $index = 0, $message = '', $group = 'Other') { + $links = $this->xpath('//a[normalize-space()=:label]', array(':label' => $label)); + $message = ($message ? $message : SafeMarkup::format('Shortcut quick link with label %label found.', array('%label' => $label))); + return $this->assert(isset($links[$index]), $message, $group); + } + }