MDL-48302 behat: Reset cache before scenario
authorRajesh Taneja <rajesh@moodle.com>
Thu, 20 Nov 2014 07:37:10 +0000 (15:37 +0800)
committerRajesh Taneja <rajesh@moodle.com>
Fri, 21 Nov 2014 02:22:56 +0000 (10:22 +0800)
lib/behat/classes/util.php
lib/tests/behat/behat_hooks.php

index 047ee28..713bb9f 100644 (file)
@@ -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();
+    }
 }
index 8b5f734..4c160dd 100644 (file)
@@ -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'));