View source
<?php
namespace Drupal\Tests\views\Functional\Plugin;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\Tests\views\Functional\ViewTestBase;
class MenuLinkTest extends ViewTestBase {
public static $testViews = [
'test_menu_link',
];
protected static $modules = [
'views',
'views_ui',
'user',
'node',
'menu_link_content',
'block',
];
protected $defaultTheme = 'stark';
protected $adminUser;
protected function setUp($import_test_views = TRUE, $modules = [
'views_test_config',
]) : void {
parent::setUp($import_test_views, $modules);
$this
->enableViewsTestModule();
$this->adminUser = $this
->drupalCreateUser([
'administer views',
'administer menu',
]);
$this
->drupalPlaceBlock('system_menu_block:main');
$this
->drupalCreateContentType([
'type' => 'page',
]);
}
public function testHierarchicalMenuLinkVisibility() {
$this
->drupalLogin($this->adminUser);
$node = $this
->drupalCreateNode([
'type' => 'page',
]);
$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();
$this
->drupalGet("admin/structure/views/nojs/display/test_menu_link/page_1/menu");
$this
->submitForm([
'menu[type]' => 'normal',
'menu[title]' => 'Secondary level view page',
'menu[parent]' => $parent_menu_value,
], 'Apply');
$this
->submitForm([], 'Save');
$this
->drupalGet('admin/structure/views/nojs/display/test_menu_link/page_1/menu');
$this
->assertTrue($this
->assertSession()
->optionExists('edit-menu-parent', $parent_menu_value)
->isSelected());
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains('Primary level node');
$this
->assertSession()
->pageTextNotContains('Secondary level view page');
$this
->drupalGet($node
->toUrl());
$this
->assertSession()
->pageTextContains('Primary level node');
$this
->assertSession()
->pageTextContains('Secondary level view page');
}
}