You are here

public function UpdateScriptTest::testUpdateAccess in Drupal 8

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()

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() {

  // 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');
}