Chris@0: drupalGet($goto); Chris@0: } Chris@0: $this->assertBreadcrumbParts($trail); Chris@0: Chris@0: // Additionally assert page title, if given. Chris@0: if (isset($page_title)) { Chris@0: $this->assertTitle(strtr('@title | Drupal', ['@title' => $page_title])); Chris@0: } Chris@0: Chris@0: // Additionally assert active trail in a menu tree output, if given. Chris@0: if ($tree) { Chris@0: $this->assertMenuActiveTrail($tree, $last_active); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Assert that a trail exists in the internal browser. Chris@0: * Chris@0: * @param array $trail Chris@0: * An associative array whose keys are expected breadcrumb link paths and Chris@0: * whose values are expected breadcrumb link texts (not sanitized). Chris@0: */ Chris@0: protected function assertBreadcrumbParts($trail) { Chris@0: // Compare paths with actual breadcrumb. Chris@0: $parts = $this->getBreadcrumbParts(); Chris@0: $pass = TRUE; Chris@0: // There may be more than one breadcrumb on the page. If $trail is empty Chris@0: // this test would go into an infinite loop, so we need to check that too. Chris@0: while ($trail && !empty($parts)) { Chris@0: foreach ($trail as $path => $title) { Chris@0: // If the path is empty, generate the path from the route. If Chris@0: // the path does not start with a leading slash, then run it through Chris@0: // Url::fromUri('base:')->toString() to get the correct base Chris@0: // prepended. Chris@0: if ($path == '') { Chris@0: $url = Url::fromRoute('')->toString(); Chris@0: } Chris@0: elseif ($path[0] != '/') { Chris@0: $url = Url::fromUri('base:' . $path)->toString(); Chris@0: } Chris@0: else { Chris@0: $url = $path; Chris@0: } Chris@0: $part = array_shift($parts); Chris@0: $pass = ($pass && $part['href'] === $url && $part['text'] === Html::escape($title)); Chris@0: } Chris@0: } Chris@0: // No parts must be left, or an expected "Home" will always pass. Chris@0: $pass = ($pass && empty($parts)); Chris@0: Chris@0: $this->assertTrue($pass, format_string('Breadcrumb %parts found on @path.', [ Chris@0: '%parts' => implode(' ยป ', $trail), Chris@0: '@path' => $this->getUrl(), Chris@0: ])); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the breadcrumb contents of the current page in the internal browser. Chris@0: */ Chris@0: protected function getBreadcrumbParts() { Chris@0: $parts = []; Chris@0: $elements = $this->xpath('//nav[@class="breadcrumb"]/ol/li/a'); Chris@0: if (!empty($elements)) { Chris@0: foreach ($elements as $element) { Chris@0: $parts[] = [ Chris@0: 'text' => (string) $element, Chris@0: 'href' => (string) $element['href'], Chris@0: 'title' => (string) $element['title'], Chris@0: ]; Chris@0: } Chris@0: } Chris@0: return $parts; Chris@0: } Chris@0: Chris@0: }