diff --git a/core/modules/system/tests/Drupal/system/Tests/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php b/core/modules/system/tests/Drupal/system/Tests/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php index 0abdf13..620d0c4 100644 --- a/core/modules/system/tests/Drupal/system/Tests/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php +++ b/core/modules/system/tests/Drupal/system/Tests/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php @@ -7,7 +7,6 @@ namespace Drupal\system\Tests\Breadcrumbs; -use Drupal\Core\ParamConverter\ParamNotConvertedException; use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Utility\LinkGeneratorInterface; @@ -16,15 +15,13 @@ use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Exception\MethodNotAllowedException; -use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Route; /** - * Tests machine name controller's transliteration functionality. + * Tests the path based breadcrumb builder. * - * @group System * @group Drupal + * @group System * * @coversDefaultClass \Drupal\system\PathBasedBreadcrumbBuilder */ @@ -38,7 +35,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase { protected $builder; /** - * The title resolver. + * The mocked title resolver. * * @var \Drupal\Core\Controller\TitleResolverInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -73,7 +70,7 @@ class PathBasedBreadcrumbBuilderTest extends UnitTestCase { protected $linkGenerator; /** - * The current user. + * The mocked current user. * * @var \Drupal\Core\Session\AccountInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -267,8 +264,10 @@ public function testBuildWithThreePathElements() { * * @covers ::build() * @covers ::getRequestForPath() + * + * @dataProvider providerTestBuildWithException */ - public function testBuildWithPathMatchingExceptions() { + public function testBuildWithException($exception_class, $exception_argument) { $this->request->expects($this->once()) ->method('getPathInfo') ->will($this->returnValue('/example/bar')); @@ -276,7 +275,7 @@ public function testBuildWithPathMatchingExceptions() { $this->requestMatcher->expects($this->any()) ->method('matchRequest') - ->will($this->throwException(new MethodNotAllowedException(array()))); + ->will($this->throwException(new $exception_class($exception_argument))); $this->setupLinkGeneratorWithFrontpage(); $links = $this->builder->build(array()); @@ -286,26 +285,16 @@ public function testBuildWithPathMatchingExceptions() { } /** - * Tests that ParamNotConvertedException are caught. + * Provides exception types for testBuildWithException. * - * @covers ::build() - * @covers ::getRequestForPath() + * @return array */ - public function testBuildWithParamNotConvertedException() { - $this->request->expects($this->once()) - ->method('getPathInfo') - ->will($this->returnValue('/example/bar')); - $this->setupStubPathProcessor(); - - $this->requestMatcher->expects($this->any()) - ->method('matchRequest') - ->will($this->throwException(new ParamNotConvertedException())); - $this->setupLinkGeneratorWithFrontpage(); - - $links = $this->builder->build(array()); - - // No path matched, though at least the frontpage is displayed. - $this->assertEquals(array(0 => 'Home'), $links); + public function providerTestBuildWithException() { + return array( + array('Drupal\Core\ParamConverter\ParamNotConvertedException', ''), + array('Symfony\Component\Routing\Exception\MethodNotAllowedException', array()), + array('Symfony\Component\Routing\Exception\ResourceNotFoundException', ''), + ); } /** @@ -334,30 +323,6 @@ public function testBuildWithNonProcessedPath() { $this->assertEquals(array(0 => 'Home'), $links); } - - /** - * Tests that ResourceNotFoundException are caught. - * - * @covers ::build() - * @covers ::getRequestForPath() - */ - public function testBuildWithRosourceNotFoundException() { - $this->request->expects($this->once()) - ->method('getPathInfo') - ->will($this->returnValue('/example/bar')); - $this->setupStubPathProcessor(); - - $this->requestMatcher->expects($this->any()) - ->method('matchRequest') - ->will($this->throwException(new ResourceNotFoundException())); - $this->setupLinkGeneratorWithFrontpage(); - - $links = $this->builder->build(array()); - - // No path matched, though at least the frontpage is displayed. - $this->assertEquals(array(0 => 'Home'), $links); - } - /** * Tests the applied method. * @@ -368,7 +333,7 @@ public function testApplies() { } /** - * Tests the breadcrumb for an user path. + * Tests the breadcrumb for a user path. * * @covers ::build() * @covers ::getRequestForPath()