summaryrefslogtreecommitdiff
path: root/modules/system
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-04-20 18:24:07 +0000
committerDries Buytaert <dries@buytaert.net>2008-04-20 18:24:07 +0000
commitaf474609e3e80db9ba1d16b9ad2eae89775f51c8 (patch)
treee525479dd6381b94d21943c3d2decf1c749c028c /modules/system
parentfe7b9baff62379f5a0c901d27cbb677345791bd0 (diff)
downloadbrdo-af474609e3e80db9ba1d16b9ad2eae89775f51c8.tar.gz
brdo-af474609e3e80db9ba1d16b9ad2eae89775f51c8.tar.bz2
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable the module and check it out ... :) Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran Lal, Moshe Weitzman, and the many other people that helped with testing over the past years and that drove this home. It all works but it is still rough around the edges (i.e. documentation is still being written, the coding style is not 100% yet, a number of tests still fail) but we spent the entire weekend working on it in Paris and made a ton of progress. The best way to help and to get up to speed, is to start writing and contributing some tests ... as well as fixing some of the failures. For those willing to help with improving the test framework, here are some next steps and issues to resolve: - How to best approach unit tests and mock functions? - How to test drupal_mail() and drupal_http_request()? - How to improve the admin UI so we have a nice progress bar? - How best to do code coverage? - See http://g.d.o/node/10099 for more ...
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/system.test128
1 files changed, 128 insertions, 0 deletions
diff --git a/modules/system/system.test b/modules/system/system.test
new file mode 100644
index 000000000..657c4b95e
--- /dev/null
+++ b/modules/system/system.test
@@ -0,0 +1,128 @@
+<?php
+// $Id$
+
+class EnableDisableCoreTestCase extends DrupalWebTestCase {
+ /**
+ * Implementation of getInfo().
+ */
+ function getInfo() {
+ return array(
+ 'name' => t('Module list functionality'),
+ 'description' => t('Enable/disable core module and confirm table creation/deletion. Enable module without dependecy enabled.'),
+ 'group' => t('System')
+ );
+ }
+
+ /**
+ * Implementation of setUp().
+ */
+ function setUp() {
+ parent::setUp();
+
+ $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer site configuration'));
+ $this->drupalLogin($admin_user);
+ }
+
+ /**
+ * Enable a module, check the database for related tables, disable module,
+ * check for related tables, unistall module, check for related tables.
+ */
+ function testEnableDisable() {
+ $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer site configuration'));
+ $this->drupalLogin($admin_user);
+
+ // Enable aggregator, and check tables.
+ $this->assertModules(array('aggregator'), FALSE);
+ $this->assertTableCount('aggregator', FALSE);
+
+ $edit = array();
+ $edit['status[aggregator]'] = 'aggregator';
+ $this->drupalPost('admin/build/modules', $edit, t('Save configuration'));
+ $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
+
+ $this->assertModules(array('aggregator'), TRUE);
+ $this->assertTableCount('aggregator', TRUE);
+
+ // Disable aggregator, check tables, uninstall aggregator, check tables.
+ $edit = array();
+ $edit['status[aggregator]'] = FALSE;
+ $this->drupalPost('admin/build/modules', $edit, t('Save configuration'));
+ $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
+
+ $this->assertModules(array('aggregator'), FALSE);
+ $this->assertTableCount('aggregator', TRUE);
+
+ $edit = array();
+ $edit['uninstall[aggregator]'] = 'aggregator';
+ $this->drupalPost('admin/build/modules/uninstall', $edit, t('Uninstall'));
+
+ $this->drupalPost(NULL, NULL, t('Uninstall'));
+ $this->assertText(t('The selected modules have been uninstalled.'), t('Modules status has been updated.'));
+
+ $this->assertModules(array('aggregator'), FALSE);
+ $this->assertTableCount('aggregator', FALSE);
+ }
+
+ /**
+ * Attempt to enable translation module without locale enabled.
+ */
+ function testEnableWithoutDependency () {
+ $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer site configuration'));
+ $this->drupalLogin($admin_user);
+
+ // Attempt to enable content translation without locale enabled.
+ $edit = array();
+ $edit['status[translation]'] = 'translation';
+ $this->drupalPost('admin/build/modules', $edit, t('Save configuration'));
+ $this->assertText(t('Some required modules must be enabled'), t('Dependecy required.'));
+
+ $this->assertModules(array('translation', 'locale'), FALSE);
+
+ // Assert that the locale tables weren't enabled.
+ $this->assertTableCount('languages', FALSE);
+ $this->assertTableCount('locale', FALSE);
+
+ $this->drupalPost(NULL, NULL, t('Continue'));
+ $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
+
+ $this->assertModules(array('translation', 'locale'), TRUE);
+
+ // Assert that the locale tables were enabled.
+ $this->assertTableCount('languages', TRUE);
+ $this->assertTableCount('locale', TRUE);
+ }
+
+ /**
+ * Assert tables that begin with the specified base table name.
+ *
+ * @param string $base_table Begginning of table name to look for.
+ * @param boolean $count Assert tables that match specified base table.
+ * @return boolean Tables with specified base table.
+ */
+ function assertTableCount($base_table, $count) {
+ $match_count = simpletest_get_like_tables($base_table, TRUE);
+
+ if ($count) {
+ return $this->assertTrue($match_count, t('Tables matching "@base_table" found.', array('@base_table' => $base_table)));
+ }
+ return $this->assertFalse($match_count, t('Tables matching "@base_table" not found.', array('@base_table' => $base_table)));
+ }
+
+ /**
+ * Assert the list of modules are enabled or disabled.
+ *
+ * @param array $modules Modules to check.
+ * @param boolean $enabled Module state.
+ */
+ function assertModules(array $modules, $enabled) {
+ module_list(TRUE, FALSE);
+ foreach ($modules as $module) {
+ if ($enabled) {
+ $this->assertTrue(module_exists($module) == $enabled, t('Module "@module" is enabled.', array('@module' => $module)));
+ }
+ else {
+ $this->assertTrue(module_exists($module) == $enabled, t('Module "@module" not enabled.', array('@module' => $module)));
+ }
+ }
+ }
+}