// Move the menu link back to the Tools menu.
$item->menu_name->value = 'tools';
$item->
save();
// Create a second node.
$child_node =
$this->
drupalCreateNode(['type' => 'article'
]);
// Assign a menu link to the second node, being a child of the first one.
$child_item = MenuLinkContent::
create([ 'link' =>
[['uri' => 'entity:node/' .
$child_node->
id()]],
'title' =>
$this->
randomMachineName(16
),
'parent' =>
$item->
getPluginId(),
'menu_name' =>
$item->
getMenuName(),
]);
$child_item->
save();
// Edit the first node.
$this->
drupalGet('node/' .
$node->
id() . '/edit'
);
// Assert that it is not possible to set the parent of the first node to itself or the second node.
$this->
assertSession()->
optionNotExists('edit-menu-menu-parent', 'tools:' .
$item->
getPluginId());
$this->
assertSession()->
optionNotExists('edit-menu-menu-parent', 'tools:' .
$child_item->
getPluginId());
// Assert that unallowed Administration menu is not available in options.
$this->
assertSession()->
optionNotExists('edit-menu-menu-parent', 'admin:'
);
}