Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Drupal\views\Tests\Plugin;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\views\Tests\ViewTestBase;
/**
* Tests the menu links created in views.
*
* @group views
*/
class MenuLinkTest extends ViewTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_menu_link'];
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['views', 'views_ui', 'user', 'node', 'menu_ui', 'block'];
/**
* A user with permission to administer views, menus and view content.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
$this->adminUser = $this->drupalCreateUser(['administer views', 'administer menu']);
$this->drupalPlaceBlock('system_menu_block:main');
$this->drupalCreateContentType(['type' => 'page']);
}
/**
* Test that menu links using menu_link_content as parent are visible.
*/
public function testHierarchicalMenuLinkVisibility() {
$this->drupalLogin($this->adminUser);
$node = $this->drupalCreateNode(['type' => 'page']);
// Create a primary level menu link to the node.
$link = MenuLinkContent::create([
'title' => 'Primary level node',
'menu_name' => 'main',
'bundle' => 'menu_link_content',
'parent' => '',
'link' => [['uri' => 'entity:node/' . $node->id()]],
]);
$link->save();
$parent_menu_value = 'main:menu_link_content:' . $link->uuid();
// Alter the view's menu link in view page to use the menu link from the
// node as parent.
$this->drupalPostForm("admin/structure/views/nojs/display/test_menu_link/page_1/menu", [
'menu[type]' => 'normal',
'menu[title]' => 'Secondary level view page',
'menu[parent]' => $parent_menu_value,
], 'Apply');
// Save view which has pending changes.
$this->drupalPostForm(NULL, [], 'Save');
// Test if the node as parent menu item is selected in our views settings.
$this->drupalGet('admin/structure/views/nojs/display/test_menu_link/page_1/menu');
$this->assertOptionSelected('edit-menu-parent', $parent_menu_value);
$this->drupalGet('');
// Test if the primary menu item (node) is visible, and the secondary menu
// item (view) is hidden.
$this->assertText('Primary level node');
$this->assertNoText('Secondary level view page');
// Go to the node page and ensure that both the first and second level items
// are visible.
$this->drupalGet($node->urlInfo());
$this->assertText('Primary level node');
$this->assertText('Secondary level view page');
}
}