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
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -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);
    }
  }

+11 −12
Original line number Diff line number Diff line
@@ -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,
    ];
+1 −1
Original line number Diff line number Diff line
@@ -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());