Commit 1aee24df authored by catch's avatar catch
Browse files

Issue #1594256 by aspilicious: Convert update tests to PSR-0.

parent ef4ba313
......@@ -2,271 +2,12 @@
/**
* @file
* Tests for update.module.
*
* This file contains tests for the update module. The overarching methodology
* of these tests is we need to compare a given state of installed modules and
* themes (e.g. version, project grouping, timestamps, etc) vs. a current
* state of what the release history XML files we fetch say is available. We
* have dummy XML files (in the 'tests' subdirectory) that describe various
* scenarios of what's available for different test projects, and we have
* dummy .info file data (specified via hook_system_info_alter() in the
* update_test helper module) describing what's currently installed. Each
* test case defines a set of projects to install, their current state (via
* the 'update_test_system_info' variable) and the desired available update
* data (via the 'update_test_xml_map' variable), and then performs a series
* of assertions that the report matches our expectations given the specific
* initial state and availability scenario.
* Definition of Drupal\update\Tests\UpdateContribTest.
*/
use Drupal\simpletest\WebTestBase;
use Drupal\simpletest\UnitTestBase;
namespace Drupal\update\Tests;
/**
* Base class to define some shared functions used by all update tests.
*/
class UpdateTestHelper extends WebTestBase {
/**
* Refresh the update status based on the desired available update scenario.
*
* @param $xml_map
* Array that maps project names to availability scenarios to fetch.
* The key '#all' is used if a project-specific mapping is not defined.
*
* @see update_test_mock_page()
*/
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($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.
$this->drupalGet('admin/reports/updates/check');
}
/**
* Run a series of assertions that are applicable for all update statuses.
*/
protected function standardTests() {
$this->assertRaw('<h3>' . t('Drupal core') . '</h3>');
$this->assertRaw(l(t('Drupal'), 'http://example.com/project/drupal'), t('Link to the Drupal project appears.'));
$this->assertNoText(t('No available releases found'));
}
}
class UpdateCoreTestCase extends UpdateTestHelper {
public static function getInfo() {
return array(
'name' => 'Update core functionality',
'description' => 'Tests the update module through a series of functional tests using mock XML data.',
'group' => 'Update',
);
}
function setUp() {
parent::setUp('update_test', 'update');
$admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules'));
$this->drupalLogin($admin_user);
}
/**
* Tests the update module when no updates are available.
*/
function testNoUpdatesAvailable() {
$this->setSystemInfo7_0();
$this->refreshUpdateStatus(array('drupal' => '0'));
$this->standardTests();
$this->assertText(t('Up to date'));
$this->assertNoText(t('Update available'));
$this->assertNoText(t('Security update required!'));
}
/**
* Tests the update module when one normal update ("7.1") is available.
*/
function testNormalUpdateAvailable() {
$this->setSystemInfo7_0();
$this->refreshUpdateStatus(array('drupal' => '1'));
$this->standardTests();
$this->assertNoText(t('Up to date'));
$this->assertText(t('Update available'));
$this->assertNoText(t('Security update required!'));
$this->assertRaw(l('7.1', 'http://example.com/drupal-7-1-release'), t('Link to release appears.'));
$this->assertRaw(l(t('Download'), 'http://example.com/drupal-7-1.tar.gz'), t('Link to download appears.'));
$this->assertRaw(l(t('Release notes'), 'http://example.com/drupal-7-1-release'), t('Link to release notes appears.'));
}
/**
* Tests the update module when a security update ("7.2") is available.
*/
function testSecurityUpdateAvailable() {
$this->setSystemInfo7_0();
$this->refreshUpdateStatus(array('drupal' => '2-sec'));
$this->standardTests();
$this->assertNoText(t('Up to date'));
$this->assertNoText(t('Update available'));
$this->assertText(t('Security update required!'));
$this->assertRaw(l('7.2', 'http://example.com/drupal-7-2-release'), t('Link to release appears.'));
$this->assertRaw(l(t('Download'), 'http://example.com/drupal-7-2.tar.gz'), t('Link to download appears.'));
$this->assertRaw(l(t('Release notes'), 'http://example.com/drupal-7-2-release'), t('Link to release notes appears.'));
}
/**
* Ensure proper results where there are date mismatches among modules.
*/
function testDatestampMismatch() {
$system_info = array(
'#all' => array(
// We need to think we're running a -dev snapshot to see dates.
'version' => '7.0-dev',
'datestamp' => time(),
),
'block' => array(
// This is 2001-09-09 01:46:40 GMT, so test for "2001-Sep-".
'datestamp' => '1000000000',
),
);
variable_set('update_test_system_info', $system_info);
$this->refreshUpdateStatus(array('drupal' => 'dev'));
$this->assertNoText(t('2001-Sep-'));
$this->assertText(t('Up to date'));
$this->assertNoText(t('Update available'));
$this->assertNoText(t('Security update required!'));
}
/**
* Check that running cron updates the list of available updates.
*/
function testModulePageRunCron() {
$this->setSystemInfo7_0();
variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
variable_set('update_test_xml_map', array('drupal' => '0'));
$this->cronRun();
$this->drupalGet('admin/modules');
$this->assertNoText(t('No update information available.'));
}
/**
* Check the messages at admin/modules when the site is up to date.
*/
function testModulePageUpToDate() {
$this->setSystemInfo7_0();
// Instead of using refreshUpdateStatus(), set these manually.
variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
variable_set('update_test_xml_map', array('drupal' => '0'));
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
$this->assertText(t('Checked available update data for one project.'));
$this->drupalGet('admin/modules');
$this->assertNoText(t('There are updates available for your version of Drupal.'));
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
}
/**
* Check the messages at admin/modules when missing an update.
*/
function testModulePageRegularUpdate() {
$this->setSystemInfo7_0();
// Instead of using refreshUpdateStatus(), set these manually.
variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
variable_set('update_test_xml_map', array('drupal' => '1'));
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
$this->assertText(t('Checked available update data for one project.'));
$this->drupalGet('admin/modules');
$this->assertText(t('There are updates available for your version of Drupal.'));
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
}
/**
* Check the messages at admin/modules when missing a security update.
*/
function testModulePageSecurityUpdate() {
$this->setSystemInfo7_0();
// Instead of using refreshUpdateStatus(), set these manually.
variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
variable_set('update_test_xml_map', array('drupal' => '2-sec'));
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
$this->assertText(t('Checked available update data for one project.'));
$this->drupalGet('admin/modules');
$this->assertNoText(t('There are updates available for your version of Drupal.'));
$this->assertText(t('There is a security update available for your version of Drupal.'));
// Make sure admin/appearance warns you you're missing a security update.
$this->drupalGet('admin/appearance');
$this->assertNoText(t('There are updates available for your version of Drupal.'));
$this->assertText(t('There is a security update available for your version of Drupal.'));
// Make sure duplicate messages don't appear on Update status pages.
$this->drupalGet('admin/reports/status');
// We're expecting "There is a security update..." inside the status report
// itself, but the drupal_set_message() appears as an li so we can prefix
// with that and search for the raw HTML.
$this->assertNoRaw('<li>' . t('There is a security update available for your version of Drupal.'));
$this->drupalGet('admin/reports/updates');
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
$this->drupalGet('admin/reports/updates/settings');
$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.'));
}
/**
* Tests that exactly one fetch task per project is created and not more.
*/
function testFetchTasks() {
$projecta = array(
'name' => 'aaa_update_test',
);
$projectb = array(
'name' => 'bbb_update_test',
);
$queue = queue('update_fetch_tasks');
$this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty');
update_create_fetch_task($projecta);
$this->assertEqual($queue->numberOfItems(), 1, 'Queue contains one item');
update_create_fetch_task($projectb);
$this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
// Try to add project a again.
update_create_fetch_task($projecta);
$this->assertEqual($queue->numberOfItems(), 2, 'Queue still contains two items');
// Clear cache and try again.
_update_cache_clear();
drupal_static_reset('_update_create_fetch_task');
update_create_fetch_task($projecta);
$this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items');
}
protected function setSystemInfo7_0() {
$setting = array(
'#all' => array(
'version' => '7.0',
),
);
variable_set('update_test_system_info', $setting);
}
}
class UpdateTestContribCase extends UpdateTestHelper {
class UpdateContribTest extends UpdateTestBase {
public static function getInfo() {
return array(
......@@ -630,157 +371,3 @@ function testHookUpdateStatusAlter() {
}
}
class UpdateTestUploadCase extends UpdateTestHelper {
public static function getInfo() {
return array(
'name' => 'Upload and extract module functionality',
'description' => 'Tests the update module\'s upload and extraction functionality.',
'group' => 'Update',
);
}
public function setUp() {
parent::setUp('update', 'update_test');
variable_set('allow_authorize_operations', TRUE);
$admin_user = $this->drupalCreateUser(array('administer software updates', 'administer site configuration'));
$this->drupalLogin($admin_user);
}
/**
* Tests upload and extraction of a module.
*/
public function testUploadModule() {
// Images are not valid archives, so get one and try to install it. We
// need an extra variable to store the result of drupalGetTestFiles()
// since reset() takes an argument by reference and passing in a constant
// emits a notice in strict mode.
$imageTestFiles = $this->drupalGetTestFiles('image');
$invalidArchiveFile = reset($imageTestFiles);
$edit = array(
'files[project_upload]' => $invalidArchiveFile->uri,
);
// This also checks that the correct archive extensions are allowed.
$this->drupalPost('admin/modules/install', $edit, t('Install'));
$this->assertText(t('Only files with the following extensions are allowed: @archive_extensions.', array('@archive_extensions' => archiver_get_extensions())),'Only valid archives can be uploaded.');
// Check to ensure an existing module can't be reinstalled. Also checks that
// the archive was extracted since we can't know if the module is already
// installed until after extraction.
$validArchiveFile = drupal_get_path('module', 'update') . '/tests/aaa_update_test.tar.gz';
$edit = array(
'files[project_upload]' => $validArchiveFile,
);
$this->drupalPost('admin/modules/install', $edit, t('Install'));
$this->assertText(t('@module_name is already installed.', array('@module_name' => 'AAA Update test')), 'Existing module was extracted and not reinstalled.');
}
/**
* Ensure that archiver extensions are properly merged in the UI.
*/
function testFileNameExtensionMerging() {
$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.
$this->assertPattern('/file extensions are supported:.*tar/', t("Found 'tar' extension"));
}
/**
* Check the messages on Update manager pages when missing a security update.
*/
function testUpdateManagerCoreSecurityUpdateMessages() {
$setting = array(
'#all' => array(
'version' => '7.0',
),
);
variable_set('update_test_system_info', $setting);
variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
variable_set('update_test_xml_map', array('drupal' => '2-sec'));
// Initialize the update status.
$this->drupalGet('admin/reports/updates');
// Now, make sure none of the Update manager pages have duplicate messages
// about core missing a security update.
$this->drupalGet('admin/modules/install');
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
$this->drupalGet('admin/modules/update');
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
$this->drupalGet('admin/appearance/install');
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
$this->drupalGet('admin/appearance/update');
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
$this->drupalGet('admin/reports/updates/install');
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
$this->drupalGet('admin/reports/updates/update');
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
$this->drupalGet('admin/update/ready');
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
}
}
class UpdateCoreUnitTestCase extends UnitTestBase {
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';
$project['includes'] = array('module1' => 'Module 1', 'module2' => 'Module 2');
$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';
$expected .= '&list=' . rawurlencode('module1,module2');
$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';
$expected .= '&list=' . rawurlencode('module1,module2');
$url = _update_build_fetch_url($project, $site_key);
$this->assertEqual($url, $expected, "When ? is present, '$url' should be '$expected'.");
}
}
<?php
/**
* @file
* Definition of Drupal\update\Tests\UpdateCoreTest.
*/
namespace Drupal\update\Tests;
class UpdateCoreTest extends UpdateTestBase {
public static function getInfo() {
return array(
'name' => 'Update core functionality',
'description' => 'Tests the update module through a series of functional tests using mock XML data.',
'group' => 'Update',
);
}
function setUp() {
parent::setUp('update_test', 'update');
$admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules'));
$this->drupalLogin($admin_user);
}
/**
* Tests the update module when no updates are available.
*/
function testNoUpdatesAvailable() {
$this->setSystemInfo7_0();
$this->refreshUpdateStatus(array('drupal' => '0'));
$this->standardTests();
$this->assertText(t('Up to date'));
$this->assertNoText(t('Update available'));
$this->assertNoText(t('Security update required!'));
}
/**
* Tests the update module when one normal update ("7.1") is available.
*/
function testNormalUpdateAvailable() {
$this->setSystemInfo7_0();
$this->refreshUpdateStatus(array('drupal' => '1'));
$this->standardTests();
$this->assertNoText(t('Up to date'));
$this->assertText(t('Update available'));
$this->assertNoText(t('Security update required!'));
$this->assertRaw(l('7.1', 'http://example.com/drupal-7-1-release'), t('Link to release appears.'));
$this->assertRaw(l(t('Download'), 'http://example.com/drupal-7-1.tar.gz'), t('Link to download appears.'));
$this->assertRaw(l(t('Release notes'), 'http://example.com/drupal-7-1-release'), t('Link to release notes appears.'));
}
/**
* Tests the update module when a security update ("7.2") is available.
*/
function testSecurityUpdateAvailable() {
$this->setSystemInfo7_0();
$this->refreshUpdateStatus(array('drupal' => '2-sec'));
$this->standardTests();
$this->assertNoText(t('Up to date'));
$this->assertNoText(t('Update available'));
$this->assertText(t('Security update required!'));
$this->assertRaw(l('7.2', 'http://example.com/drupal-7-2-release'), t('Link to release appears.'));
$this->assertRaw(l(t('Download'), 'http://example.com/drupal-7-2.tar.gz'), t('Link to download appears.'));
$this->assertRaw(l(t('Release notes'), 'http://example.com/drupal-7-2-release'), t('Link to release notes appears.'));
}
/**
* Ensure proper results where there are date mismatches among modules.
*/
function testDatestampMismatch() {
$system_info = array(
'#all' => array(
// We need to think we're running a -dev snapshot to see dates.
'version' => '7.0-dev',
'datestamp' => time(),
),
'block' => array(
// This is 2001-09-09 01:46:40 GMT, so test for "2001-Sep-".
'datestamp' => '1000000000',
),
);
variable_set('update_test_system_info', $system_info);
$this->refreshUpdateStatus(array('drupal' => 'dev'));
$this->assertNoText(t('2001-Sep-'));
$this->assertText(t('Up to date'));
$this->assertNoText(t('Update available'));
$this->assertNoText(t('Security update required!'));
}
/**
* Check that running cron updates the list of available updates.
*/
function testModulePageRunCron() {
$this->setSystemInfo7_0();
variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
variable_set('update_test_xml_map', array('drupal' => '0'));
$this->cronRun();
$this->drupalGet('admin/modules');
$this->assertNoText(t('No update information available.'));
}
/**
* Check the messages at admin/modules when the site is up to date.
*/
function testModulePageUpToDate() {
$this->setSystemInfo7_0();
// Instead of using refreshUpdateStatus(), set these manually.
variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
variable_set('update_test_xml_map', array('drupal' => '0'));
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
$this->assertText(t('Checked available update data for one project.'));
$this->drupalGet('admin/modules');
$this->assertNoText(t('There are updates available for your version of Drupal.'));
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
}
/**
* Check the messages at admin/modules when missing an update.
*/
function testModulePageRegularUpdate() {
$this->setSystemInfo7_0();
// Instead of using refreshUpdateStatus(), set these manually.
variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
variable_set('update_test_xml_map', array('drupal' => '1'));
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
$this->assertText(t('Checked available update data for one project.'));
$this->drupalGet('admin/modules');
$this->assertText(t('There are updates available for your version of Drupal.'));
$this->assertNoText(t('There is a security update available for your version of Drupal.'));
}
/**
* Check the messages at admin/modules when missing a security update.
*/
function testModulePageSecurityUpdate() {
$this->setSystemInfo7_0();
// Instead of using refreshUpdateStatus(), set these manually.
variable_set('update_fetch_url', url('update-test', array('absolute' => TRUE)));
variable_set('update_test_xml_map', array('drupal' => '2-sec'));
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
$this->assertText(t('Checked available update data for one project.'));
$this->drupalGet('admin/modules');
$this->assertNoText(t('There are updates available for your version of Drupal.'));
$this->assertText(t('There is a security update available for your version of Drupal.'));
// Make sure admin/appearance warns you you're missing a security update.
$this->drupalGet('admin/appearance');
$this->assertNoText(t('There are updates available for your version of Drupal.'));
$this->assertText(t('There is a security update available for your version of Drupal.'));
// Make sure duplicate messages don't appear on Update status pages.
$this->drupalGet('admin/reports/status');