function UpdateScriptFunctionalTest::testUpdateAccess

7.x system.test UpdateScriptFunctionalTest::testUpdateAccess()

Tests access to the update script.

File

drupal-7.x/modules/system/system.test, line 2221
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);
}