function UpdateScriptTest::testUpdateAccess

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateScriptTest::testUpdateAccess()
  2. 8.9.x 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 80

Class

UpdateScriptTest
Tests the update script access and functionality.

Namespace

Drupal\Tests\system\Functional\UpdateSystem

Code

public function testUpdateAccess() : void {
  // 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 administrator.
  $this->drupalLogin($this->createUser([
    'administer software updates',
    'access site in maintenance mode',
    'administer themes',
  ]));
  $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');
}

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