diff --git a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php index a145114..2720275 100644 --- a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php +++ b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php @@ -76,14 +76,14 @@ public function applies(RouteMatchInterface $route_match) { * {@inheritdoc} */ public function build(RouteMatchInterface $route_match) { + $build = new Breadcrumb(); // Without builders return early. $sorted_builders = $this->getSortedBuilders(); if (empty($sorted_builders)) { - return array(); + return $build; } - $build = new Breadcrumb(); $context = array('builder' => NULL); // Call the build method of registered breadcrumb builders, // until one of them returns an array. diff --git a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php index f2f55ca..1e21ad9 100644 --- a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Breadcrumb\Breadcrumb; use Drupal\Core\Breadcrumb\BreadcrumbManager; use Drupal\Tests\UnitTestCase; +use PHPUnit_Framework_Assert as Assert; /** * @coversDefaultClass \Drupal\Core\Breadcrumb\BreadcrumbManager @@ -74,7 +75,14 @@ public function testBuildWithSingleBuilder() { $route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface'); $this->moduleHandler->expects($this->once()) ->method('alter') - ->with('system_breadcrumb', $links, $route_match, array('builder' => $builder)); + ->willReturnCallback(function($type, $data, $context1, $context2) use ($route_match, $links, $builder) { + Assert::assertEquals($type, 'system_breadcrumb', 'SingleTest: Module handler expected alter call to system_breadcrumb'); + $extracted_links = $data->getLinks(); + Assert::assertEquals($extracted_links, $links, 'SingleTest: Module handler was passed the correct link'); + Assert::assertEquals($context1, $route_match, 'SingleTest: Module handler was passed route_match.'); + Assert::assertEquals($context2, array('builder' => $builder), 'SingleTest: Module handler received the builder context'); + } + ); $this->breadcrumbManager->addBuilder($builder, 0); @@ -106,7 +114,14 @@ public function testBuildWithMultipleApplyingBuilders() { $this->moduleHandler->expects($this->once()) ->method('alter') - ->with('system_breadcrumb', $links2, $route_match, array('builder' => $builder2)); + ->willReturnCallback(function($type, $data, $context1, $context2) use ($links2, $route_match, $builder2) { + Assert::assertEquals($type, 'system_breadcrumb', 'MultipleApplying: Module handler expected alter call to system_breadcrumb'); + $extracted_links = $data->getLinks(); + Assert::assertEquals($extracted_links, $links2, 'MultipleApplying: Module handler was passed the correct link'); + Assert::assertEquals($context1, $route_match, 'MultipleApplying: Module handler was passed route_match.'); + Assert::assertEquals($context2, array('builder' => $builder2), 'MultipleApplying: Module handler received the builder context'); + } + ); $this->breadcrumbManager->addBuilder($builder1, 0); $this->breadcrumbManager->addBuilder($builder2, 10); @@ -140,7 +155,14 @@ public function testBuildWithOneNotApplyingBuilders() { $this->moduleHandler->expects($this->once()) ->method('alter') - ->with('system_breadcrumb', $links2, $route_match, array('builder' => $builder2)); + ->willReturnCallback(function($type, $data, $context1, $context2) use ($links2, $route_match, $builder2) { + Assert::assertEquals($type, 'system_breadcrumb', 'NotApplying: Module handler expected alter call to system_breadcrumb'); + $extracted_links = $data->getLinks(); + Assert::assertEquals($extracted_links, $links2, 'NotApplying: Module handler was passed the correct link'); + Assert::assertEquals($context1, $route_match, 'NotApplying: Module handler was passed route_match.'); + Assert::assertEquals($context2, array('builder' => $builder2), 'NotApplying: Module handler received the builder context'); + } + ); $this->breadcrumbManager->addBuilder($builder1, 10); $this->breadcrumbManager->addBuilder($builder2, 0);