function MenuUiTest::testMenuParentsJsAccess

Same name in other branches
  1. 9 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testMenuParentsJsAccess()
  2. 8.9.x core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testMenuParentsJsAccess()
  3. 10 core/modules/menu_ui/tests/src/Functional/MenuUiTest.php \Drupal\Tests\menu_ui\Functional\MenuUiTest::testMenuParentsJsAccess()

Tests if admin users, other than UID1, can access parents AJAX callback.

File

core/modules/menu_ui/tests/src/Functional/MenuUiTest.php, line 1056

Class

MenuUiTest
Tests the menu UI.

Namespace

Drupal\Tests\menu_ui\Functional

Code

public function testMenuParentsJsAccess() : void {
    $this->drupalLogin($this->drupalCreateUser([
        'administer menu',
    ]));
    // Just check access to the callback overall, the POST data is irrelevant.
    $this->drupalGet('admin/structure/menu/parents', [
        'query' => [
            MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax',
        ],
    ], [
        'X-Requested-With' => 'XMLHttpRequest',
    ]);
    $this->assertSession()
        ->statusCodeEquals(200);
    // Log in as authenticated user.
    $this->drupalLogin($this->drupalCreateUser());
    // Check that a simple user is not able to access the menu.
    $this->drupalGet('admin/structure/menu/parents', [
        'query' => [
            MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax',
        ],
    ], [
        'X-Requested-With' => 'XMLHttpRequest',
    ]);
    $this->assertSession()
        ->statusCodeEquals(403);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.