public function MenuAdminPerMenuEntityReferenceTest::testEntityReferenceField in Menu Admin per Menu 8
Test Menu Admin per Menu permissions in an entity reference field.
File
- tests/
src/ Functional/ MenuAdminPerMenuEntityReferenceTest.php, line 125
Class
- MenuAdminPerMenuEntityReferenceTest
- Tests a menu reference field in combination with Menu Admin per Menu.
Namespace
Drupal\Tests\menu_admin_per_menu\FunctionalCode
public function testEntityReferenceField() {
$assert_session = $this
->assertSession();
// User with 'administer menu' permission can access all menus.
$this
->drupalLogin($this->adminMenuUser);
$this
->drupalGet('node/add/page');
$assert_session
->selectExists('field_menu');
$assert_session
->optionExists('field_menu', 'menu_1');
$assert_session
->optionExists('field_menu', 'menu_2');
$assert_session
->optionExists('field_menu', 'menu_3');
// User with 'adminiser menu_1 menu items' can only access menu 1.
$this
->drupalLogin($this->menu1User);
$this
->drupalGet('node/add/page');
$assert_session
->selectExists('field_menu');
$assert_session
->optionExists('field_menu', 'menu_1');
$assert_session
->optionNotExists('field_menu', 'menu_2');
$assert_session
->optionNotExists('field_menu', 'menu_3');
// User with 'adminiser menu_2 menu items' can only access menu 2.
$this
->drupalLogin($this->menu2User);
$this
->drupalGet('node/add/page');
$assert_session
->selectExists('field_menu');
$assert_session
->optionNotExists('field_menu', 'menu_1');
$assert_session
->optionExists('field_menu', 'menu_2');
$assert_session
->optionNotExists('field_menu', 'menu_3');
// Permission for this user was added by
// hook_menu_admin_per_menu_get_permissions_alter.
$this
->drupalLogin($this->menu3User);
$this
->drupalGet('node/add/page');
$assert_session
->selectExists('field_menu');
$assert_session
->optionNotExists('field_menu', 'menu_1');
$assert_session
->optionNotExists('field_menu', 'menu_2');
$assert_session
->optionExists('field_menu', 'menu_3');
}