From 4c0124b78a59ddeda84b4f1cafc3e66f367cd66b Mon Sep 17 00:00:00 2001 From: Dries <dries@buytaert.net> Date: Fri, 30 Mar 2012 12:02:46 -0400 Subject: [PATCH] - Patch #1481156 by npiacentine, lucascaro: Incorrect logic in creating url to fetch information about project updates. --- core/modules/update/update.fetch.inc | 2 +- core/modules/update/update.test | 56 +++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/core/modules/update/update.fetch.inc b/core/modules/update/update.fetch.inc index ec3bfbc25a9f..8588832873eb 100644 --- a/core/modules/update/update.fetch.inc +++ b/core/modules/update/update.fetch.inc @@ -271,7 +271,7 @@ function _update_build_fetch_url($project, $site_key = '') { // in the first place, and if this is not a disabled module or theme. We do // not want to record usage statistics for disabled code. if (!empty($site_key) && (strpos($project['project_type'], 'disabled') === FALSE)) { - $url .= (strpos($url, '?') === TRUE) ? '&' : '?'; + $url .= (strpos($url, '?') !== FALSE) ? '&' : '?'; $url .= 'site_key='; $url .= rawurlencode($site_key); if (!empty($project['info']['version'])) { diff --git a/core/modules/update/update.test b/core/modules/update/update.test index a657f91de0da..f91e41addf3f 100644 --- a/core/modules/update/update.test +++ b/core/modules/update/update.test @@ -649,7 +649,7 @@ class UpdateTestUploadCase extends UpdateTestHelper { * Ensure that archiver extensions are properly merged in the UI. */ function testFileNameExtensionMerging() { - $this->drupalGet('admin/modules/install'); + $this->drupalGet('admin/modules/install'); // Make sure the bogus extension supported by update_test.module is there. $this->assertPattern('/file extensions are supported:.*update-test-extension/', t("Found 'update-test-extension' extension")); // Make sure it didn't clobber the first option from core. @@ -697,3 +697,57 @@ class UpdateTestUploadCase extends UpdateTestHelper { } } + +class UpdateCoreUnitTestCase extends DrupalUnitTestCase { + + public static function getInfo() { + return array( + 'name' => "Unit tests", + 'description' => 'Test update funcionality unrelated to the database.', + 'group' => 'Update', + ); + } + + function setUp() { + parent::setUp('update'); + module_load_include('inc', 'update', 'update.fetch'); + } + + /** + * Tests _update_build_fetch_url according to issue 1481156 + */ + function testUpdateBuildFetchUrl() { + //first test that we didn't break the trivial case + $project['name'] = 'update_test'; + $project['project_type'] = ''; + $project['info']['version'] = ''; + $project['info']['project status url'] = 'http://www.example.com'; + $site_key = ''; + $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY; + $url = _update_build_fetch_url($project, $site_key); + $this->assertEqual($url, $expected, "'$url' when no site_key provided should be '$expected'."); + + //For disabled projects it shouldn't add the site key either. + $site_key = 'site_key'; + $project['project_type'] = 'disabled'; + $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY; + $url = _update_build_fetch_url($project, $site_key); + $this->assertEqual($url, $expected, "'$url' should be '$expected' for disabled projects."); + + //for enabled projects, adding the site key + $project['project_type'] = ''; + $expected = 'http://www.example.com/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY; + $expected .= '?site_key=site_key'; + $url = _update_build_fetch_url($project, $site_key); + $this->assertEqual($url, $expected, "When site_key provided, '$url' should be '$expected'."); + + // http://drupal.org/node/1481156 test incorrect logic when url contains + // a question mark. + $project['info']['project status url'] = 'http://www.example.com/?project='; + $expected = 'http://www.example.com/?project=/' . $project['name'] . '/' . DRUPAL_CORE_COMPATIBILITY; + $expected .= '&site_key=site_key'; + $url = _update_build_fetch_url($project, $site_key); + $this->assertEqual($url, $expected, "When ? is present, '$url' should be '$expected'."); + + } +} -- GitLab