Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / tests / src / Functional / Wizard / MenuTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Wizard;
4
5 use Drupal\Component\Render\FormattableMarkup;
6 use Drupal\Core\Url;
7
8 /**
9  * Tests the ability of the views wizard to put views in a menu.
10  *
11  * @group views
12  */
13 class MenuTest extends WizardTestBase {
14
15   /**
16    * Tests the menu functionality.
17    */
18   public function testMenus() {
19     $this->drupalPlaceBlock('system_menu_block:main');
20
21     // Create a view with a page display and a menu link in the Main Menu.
22     $view = [];
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'));
33
34     // Make sure there is a link to the view from the front page (where we
35     // expect the main menu to display).
36     $this->drupalGet('');
37     $this->assertResponse(200);
38     $this->assertLink($view['page[link_properties][title]']);
39     $this->assertLinkByHref(Url::fromUri('base:' . $view['page[path]'])->toString());
40
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);
50   }
51
52 }