Issue #3276652 by andregp, eojthebrave, markie, catch, danflanagan8: AssertMenuActiveTrailTrait should not rely on classy/bartik
(cherry picked from commit 3eedc9628e
)
merge-requests/2281/head
parent
3f231c5d78
commit
537c279861
|
@ -32,8 +32,13 @@ trait AssertBreadcrumbTrait {
|
|||
* @param $last_active
|
||||
* (optional) Whether the last link in $tree is expected to be active (TRUE)
|
||||
* or just to be in the active trail (FALSE).
|
||||
* @param string $active_trail_class
|
||||
* (optional) The class of the active trail. Defaults to
|
||||
* 'menu-item--active-trail'.
|
||||
* @param string $active_class
|
||||
* (optional) The class of the active element. Defaults to 'is-active'.
|
||||
*/
|
||||
protected function assertBreadcrumb($goto, array $trail, $page_title = NULL, array $tree = [], $last_active = TRUE) {
|
||||
protected function assertBreadcrumb($goto, array $trail, $page_title = NULL, array $tree = [], $last_active = TRUE, $active_trail_class = 'menu-item--active-trail', $active_class = 'is-active') {
|
||||
if (isset($goto)) {
|
||||
$this->drupalGet($goto);
|
||||
}
|
||||
|
@ -46,7 +51,7 @@ trait AssertBreadcrumbTrait {
|
|||
|
||||
// Additionally assert active trail in a menu tree output, if given.
|
||||
if ($tree) {
|
||||
$this->assertMenuActiveTrail($tree, $last_active);
|
||||
$this->assertMenuActiveTrail($tree, $last_active, $active_trail_class, $active_class);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,13 @@ trait AssertMenuActiveTrailTrait {
|
|||
* @param bool $last_active
|
||||
* Whether the last link in $tree is expected to be active (TRUE)
|
||||
* or just to be in the active trail (FALSE).
|
||||
* @param string $active_trail_class
|
||||
* (optional) The class of the active trail. Defaults to
|
||||
* 'menu-item--active-trail'.
|
||||
* @param string $active_class
|
||||
* (optional) The class of the active element. Defaults to 'is-active'.
|
||||
*/
|
||||
protected function assertMenuActiveTrail($tree, $last_active) {
|
||||
protected function assertMenuActiveTrail($tree, $last_active, $active_trail_class = 'menu-item--active-trail', $active_class = 'is-active') {
|
||||
end($tree);
|
||||
$active_link_path = key($tree);
|
||||
$active_link_title = array_pop($tree);
|
||||
|
@ -29,14 +34,9 @@ trait AssertMenuActiveTrailTrait {
|
|||
$i = 0;
|
||||
foreach ($tree as $link_path => $link_title) {
|
||||
$part_xpath = (!$i ? '//' : '/following-sibling::ul/descendant::');
|
||||
$part_xpath .= 'li[contains(@class, :classy-class-trail) or contains(@class, :olivero-class-trail)]/a[contains(@href, :href) and contains(text(), :title)]';
|
||||
// These active trail classes are added by classy/olivero. This should
|
||||
// be refactored to work with stark and not depend on any specific
|
||||
// theme.
|
||||
// https://www.drupal.org/project/drupal/issues/3276652
|
||||
$part_xpath .= 'li[contains(@class, :class-trail)]/a[contains(@href, :href) and contains(text(), :title)]';
|
||||
$part_args = [
|
||||
':classy-class-trail' => 'menu-item--active-trail',
|
||||
':olivero-class-trail' => 'menu__item--active-trail',
|
||||
':class-trail' => $active_trail_class,
|
||||
':href' => Url::fromUri('base:' . $link_path)->toString(),
|
||||
':title' => $link_title,
|
||||
];
|
||||
|
@ -53,11 +53,10 @@ trait AssertMenuActiveTrailTrait {
|
|||
$xpath .= '//';
|
||||
}
|
||||
$xpath_last_active = ($last_active ? 'and contains(@class, :class-active)' : '');
|
||||
$xpath .= 'li[contains(@class, :classy-class-trail) or contains(@class, :olivero-class-trail)]/a[contains(@href, :href) ' . $xpath_last_active . 'and contains(text(), :title)]';
|
||||
$xpath .= 'li[contains(@class, :class-trail)]/a[contains(@href, :href) ' . $xpath_last_active . 'and contains(text(), :title)]';
|
||||
$args = [
|
||||
':classy-class-trail' => 'menu-item--active-trail',
|
||||
':olivero-class-trail' => 'menu__item--active-trail',
|
||||
':class-active' => 'is-active',
|
||||
':class-trail' => $active_trail_class,
|
||||
':class-active' => $active_class,
|
||||
':href' => Url::fromUri('base:' . $active_link_path)->toString(),
|
||||
':title' => $active_link_title,
|
||||
];
|
||||
|
|
|
@ -294,7 +294,7 @@ class BreadcrumbTest extends BrowserTestBase {
|
|||
$tree += [
|
||||
$link_path => $link->getTitle(),
|
||||
];
|
||||
$this->assertBreadcrumb($link_path, $trail, $term->getName(), $tree);
|
||||
$this->assertBreadcrumb($link_path, $trail, $term->getName(), $tree, TRUE, 'menu__item--active-trail');
|
||||
// Ensure that the tagged node is found.
|
||||
$this->assertSession()->assertEscaped($parent->getTitle());
|
||||
|
||||
|
|
Loading…
Reference in New Issue