diff --git a/src/Tests/FootermapBlockIntegrationTest.php b/src/Tests/FootermapBlockIntegrationTest.php index 3e4a373..4b40cf0 100644 --- a/src/Tests/FootermapBlockIntegrationTest.php +++ b/src/Tests/FootermapBlockIntegrationTest.php @@ -28,10 +28,12 @@ class FootermapBlockIntegrationTest extends WebTestBase { $settings = [ 'label' => 'Footermap', - 'footermap_recurse_limit' => 0, - 'footermap_avail_menus' => ['user'], - 'footermap_display_heading' => 1, - 'footermap_top_menu' => '' + 'footermap' => [ + 'footermap_recurse_limit' => 0, + 'footermap_avail_menus' => ['user'], + 'footermap_display_heading' => 1, + 'footermap_top_menu' => '' + ] ]; $this->drupalPlaceBlock('footermap_block', $settings); diff --git a/tests/src/Unit/Plugin/Block/FootermapBlockTest.php b/tests/src/Unit/Plugin/Block/FootermapBlockTest.php index 4ff4a3f..552e251 100644 --- a/tests/src/Unit/Plugin/Block/FootermapBlockTest.php +++ b/tests/src/Unit/Plugin/Block/FootermapBlockTest.php @@ -1,10 +1,10 @@ 'menu1', 'description' => 'menu1', 'label' => 'menu1'], 'menu'); $menu2 = new Menu(['id' => 'menu2', 'description' => 'menu2', 'label' => 'menu2'], 'menu'); - + $link1 = [ 'title' => 'Link1' ]; @@ -50,7 +50,7 @@ class FootermapBlockTest extends UnitTestCase { 'enabled' => TRUE, 'options' => [], ]; - + $link1_child = [ 'title' => 'Child Link 1' ]; @@ -61,7 +61,7 @@ class FootermapBlockTest extends UnitTestCase { 'enabled' => TRUE, 'options' => [], ]; - + $configEntityType = new ConfigEntityType([ 'id' => 'menu', 'label' => 'Menu', @@ -69,12 +69,12 @@ class FootermapBlockTest extends UnitTestCase { 'entity_keys' => ['id' => 'id', 'label' => 'label'], 'admin_permission' => 'administer menu', ]); - + // Mock Static Menu link overrides. $staticMenuLinkOverrides = $this->getMockBuilder('\Drupal\Core\Menu\StaticMenuLinkOverridesInterface') ->disableOriginalConstructor() ->getMock(); - + // Create menu link plugin instances. $menu1_link1 = new MenuLinkDefault($link1, 'menu_link1', $link1_definition, $staticMenuLinkOverrides); $menu1_link2 = new MenuLinkDefault($link1_child, 'menu_link1_child', $link1_child_definition, $staticMenuLinkOverrides); @@ -91,8 +91,8 @@ class FootermapBlockTest extends UnitTestCase { ->willReturn([ 'menu1' => $menu1, 'menu2' => $menu2 - ]); - + ]); + // Mock the entity manager. $entityManager = $this->getMockBuilder('\Drupal\Core\Entity\EntityManagerInterface') ->disableOriginalConstructor() @@ -105,7 +105,7 @@ class FootermapBlockTest extends UnitTestCase { ->method('getDefinition') ->with('menu') ->willReturn($configEntityType); - + // Mock the menu link tree manager $menuLinkTree = $this->getMockBuilder('\Drupal\Core\Menu\MenuLinkTreeInterface') ->disableOriginalConstructor() @@ -117,12 +117,12 @@ class FootermapBlockTest extends UnitTestCase { $menuLinkTree->expects($this->any()) ->method('transform') ->willReturn([$menu1_tree]); - + // Mock the plugin manager for menu link $menuLinkPluginManager = $this->getMockBuilder('\Drupal\Core\Menu\MenuLinkManagerInterface') ->disableOriginalConstructor() ->getMock(); - + // Mock the Logger Channel factory. $loggerChannelFactory = $this->getMockBuilder('\Drupal\Core\Logger\LoggerChannelFactoryInterface') ->disableOriginalConstructor() @@ -131,26 +131,26 @@ class FootermapBlockTest extends UnitTestCase { ->method('get') ->with('footermap') ->willReturn(new LoggerChannel('footermap')); - + // Mock the Access Manager. $access_manager = $this->getMockBuilder('\Drupal\Core\Access\AccessManagerInterface') ->disableOriginalConstructor() ->getMock(); - + // Mock an anonymous user session. $account = $this->getMockBuilder('\Drupal\Core\Session\AnonymousUserSession') ->disableOriginalConstructor() ->getMock(); - + // Mock the entity query factory. $query_factory = $this->getMockBuilder('\Drupal\Core\Entity\Query\QueryFactory') ->disableOriginalConstructor() ->getMock(); - + $anonymousTreeManipulator = new AnonymousMenuLinkTreeManipulator($access_manager, $account, $query_factory); - + $this->container = new ContainerBuilder(); - + $this->container->set('entity.manager', $entityManager); $this->container->set('menu.link_tree', $menuLinkTree); $this->container->set('plugin.manager.menu.link', $menuLinkPluginManager); @@ -158,10 +158,10 @@ class FootermapBlockTest extends UnitTestCase { $this->container->set('footermap.anonymous_tree_manipulator', $anonymousTreeManipulator); $this->container->set('footermap.anonymous_user', $account); $this->container->set('logger.factory', $loggerChannelFactory); - + \Drupal::setContainer($this->container); } - + /** * @covers \Drupal\footermap\Plugin\Block\FootermapBlock::create */ @@ -169,7 +169,7 @@ class FootermapBlockTest extends UnitTestCase { $block = $this->getPlugin(); $this->assertInstanceOf('\Drupal\footermap\Plugin\Block\FootermapBlock', $block); } - + /** * @covers \Drupal\footermap\Plugin\Block\FootermapBlock::__construct */ @@ -183,7 +183,7 @@ class FootermapBlockTest extends UnitTestCase { 'plugin_id' => $plugin_id, 'provider' => 'footermap' ]; - + $block = new FootermapBlock( $configuration, $plugin_id, @@ -195,7 +195,7 @@ class FootermapBlockTest extends UnitTestCase { ); $this->assertInstanceOf('\Drupal\footermap\Plugin\Block\FootermapBlock', $block); } - + /** * @covers \Drupal\footermap\Plugin\Block\FootermapBlock::defaultConfiguration */ @@ -209,14 +209,14 @@ class FootermapBlockTest extends UnitTestCase { $block = $this->getPlugin(); $this->assertEquals($expected, $block->defaultConfiguration()); } - + /** * Assert that site map is built. */ public function testBuild() { $block = $this->getPlugin(); $block->setConfigurationValue('footermap_avail_menus', ['menu1' => 'menu1']); - + // Assert that site map is built with children. $map = $block->build(); $this->assertArrayHasKey('#footermap', $map); @@ -226,16 +226,8 @@ class FootermapBlockTest extends UnitTestCase { $this->assertEquals('Link1', $map['#footermap']['menu1']['#items']['menu-0']['#title']); $children = &$map['#footermap']['menu1']['#items']['menu-0']['#children']; $this->assertEquals('Child Link 1', $children['menu-0']['#title']); - - // Assert that the site map is built but child is hidden. - $block->setConfigurationValue('footermap_recurse_limit', 1); - $map2 = $block->build(); - $this->assertArrayNotHasKey('#children', $map2['#footermap']['menu1']['#items']['menu-0']); - - - // Assert that the site map is built with the root as the child. } - + /** * @covers \Drupal\footermap\Plugin\Block\FootermapBlock::blockForm */ @@ -243,26 +235,26 @@ class FootermapBlockTest extends UnitTestCase { $form_state = new FormState(); $block = $this->getPlugin(); $block->setConfigurationValue('footermap_avail_menus', ['menu1' => 'menu1']); - + $form = $block->blockForm([], $form_state); - + $this->assertEquals($form['footermap_avail_menus']['#options'], ['menu1' => 'menu1', 'menu2' => 'menu2']); $this->assertArrayHasKey('footermap_recurse_limit', $form); $this->assertArrayHasKey('footermap_top_menu', $form); $this->assertArrayHasKey('footermap_display_heading', $form); } - + /** * @covers \Drupal\footermap\Plugin\Block\FootermapBlock::access */ public function testAccess() { $block = $this->getPlugin(); $account = $this->container->get('footermap.anonymous_user'); - + $this->assertInstanceOf('\Drupal\Core\Access\AccessResultAllowed', $block->access($account, TRUE)); $this->assertTrue($block->access($account)); } - + /** * @covers \Drupal\footermap\Plugin\Block\FootermapBlock::getCacheContexts */ @@ -270,10 +262,10 @@ class FootermapBlockTest extends UnitTestCase { $block = $this->getPlugin(); $this->assertEquals(['cache_context.language'], $block->getCacheContexts()); } - + /** * Create an instance of the footermap block.plugin. - * + * * @returns \Drupal\footermap\Plugin\Block\FootermapBlock * A block plugin instance. */ @@ -287,10 +279,10 @@ class FootermapBlockTest extends UnitTestCase { 'plugin_id' => $plugin_id, 'provider' => 'footermap' ]; - + return FootermapBlock::create($this->container, $configuration, $plugin_id, $plugin_definition); } - + /** * Get the menu parameters to pass into menu tree parameters. * @@ -305,15 +297,15 @@ class FootermapBlockTest extends UnitTestCase { $parameters = new MenuTreeParameters(); $parameters->onlyEnabledLinks(); $parameters->excludeRoot(); - + if ($limit) { $parameters->setMaxDepth($limit); } - + if ($menu) { $parameters->setRoot($menu); } - + return $parameters; } }