diff --git a/blocks/activity_modules/tests/behat/block_activity_modules.feature b/blocks/activity_modules/tests/behat/block_activity_modules.feature index 0bf0c45fd4f..3eefd4e5742 100644 --- a/blocks/activity_modules/tests/behat/block_activity_modules.feature +++ b/blocks/activity_modules/tests/behat/block_activity_modules.feature @@ -92,8 +92,8 @@ Feature: Block activity modules | activity | name | intro | course | idnumber | | assign | Test assignment name | Test assignment description | C1 | assign1 | | book | Test book name | Test book description | C1 | book1 | - | choice | Test choice name | Test choice description | C1 | choice1 | | chat | Test chat name | Test chat description | C1 | chat1 | + | choice | Test choice name | Test choice description | C1 | choice1 | | data | Test database name | Test database description | C1 | data1 | | feedback | Test feedback name | Test feedback description | C1 | feedback1 | | folder | Test folder name | Test folder description | C1 | folder1 | diff --git a/lib/behat/classes/util.php b/lib/behat/classes/util.php index 047ee289be6..713bb9f89a5 100644 --- a/lib/behat/classes/util.php +++ b/lib/behat/classes/util.php @@ -290,4 +290,31 @@ class behat_util extends testing_util { return behat_command::get_behat_dir() . '/test_environment_enabled.txt'; } + /** + * Reset contents of all database tables to initial values, reset caches, etc. + */ + public static function reset_all_data() { + // Reset all static caches. + accesslib_clear_all_caches(true); + // Reset the nasty strings list used during the last test. + nasty_strings::reset_used_strings(); + + filter_manager::reset_caches(); + + // Reset course and module caches. + if (class_exists('format_base')) { + // If file containing class is not loaded, there is no cache there anyway. + format_base::reset_course_cache(0); + } + get_fast_modinfo(0, 0, true); + + // Inform data generator. + self::get_data_generator()->reset(); + + // Purge dataroot directory. + self::reset_dataroot(); + + // Reset database. + self::reset_database(); + } } diff --git a/lib/testing/classes/util.php b/lib/testing/classes/util.php index 520cb775183..4fdd3c74825 100644 --- a/lib/testing/classes/util.php +++ b/lib/testing/classes/util.php @@ -715,6 +715,9 @@ abstract class testing_util { // Do not delete automatically installed files. self::skip_original_data_files($childclassname); + // Clear file status cache, before checking file_exists. + clearstatcache(); + // Clean up the dataroot folder. $handle = opendir(self::get_dataroot()); while (false !== ($item = readdir($handle))) { diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 8b5f7349033..81b1182b966 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -123,6 +123,10 @@ class behat_hooks extends behat_base { throw new Exception('Behat only can run if test mode is enabled. More info in ' . behat_command::DOCS_URL . '#Running_tests'); } + // Reset all data, before checking for is_server_running. + // If not done, then it can return apache error, while running tests. + behat_util::reset_all_data(); + if (!behat_util::is_server_running()) { throw new Exception($CFG->behat_wwwroot . ' is not available, ensure you specified correct url and that the server is set up and started.' . @@ -192,13 +196,7 @@ class behat_hooks extends behat_base { // Reset $SESSION. \core\session\manager::init_empty_session(); - behat_util::reset_database(); - behat_util::reset_dataroot(); - - accesslib_clear_all_caches(true); - - // Reset the nasty strings list used during the last test. - nasty_strings::reset_used_strings(); + behat_util::reset_all_data(); // Assign valid data to admin user (some generator-related code needs a valid user). $user = $DB->get_record('user', array('username' => 'admin'));