diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuTestBase.php index eb7fbaf..cc8ca91 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuTestBase.php @@ -34,13 +34,30 @@ protected function assertBreadcrumb($goto, array $trail, $page_title = NULL, arr if (isset($goto)) { $this->drupalGet($goto); } + $this->assertBreadcrumbParts($trail); + + // Additionally assert page title, if given. + if (isset($page_title)) { + $this->assertTitle(strtr('@title | Drupal', array('@title' => $page_title))); + } + + // Additionally assert active trail in a menu tree output, if given. + if ($tree) { + $this->assertMenuActiveTrail($tree, $last_active); + } + } + + protected function assertBreadcrumbParts($trail) { // Compare paths with actual breadcrumb. - $parts = $this->getParts(); + $parts = $this->getBreadcrumbParts(); $pass = TRUE; - foreach ($trail as $path => $title) { - $url = url($path); - $part = array_shift($parts); - $pass = ($pass && $part['href'] === $url && $part['text'] === check_plain($title)); + // There may be more than one breadcrumb on the page. + while (!empty($parts)) { + foreach ($trail as $path => $title) { + $url = url($path); + $part = array_shift($parts); + $pass = ($pass && $part['href'] === $url && $part['text'] === check_plain($title)); + } } // No parts must be left, or an expected "Home" will always pass. $pass = ($pass && empty($parts)); @@ -49,14 +66,11 @@ protected function assertBreadcrumb($goto, array $trail, $page_title = NULL, arr '%parts' => implode(' ยป ', $trail), '@path' => $this->getUrl(), ))); + } - // Additionally assert page title, if given. - if (isset($page_title)) { - $this->assertTitle(strtr('@title | Drupal', array('@title' => $page_title))); - } - - // Additionally assert active trail in a menu tree output, if given. - if ($tree) { + protected function assertMenuActiveTrail($tree, $last_active) { + // Indentation to reduce git diff. + if (TRUE) { end($tree); $active_link_path = key($tree); $active_link_title = array_pop($tree); @@ -102,7 +116,7 @@ protected function assertBreadcrumb($goto, array $trail, $page_title = NULL, arr /** * Returns the breadcrumb contents of the current page in the internal browser. */ - protected function getParts() { + protected function getBreadcrumbParts() { $parts = array(); $elements = $this->xpath('//nav[@class="breadcrumb"]/ol/li/a'); if (!empty($elements)) {