MDL-48302 behat: Reset cache before scenario

This commit is contained in:
Rajesh Taneja 2014-11-20 15:37:10 +08:00
parent ca0e301c7b
commit ef1d45b394
2 changed files with 28 additions and 7 deletions

View 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();
}
}

View 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'));