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