You are here

function UpdateScriptFunctionalTest::testUpdateAccess in Drupal 7

Tests access to the update script.

File

modules/system/system.test, line 2471
Tests for system.module.

Class

UpdateScriptFunctionalTest
Tests for the update system functionality.

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();
  require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
  $user1->pass = user_hash_password(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);
}