MDL-79338 core: add support for hook callback redirection in tests

This commit is contained in:
Petr Skoda
2023-09-14 11:47:52 +02:00
parent f42cc76a78
commit b2a2d3dc66
3 changed files with 60 additions and 0 deletions
+20
View File
@@ -499,6 +499,26 @@ abstract class advanced_testcase extends base_testcase {
return phpunit_util::start_event_redirection();
}
/**
* Override hook callbacks.
*
* @param string $hookname
* @param callable $callback
* @return void
*/
public function redirectHook(string $hookname, callable $callback): void {
\core\hook\manager::get_instance()->phpunit_redirect_hook($hookname, $callback);
}
/**
* Remove all hook overrides.
*
* @return void
*/
public function stopHookRedirections(): void {
\core\hook\manager::get_instance()->phpunit_stop_redirections();
}
/**
* Reset all database tables, restore global state and clear caches and optionally purge dataroot dir.
*
+3
View File
@@ -104,6 +104,9 @@ class phpunit_util extends testing_util {
public static function reset_all_data($detectchanges = false) {
global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION, $FULLME, $FILTERLIB_PRIVATE;
// Stop all hook redirections.
\core\hook\manager::get_instance()->phpunit_stop_redirections();
// Stop any message redirection.
self::stop_message_redirection();