From ef1d45b3943852db58aaa787c67ecbcd621255d4 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Thu, 20 Nov 2014 15:37:10 +0800 Subject: [PATCH] MDL-48302 behat: Reset cache before scenario --- lib/behat/classes/util.php | 27 +++++++++++++++++++++++++++ lib/tests/behat/behat_hooks.php | 8 +------- 2 files changed, 28 insertions(+), 7 deletions(-) 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/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 8b5f7349033..4c160dd7999 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -192,13 +192,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'));