Loading core/modules/forum/tests/src/Unit/Breadcrumb/ForumListingBreadcrumbBuilderTest.php +20 −33 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Link; use Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder; use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\TermStorageInterface; use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\Container; Loading Loading @@ -46,12 +47,21 @@ protected function setUp(): void { * @dataProvider providerTestApplies * @covers ::applies */ public function testApplies($expected, $route_name = NULL, $parameter_map = []) { public function testApplies(bool $expected, ?string $route_name = NULL, array $parameter_map = []): void { // Make some test doubles. $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); $config_factory = $this->getConfigFactoryStub([]); $forum_manager = $this->createMock('Drupal\forum\ForumManagerInterface'); $translation_manager = $this->createMock('Drupal\Core\StringTranslation\TranslationInterface'); $map = []; if ($parameter_map) { foreach ($parameter_map as $parameter) { $map[] = [ $parameter[0], $parameter[1] === TRUE ? $this->getMockBuilder(Term::class)->disableOriginalConstructor()->getMock() : $parameter[1], ]; } } // Make an object to test. $builder = new ForumListingBreadcrumbBuilder($entity_type_manager, $config_factory, $forum_manager, $translation_manager); Loading @@ -62,7 +72,7 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = []) ->willReturn($route_name); $route_match->expects($this->any()) ->method('getParameter') ->willReturnMap($parameter_map); ->willReturnMap($map); $this->assertEquals($expected, $builder->applies($route_match)); } Loading @@ -70,40 +80,17 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = []) /** * Provides test data for testApplies(). * * @return array * Array of datasets for testApplies(). Structured as such: * @return \Generator * Datasets for testApplies(). Structured as such: * - ForumListBreadcrumbBuilder::applies() expected result. * - ForumListBreadcrumbBuilder::applies() $attributes input array. */ public function providerTestApplies() { // Send a Node mock, because NodeInterface cannot be mocked. $mock_term = $this->getMockBuilder('Drupal\taxonomy\Entity\Term') ->disableOriginalConstructor() ->getMock(); return [ [ FALSE, ], [ FALSE, 'NOT.forum.page', ], [ FALSE, 'forum.page', ], [ TRUE, 'forum.page', [['taxonomy_term', 'anything']], ], [ TRUE, 'forum.page', [['taxonomy_term', $mock_term]], ], ]; public static function providerTestApplies(): \Generator { yield [FALSE]; yield [FALSE, 'NOT.forum.page']; yield [FALSE, 'forum.page']; yield [TRUE, 'forum.page', [['taxonomy_term', 'anything']]]; yield [TRUE, 'forum.page', [['taxonomy_term', TRUE]]]; } /** Loading core/modules/forum/tests/src/Unit/Breadcrumb/ForumNodeBreadcrumbBuilderTest.php +20 −33 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Link; use Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder; use Drupal\node\Entity\Node; use Drupal\taxonomy\TermStorageInterface; use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\Container; Loading Loading @@ -46,10 +47,19 @@ protected function setUp(): void { * @dataProvider providerTestApplies * @covers ::applies */ public function testApplies($expected, $route_name = NULL, $parameter_map = []) { public function testApplies(bool $expected, ?string $route_name = NULL, array $parameter_map = []): void { // Make some test doubles. $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); $config_factory = $this->getConfigFactoryStub([]); $map = []; if ($parameter_map) { foreach ($parameter_map as $parameter) { $map[] = [ $parameter[0], $parameter[1] === TRUE ? $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock() : $parameter[1], ]; } } $forum_manager = $this->createMock('Drupal\forum\ForumManagerInterface'); $forum_manager->expects($this->any()) Loading @@ -67,7 +77,7 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = []) ->willReturn($route_name); $route_match->expects($this->any()) ->method('getParameter') ->willReturnMap($parameter_map); ->willReturnMap($map); $this->assertEquals($expected, $builder->applies($route_match)); } Loading @@ -77,40 +87,17 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = []) * * Note that this test is incomplete, because we can't mock NodeInterface. * * @return array * Array of datasets for testApplies(). Structured as such: * @return \Generator * Datasets for testApplies(). Structured as such: * - ForumNodeBreadcrumbBuilder::applies() expected result. * - ForumNodeBreadcrumbBuilder::applies() $attributes input array. */ public function providerTestApplies() { // Send a Node mock, because NodeInterface cannot be mocked. $mock_node = $this->getMockBuilder('Drupal\node\Entity\Node') ->disableOriginalConstructor() ->getMock(); return [ [ FALSE, ], [ FALSE, 'NOT.entity.node.canonical', ], [ FALSE, 'entity.node.canonical', ], [ FALSE, 'entity.node.canonical', [['node', NULL]], ], [ TRUE, 'entity.node.canonical', [['node', $mock_node]], ], ]; public static function providerTestApplies(): \Generator { yield [FALSE]; yield [FALSE, 'NOT.entity.node.canonical']; yield [FALSE, 'entity.node.canonical']; yield [FALSE, 'entity.node.canonical', [['node', NULL]]]; yield [TRUE, 'entity.node.canonical', [['node', TRUE]]]; } /** Loading Loading
core/modules/forum/tests/src/Unit/Breadcrumb/ForumListingBreadcrumbBuilderTest.php +20 −33 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Link; use Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder; use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\TermStorageInterface; use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\Container; Loading Loading @@ -46,12 +47,21 @@ protected function setUp(): void { * @dataProvider providerTestApplies * @covers ::applies */ public function testApplies($expected, $route_name = NULL, $parameter_map = []) { public function testApplies(bool $expected, ?string $route_name = NULL, array $parameter_map = []): void { // Make some test doubles. $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); $config_factory = $this->getConfigFactoryStub([]); $forum_manager = $this->createMock('Drupal\forum\ForumManagerInterface'); $translation_manager = $this->createMock('Drupal\Core\StringTranslation\TranslationInterface'); $map = []; if ($parameter_map) { foreach ($parameter_map as $parameter) { $map[] = [ $parameter[0], $parameter[1] === TRUE ? $this->getMockBuilder(Term::class)->disableOriginalConstructor()->getMock() : $parameter[1], ]; } } // Make an object to test. $builder = new ForumListingBreadcrumbBuilder($entity_type_manager, $config_factory, $forum_manager, $translation_manager); Loading @@ -62,7 +72,7 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = []) ->willReturn($route_name); $route_match->expects($this->any()) ->method('getParameter') ->willReturnMap($parameter_map); ->willReturnMap($map); $this->assertEquals($expected, $builder->applies($route_match)); } Loading @@ -70,40 +80,17 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = []) /** * Provides test data for testApplies(). * * @return array * Array of datasets for testApplies(). Structured as such: * @return \Generator * Datasets for testApplies(). Structured as such: * - ForumListBreadcrumbBuilder::applies() expected result. * - ForumListBreadcrumbBuilder::applies() $attributes input array. */ public function providerTestApplies() { // Send a Node mock, because NodeInterface cannot be mocked. $mock_term = $this->getMockBuilder('Drupal\taxonomy\Entity\Term') ->disableOriginalConstructor() ->getMock(); return [ [ FALSE, ], [ FALSE, 'NOT.forum.page', ], [ FALSE, 'forum.page', ], [ TRUE, 'forum.page', [['taxonomy_term', 'anything']], ], [ TRUE, 'forum.page', [['taxonomy_term', $mock_term]], ], ]; public static function providerTestApplies(): \Generator { yield [FALSE]; yield [FALSE, 'NOT.forum.page']; yield [FALSE, 'forum.page']; yield [TRUE, 'forum.page', [['taxonomy_term', 'anything']]]; yield [TRUE, 'forum.page', [['taxonomy_term', TRUE]]]; } /** Loading
core/modules/forum/tests/src/Unit/Breadcrumb/ForumNodeBreadcrumbBuilderTest.php +20 −33 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Link; use Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder; use Drupal\node\Entity\Node; use Drupal\taxonomy\TermStorageInterface; use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\Container; Loading Loading @@ -46,10 +47,19 @@ protected function setUp(): void { * @dataProvider providerTestApplies * @covers ::applies */ public function testApplies($expected, $route_name = NULL, $parameter_map = []) { public function testApplies(bool $expected, ?string $route_name = NULL, array $parameter_map = []): void { // Make some test doubles. $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); $config_factory = $this->getConfigFactoryStub([]); $map = []; if ($parameter_map) { foreach ($parameter_map as $parameter) { $map[] = [ $parameter[0], $parameter[1] === TRUE ? $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock() : $parameter[1], ]; } } $forum_manager = $this->createMock('Drupal\forum\ForumManagerInterface'); $forum_manager->expects($this->any()) Loading @@ -67,7 +77,7 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = []) ->willReturn($route_name); $route_match->expects($this->any()) ->method('getParameter') ->willReturnMap($parameter_map); ->willReturnMap($map); $this->assertEquals($expected, $builder->applies($route_match)); } Loading @@ -77,40 +87,17 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = []) * * Note that this test is incomplete, because we can't mock NodeInterface. * * @return array * Array of datasets for testApplies(). Structured as such: * @return \Generator * Datasets for testApplies(). Structured as such: * - ForumNodeBreadcrumbBuilder::applies() expected result. * - ForumNodeBreadcrumbBuilder::applies() $attributes input array. */ public function providerTestApplies() { // Send a Node mock, because NodeInterface cannot be mocked. $mock_node = $this->getMockBuilder('Drupal\node\Entity\Node') ->disableOriginalConstructor() ->getMock(); return [ [ FALSE, ], [ FALSE, 'NOT.entity.node.canonical', ], [ FALSE, 'entity.node.canonical', ], [ FALSE, 'entity.node.canonical', [['node', NULL]], ], [ TRUE, 'entity.node.canonical', [['node', $mock_node]], ], ]; public static function providerTestApplies(): \Generator { yield [FALSE]; yield [FALSE, 'NOT.entity.node.canonical']; yield [FALSE, 'entity.node.canonical']; yield [FALSE, 'entity.node.canonical', [['node', NULL]]]; yield [TRUE, 'entity.node.canonical', [['node', TRUE]]]; } /** Loading