From ffc0e93c4eb0555a08f0b58bed0735416e6ba41f Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 20 Apr 2008 18:34:43 +0000 Subject: - 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 ... :) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ... --- modules/simpletest/drupal_unit_test_case.php | 97 ++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 modules/simpletest/drupal_unit_test_case.php (limited to 'modules/simpletest/drupal_unit_test_case.php') diff --git a/modules/simpletest/drupal_unit_test_case.php b/modules/simpletest/drupal_unit_test_case.php new file mode 100644 index 000000000..7a7807095 --- /dev/null +++ b/modules/simpletest/drupal_unit_test_case.php @@ -0,0 +1,97 @@ +getInfo(); + $label = $info['name']; + } + } + parent::__construct($label); + } + + /** + * Generates a random database prefix and runs the install scripts on the prefixed database. + * After installation many caches are flushed and the internal browser is setup so that the page + * requests will run on the new prefix. A temporary files directory is created with the same name + * as the database prefix. + * + * @param ... List modules to enable. + */ + public function setUp() { + parent::setUp(); + } + + /** + * Create a temporary environment for tests to take place in so that changes + * will be reverted and other tests won't be affected. + * + * Generates a random database prefix and runs the install scripts on the prefixed database. + * After installation many caches are flushed and the internal browser is setup so that the page + * requests will run on the new prefix. A temporary files directory is created with the same name + * as the database prefix. + */ + protected function createTempEnvironment() { + global $db_prefix, $simpletest_ua_key; + $this->created_temp_environment = TRUE; + if ($simpletest_ua_key) { + $this->db_prefix_original = $db_prefix; + $clean_url_original = variable_get('clean_url', 0); + $db_prefix = 'simpletest'. mt_rand(1000, 1000000); + include_once './includes/install.inc'; + drupal_install_system(); + $modules = array_unique(array_merge(func_get_args(), drupal_verify_profile('default', 'en'))); + drupal_install_modules($modules); + $this->_modules = drupal_map_assoc($modules); + $this->_modules['system'] = 'system'; + $task = 'profile'; + default_profile_tasks($task, ''); + menu_rebuild(); + actions_synchronize(); + _drupal_flush_css_js(); + variable_set('install_profile', 'default'); + variable_set('install_task', 'profile-finished'); + variable_set('clean_url', $clean_url_original); + + // Use temporary files directory with the same prefix as database. + $this->original_file_directory = file_directory_path(); + variable_set('file_directory_path', file_directory_path() .'/'. $db_prefix); + file_check_directory(file_directory_path(), TRUE); // Create the files directory. + } + } + + /** + * Delete created files and temporary files directory, delete the tables created by setUp(), + * and reset the database prefix. + */ + public function tearDown() { + global $db_prefix; + if ($this->created_temp_environment && preg_match('/simpletest\d+/', $db_prefix)) { + // Delete temporary files directory and reset files directory path. + simpletest_clean_temporary_directory(file_directory_path()); + variable_set('file_directory_path', $this->original_file_directory); + + $schema = drupal_get_schema(NULL, TRUE); + $ret = array(); + foreach ($schema as $name => $table) { + db_drop_table($ret, $name); + } + $db_prefix = $this->db_prefix_original; + } + parent::tearDown(); + } +} -- cgit v1.2.3