Skip to content
Snippets Groups Projects
Verified Commit 3eedc962 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3276652 by andregp, eojthebrave, markie, catch, danflanagan8:...

Issue #3276652 by andregp, eojthebrave, markie, catch, danflanagan8: AssertMenuActiveTrailTrait should not rely on classy/bartik
parent bf7ce2f8
No related branches found
No related tags found
37 merge requests!12227Issue #3181946 by jonmcl, mglaman,!7471uncessary 5 files are moved from media-library folder to misc folder,!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!3630Issue #2815301 by Chi, DanielVeza, kostyashupenko, smustgrave: Allow to create...,!3291Issue #3336463: Rewrite rules for gzipped CSS and JavaScript aggregates never match,!3143Issue #3313342: [PHP 8.1] Deprecated function: strpos(): Passing null to parameter #1 LayoutBuilderUiCacheContext.php on line 28,!3102Issue #3164428 by DonAtt, longwave, sahil.goyal, Anchal_gupta, alexpott: Use...,!2853#3274419 Makes BaseFieldOverride inherit the internal property from the base field.,!2719Issue #3110137: Remove Classy from core.,!2437Issue #3238257 by hooroomoo, Wim Leers: Fragment link pointing to <textarea>...,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2074Issue #2707689: NodeForm::actions() checks for delete access on new entities,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1254Issue #3238915: Refactor (if feasible) uses of the jQuery ready function to use VanillaJS,!1162Issue #3100350: Unable to save '/' root path alias,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!957Added throwing of InvalidPluginDefinitionException from getDefinition().,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!873Issue #2875228: Site install not using batch API service,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!712Issue #2909128: Autocomplete intermittent on Chrome Android,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -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 @@ protected function assertBreadcrumb($goto, array $trail, $page_title = NULL, arr
// 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 @@ protected function assertMenuActiveTrail($tree, $last_active) {
$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 @@ protected function assertMenuActiveTrail($tree, $last_active) {
$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 @@ public function testBreadCrumbs() {
$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());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment