MDL-79338 core: add support for hook callback redirection in tests
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user