diff --git a/modules/update/tests/update_test.module b/modules/update/tests/update_test.module index 4e32d336afea644da469f2cdf5d91c3a280c4fee..4acb6ef837e605af25927aa7aeda03fea82212de 100644 --- a/modules/update/tests/update_test.module +++ b/modules/update/tests/update_test.module @@ -12,6 +12,12 @@ function update_test_menu() { 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); + $items['503-error'] = array( + 'title' => t('503 Service unavailable'), + 'page callback' => 'update_callback_service_unavailable', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); return $items; } @@ -148,3 +154,11 @@ public function getSettingsForm() { return $form; } } + +/** + * Return an Error 503 (Service unavailable) page. + */ +function update_callback_service_unavailable() { + drupal_add_http_header('Status', '503 Service unavailable'); + print "503 Service Temporarily Unavailable"; +} diff --git a/modules/update/update.fetch.inc b/modules/update/update.fetch.inc index ff69cbb114d66adf509c0c59a07c59458802465f..7ac0dbefbc2bb1555f87736823653fa9ec79b97d 100644 --- a/modules/update/update.fetch.inc +++ b/modules/update/update.fetch.inc @@ -143,7 +143,7 @@ function _update_process_fetch_task($project) { if (empty($fail[$fetch_url_base]) || $fail[$fetch_url_base] < $max_fetch_attempts) { $xml = drupal_http_request($url); - if (isset($xml->data)) { + if (!isset($xml->error) && isset($xml->data)) { $data = $xml->data; } } diff --git a/modules/update/update.test b/modules/update/update.test index 2688bb3aac99448027c1b143b7060b1fc7bcbeb2..a657f91de0da642903d3fcc188353e516b4ed8bd 100644 --- a/modules/update/update.test +++ b/modules/update/update.test @@ -32,9 +32,9 @@ class UpdateTestHelper extends DrupalWebTestCase { * * @see update_test_mock_page() */ - protected function refreshUpdateStatus($xml_map) { + protected function refreshUpdateStatus($xml_map, $url = 'update-test') { // Tell update module to fetch from the URL provided by update_test module. - variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE))); + variable_set('update_fetch_url', url($url, array('absolute' => TRUE))); // Save the map for update_test_mock_page() to use. variable_set('update_test_xml_map', $xml_map); // Manually check the update status. @@ -215,6 +215,16 @@ class UpdateCoreTestCase extends UpdateTestHelper { $this->assertNoText(t('There is a security update available for your version of Drupal.')); } + /** + * Tests the update module when the update server returns 503 (Service unavailable) errors. + */ + function testServiceUnavailable() { + $this->refreshUpdateStatus(array(), '503-error'); + // Ensure that no "Warning: SimpleXMLElement..." parse errors are found. + $this->assertNoText('SimpleXMLElement'); + $this->assertUniqueText(t('Failed to get available update data for one project.')); + } + protected function setSystemInfo7_0() { $setting = array( '#all' => array(