3 namespace Drupal\Tests\views\Functional\Wizard;
5 use Drupal\Component\Render\FormattableMarkup;
9 * Tests the ability of the views wizard to put views in a menu.
13 class MenuTest extends WizardTestBase {
16 * Tests the menu functionality.
18 public function testMenus() {
19 $this->drupalPlaceBlock('system_menu_block:main');
21 // Create a view with a page display and a menu link in the Main Menu.
23 $view['label'] = $this->randomMachineName(16);
24 $view['id'] = strtolower($this->randomMachineName(16));
25 $view['description'] = $this->randomMachineName(16);
26 $view['page[create]'] = 1;
27 $view['page[title]'] = $this->randomMachineName(16);
28 $view['page[path]'] = $this->randomMachineName(16);
29 $view['page[link]'] = 1;
30 $view['page[link_properties][menu_name]'] = 'main';
31 $view['page[link_properties][title]'] = $this->randomMachineName(16);
32 $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
34 // Make sure there is a link to the view from the front page (where we
35 // expect the main menu to display).
37 $this->assertResponse(200);
38 $this->assertLink($view['page[link_properties][title]']);
39 $this->assertLinkByHref(Url::fromUri('base:' . $view['page[path]'])->toString());
41 // Make sure the link is associated with the main menu.
42 /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
43 $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
44 /** @var \Drupal\Core\Menu\MenuLinkInterface $link */
45 $link = $menu_link_manager->createInstance('views_view:views.' . $view['id'] . '.page_1');
46 $url = $link->getUrlObject();
47 $this->assertEqual($url->getRouteName(), 'view.' . $view['id'] . '.page_1', new FormattableMarkup('Found a link to %path in the main menu', ['%path' => $view['page[path]']]));
48 $metadata = $link->getMetaData();
49 $this->assertEqual(['view_id' => $view['id'], 'display_id' => 'page_1'], $metadata);