public function MenuAdminPerMenuEntityReferenceTest::testResaveEntityReferenceWithoutAccess in Menu Admin per Menu 8
Test resaving a menu entity reference field when the user has no access.
File
- tests/
src/ Functional/ MenuAdminPerMenuEntityReferenceTest.php, line 165
Class
- MenuAdminPerMenuEntityReferenceTest
- Tests a menu reference field in combination with Menu Admin per Menu.
Namespace
Drupal\Tests\menu_admin_per_menu\FunctionalCode
public function testResaveEntityReferenceWithoutAccess() {
$assert_session = $this
->assertSession();
// Create a node with user 1. This user can only access menu_1.
$this
->drupalLogin($this->menu1User);
$title = $this
->randomString();
$this
->drupalGet('node/add/page');
$this
->submitForm([
'title[0][value]' => $title,
'field_menu' => 'menu_1',
], 'Save');
$node = $this
->drupalGetNodeByTitle($title);
// Check that field_menu references menu_1.
$this
->assertEquals('menu_1', $node
->get('field_menu')->target_id);
// Login as user 2 and resave the node. User 2 can only access menu_2.
$this
->drupalLogin($this->menu2User);
$this
->drupalGet(sprintf('node/%s/edit', $node
->id()));
$submit_button = $assert_session
->buttonExists('Save');
$submit_button
->click();
$node = $this
->drupalGetNodeByTitle($title, TRUE);
// Check that the node still has menu_1 as value.
$this
->assertEquals('menu_1', $node
->get('field_menu')->target_id);
}