class MenuUiNodeAccessTest
Edit a node when you don't have permission to add or edit menu links.
@group menu_ui
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait
- class \Drupal\Tests\menu_ui\Functional\MenuUiNodeAccessTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of MenuUiNodeAccessTest
File
-
core/
modules/ menu_ui/ tests/ src/ Functional/ MenuUiNodeAccessTest.php, line 16
Namespace
Drupal\Tests\menu_ui\FunctionalView source
class MenuUiNodeAccessTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'menu_ui',
'test_page_test',
'node',
'menu_link_access_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
}
/**
* Tests menu link create access is enforced.
*/
public function testMenuLinkCreateAccess() : void {
$this->drupalLogin($this->drupalCreateUser([
'administer menu',
'edit any page content',
]));
$node = Node::create([
'type' => 'page',
'title' => $this->randomMachineName(),
'uid' => $this->rootUser
->id(),
'status' => 1,
]);
$node->save();
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertSession()
->elementNotExists('css', 'input[name="menu[title]"]');
}
/**
* Tests menu link edit/delete access is enforced.
*/
public function testMenuLinkEditAccess() : void {
$this->drupalLogin($this->drupalCreateUser([
'administer menu',
'edit any page content',
]));
$mainLinkTitle = $this->randomMachineName();
$node = Node::create([
'type' => 'page',
'title' => $this->randomMachineName(),
'uid' => $this->rootUser
->id(),
'status' => 1,
]);
$node->save();
MenuLinkContent::create([
'link' => [
[
'uri' => 'entity:node/' . $node->id(),
],
],
'title' => $mainLinkTitle,
'menu_name' => 'main',
])
->save();
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertSession()
->elementNotExists('css', 'input[name="menu[title]"]');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.