function UpdateScriptTest::testUpdateAccess

Tests access to the update script.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php, line 46
Definition of Drupal\system\Tests\Update\UpdateScriptTest.

Class

UpdateScriptTest
Tests the update system functionality.

Namespace

Drupal\system\Tests\Update

Code

function testUpdateAccess() {

  // Try accessing update.php without the proper permission.
  $regular_user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($regular_user);
  $this
    ->drupalGet($this->update_url, array(
    'external' => TRUE,
  ));
  $this
    ->assertResponse(403);

  // Try accessing update.php as an anonymous user.
  $this
    ->drupalLogout();
  $this
    ->drupalGet($this->update_url, array(
    'external' => TRUE,
  ));
  $this
    ->assertResponse(403);

  // Access the update page with the proper permission.
  $this
    ->drupalLogin($this->update_user);
  $this
    ->drupalGet($this->update_url, array(
    'external' => TRUE,
  ));
  $this
    ->assertResponse(200);

  // Access the update page as user 1.
  $user1 = user_load(1);
  $user1->pass_raw = user_password();
  $user1->pass = drupal_container()
    ->get('password')
    ->hash(trim($user1->pass_raw));
  db_query("UPDATE {users} SET pass = :pass WHERE uid = :uid", array(
    ':pass' => $user1->pass,
    ':uid' => $user1->uid,
  ));
  $this
    ->drupalLogin($user1);
  $this
    ->drupalGet($this->update_url, array(
    'external' => TRUE,
  ));
  $this
    ->assertResponse(200);
}