summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/simpletest/drupal_web_test_case.php44
-rw-r--r--modules/simpletest/simpletest.test6
-rw-r--r--modules/system/system.module4
-rw-r--r--modules/system/system.test55
4 files changed, 76 insertions, 33 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 37c5964bc..ca7502fb7 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -1789,42 +1789,28 @@ class DrupalWebTestCase extends DrupalTestCase {
* Takes a path and returns an absolute path.
*
* @param $path
- * The path, can be a Drupal path or a site-relative path. It might have a
- * query, too. Can even be an absolute path which is just passed through.
+ * A path from the internal browser content.
* @return
- * An absolute path.
- *
- * @todo What is the intention of this function? It is only invoked from
- * locations, where URLs from the *output* are turned into absolute URLs,
- * so why do we pass that through url() again?
+ * The $path with $base_url prepended, if necessary.
*/
protected function getAbsoluteUrl($path) {
+ global $base_url, $base_path;
+
$parts = parse_url($path);
- // This is more crude than menu_path_is_external() but enough here.
if (empty($parts['host'])) {
- $options = array('absolute' => TRUE);
- $path = $parts['path'];
- $base_path = base_path();
- $n = strlen($base_path);
- if (substr($path, 0, $n) == $base_path) {
- $path = substr($path, $n);
+ // Ensure that we have a string (and no xpath object).
+ $path = (string) $path;
+ // Strip $base_path, if existent.
+ $length = strlen($base_path);
+ if (substr($path, 0, $length) === $base_path) {
+ $path = substr($path, $length);
}
- if (isset($parts['query'])) {
- parse_str($parts['query'], $options['query']);
- // Let's make it a bit more crude. It's not clear why we invoke url() on
- // a URL contained in the returned page output again, but since $path is
- // FALSE (see $path = $parts['path'] above) with Clean URLs disabled,
- // and url() now encodes the passed in query parameter array, we get a
- // double-encoded 'q' query string in the resulting absolute URL
- // generated by url(). This cannot be avoided in url(). But it could be
- // completely avoided if this function wouldn't be calling url().
- // @see SimpleTestURLTestCase->testGetAbsoluteUrl()
- if (isset($options['query']['q'])) {
- $path = $options['query']['q'];
- unset($options['query']['q']);
- }
+ // Ensure that we have an absolute path.
+ if ($path[0] !== '/') {
+ $path = '/' . $path;
}
- $path = url($path, $options);
+ // Finally, prepend the $base_url.
+ $path = $base_url . $path;
}
return $path;
}
diff --git a/modules/simpletest/simpletest.test b/modules/simpletest/simpletest.test
index 31046392c..a26216a6e 100644
--- a/modules/simpletest/simpletest.test
+++ b/modules/simpletest/simpletest.test
@@ -293,17 +293,17 @@ class SimpleTestURLTestCase extends DrupalWebTestCase {
$this->drupalGet($url);
$absolute = url($url, array('absolute' => TRUE));
$this->assertEqual($absolute, $this->url, t('Passed and requested URL are equal.'));
- $this->assertEqual($this->url, $this->getAbsoluteUrl($url), t('Requested and returned absolute URL are equal.'));
+ $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), t('Requested and returned absolute URL are equal.'));
$this->drupalPost(NULL, array(), t('Log in'));
$this->assertEqual($absolute, $this->url, t('Passed and requested URL are equal.'));
- $this->assertEqual($this->url, $this->getAbsoluteUrl($url), t('Requested and returned absolute URL are equal.'));
+ $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), t('Requested and returned absolute URL are equal.'));
$this->clickLink('Create new account');
$url = 'user/register';
$absolute = url($url, array('absolute' => TRUE));
$this->assertEqual($absolute, $this->url, t('Passed and requested URL are equal.'));
- $this->assertEqual($this->url, $this->getAbsoluteUrl($url), t('Requested and returned absolute URL are equal.'));
+ $this->assertEqual($this->url, $this->getAbsoluteUrl($this->url), t('Requested and returned absolute URL are equal.'));
}
}
diff --git a/modules/system/system.module b/modules/system/system.module
index c3477faf7..14d5833bc 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -216,6 +216,10 @@ function system_permission() {
'title' => t('Administer site configuration'),
'description' => t('Configure site-wide settings such as module or theme administration settings.'),
),
+ 'administer software updates' => array(
+ 'title' => t('Administer software updates'),
+ 'description' => t('Run the update.php script.'),
+ ),
'administer actions' => array(
'title' => t('Administer actions'),
'description' => t('Manage the actions defined for your site.'),
diff --git a/modules/system/system.test b/modules/system/system.test
index 686d6cdb9..05b42f290 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -1210,7 +1210,7 @@ class TokenReplaceTestCase extends DrupalWebTestCase {
// passed properly through the call stack and being handled correctly by a 'known'
// token, [node:title].
$this->assertFalse(strcmp($target, $result), t('Basic placeholder tokens replaced.'));
-
+
$raw_tokens = array('title' => '[node:title]');
$generated = token_generate('node', $raw_tokens, array('node' => $node));
$this->assertFalse(strcmp($generated['[node:title]'], check_plain($node->title)), t('Token sanitized.'));
@@ -1290,3 +1290,56 @@ array_space[a b] = Value';
$this->assertEqual($parsed, $expected, t('Entire parsed .info string and expected array are identical.'));
}
}
+
+/**
+ * Tests for the update system functionality.
+ */
+class UpdateScriptFunctionalTest extends DrupalWebTestCase {
+ private $update_url;
+ private $update_user;
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Update functionality',
+ 'description' => 'Tests the update script access and functionality.',
+ 'group' => 'System',
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+ $this->update_url = $GLOBALS['base_url'] . '/update.php';
+ $this->update_user = $this->drupalCreateUser(array('administer software updates'));
+ }
+
+ /**
+ * Tests access to the update script.
+ */
+ 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);
+ }
+}