function UpdateScriptTest::testUpdateAccess

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateScriptTest::testUpdateAccess()
  2. 10 core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateScriptTest::testUpdateAccess()
  3. 11.x core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateScriptTest::testUpdateAccess()

Tests access to the update script.

File

core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php, line 78

Class

UpdateScriptTest
Tests the update script access and functionality.

Namespace

Drupal\Tests\system\Functional\UpdateSystem

Code

public function testUpdateAccess() {
    // Try accessing update.php without the proper permission.
    $regular_user = $this->drupalCreateUser();
    $this->drupalLogin($regular_user);
    $this->drupalGet($this->updateUrl, [
        'external' => TRUE,
    ]);
    $this->assertSession()
        ->statusCodeEquals(403);
    // Check that a link to the update page is not accessible to regular users.
    $this->drupalGet('/update-script-test/database-updates-menu-item');
    $this->assertSession()
        ->linkNotExists('Run database updates');
    // Try accessing update.php as an anonymous user.
    $this->drupalLogout();
    $this->drupalGet($this->updateUrl, [
        'external' => TRUE,
    ]);
    $this->assertSession()
        ->statusCodeEquals(403);
    // Check that a link to the update page is not accessible to anonymous
    // users.
    $this->drupalGet('/update-script-test/database-updates-menu-item');
    $this->assertSession()
        ->linkNotExists('Run database updates');
    // Access the update page with the proper permission.
    $this->drupalLogin($this->updateUser);
    $this->drupalGet($this->updateUrl, [
        'external' => TRUE,
    ]);
    $this->assertSession()
        ->statusCodeEquals(200);
    // Check that a link to the update page is accessible to users with proper
    // permissions.
    $this->drupalGet('/update-script-test/database-updates-menu-item');
    $this->assertSession()
        ->linkExists('Run database updates');
    // Access the update page as user 1.
    $this->drupalLogin($this->rootUser);
    $this->drupalGet($this->updateUrl, [
        'external' => TRUE,
    ]);
    $this->assertSession()
        ->statusCodeEquals(200);
    // Check that a link to the update page is accessible to user 1.
    $this->drupalGet('/update-script-test/database-updates-menu-item');
    $this->assertSession()
        ->linkExists('Run database updates');
}

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