Commit d9636476 authored by alexpott's avatar alexpott

Issue #2672668 by jibran, malavya, msankhala, archunan, Wim Leers, willzyx,...

Issue #2672668 by jibran, malavya, msankhala, archunan, Wim Leers, willzyx, lokapujya: Page title with HTML tags shows HTML tags in shortcut label in the shortcut toolbar tray
parent 0a548d18
......@@ -311,7 +311,8 @@ function shortcut_preprocess_page_title(&$variables) {
// Replicate template_preprocess_html()'s processing to get the title in
// string form, so we can set the default name for the shortcut.
$name = render($variables['title']);
// Strip HTML tags from the title.
$name = trim(strip_tags(render($variables['title'])));
$query = array(
'link' => $link,
'name' => $name,
......
......@@ -2,7 +2,9 @@
namespace Drupal\shortcut\Tests;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Url;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\shortcut\Entity\ShortcutSet;
......@@ -161,18 +163,12 @@ public function testShortcutQuickLink() {
// 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');
// Test two pages which use same route name but different route parameters.
$this->drupalGet('node/add/page');
......@@ -186,6 +182,37 @@ public function testShortcutQuickLink() {
// 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(array(
'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)),
]));
}
/**
......@@ -404,4 +431,32 @@ public function testShortcutBlockAccess() {
$this->assertNoBlockAppears($block);
}
/**
* 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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment