Chris@0: $link_title) { Chris@0: $part_xpath = (!$i ? '//' : '/following-sibling::ul/descendant::'); Chris@0: $part_xpath .= 'li[contains(@class, :class)]/a[contains(@href, :href) and contains(text(), :title)]'; Chris@0: $part_args = [ Chris@0: ':class' => 'menu-item--active-trail', Chris@0: ':href' => Url::fromUri('base:' . $link_path)->toString(), Chris@0: ':title' => $link_title, Chris@0: ]; Chris@0: $xpath .= $this->buildXPathQuery($part_xpath, $part_args); Chris@0: $i++; Chris@0: } Chris@0: $elements = $this->xpath($xpath); Chris@0: $this->assertTrue(!empty($elements), 'Active trail to current page was found in menu tree.'); Chris@0: Chris@0: // Append prefix for active link asserted below. Chris@0: $xpath .= '/following-sibling::ul/descendant::'; Chris@0: } Chris@0: else { Chris@0: $xpath .= '//'; Chris@0: } Chris@0: $xpath_last_active = ($last_active ? 'and contains(@class, :class-active)' : ''); Chris@0: $xpath .= 'li[contains(@class, :class-trail)]/a[contains(@href, :href) ' . $xpath_last_active . 'and contains(text(), :title)]'; Chris@0: $args = [ Chris@0: ':class-trail' => 'menu-item--active-trail', Chris@0: ':class-active' => 'is-active', Chris@0: ':href' => Url::fromUri('base:' . $active_link_path)->toString(), Chris@0: ':title' => $active_link_title, Chris@0: ]; Chris@0: $elements = $this->xpath($xpath, $args); Chris@0: $this->assertTrue(!empty($elements), format_string('Active link %title was found in menu tree, including active trail links %tree.', [ Chris@0: '%title' => $active_link_title, Chris@0: '%tree' => implode(' ยป ', $tree), Chris@0: ])); Chris@0: } Chris@0: Chris@0: }