diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 95a5642f681..7c6da7a43f5 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -998,7 +998,21 @@ class navigation_node implements renderable { ); } } + } + /** + * Reset all static data. + * + * @throws coding_exception if called outside of a unit test + */ + public static function reset_all_data(): void { + if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) { + throw new coding_exception('Resetting all data is not allowed outside of PHPUnit tests.'); + } + + self::$fullmeurl = null; + self::$autofindactive = true; + self::$loadadmintree = false; } } diff --git a/lib/phpunit/classes/util.php b/lib/phpunit/classes/util.php index 5c9d9cca89a..9d5acc4bae0 100644 --- a/lib/phpunit/classes/util.php +++ b/lib/phpunit/classes/util.php @@ -199,6 +199,7 @@ class phpunit_util extends testing_util { // reinitialise following globals $OUTPUT = new bootstrap_renderer(); $PAGE = new moodle_page(); + \navigation_node::reset_all_data(); $FULLME = null; $ME = null; $SCRIPT = null; diff --git a/lib/phpunit/tests/basic_test.php b/lib/phpunit/tests/basic_test.php index 839b1917d17..3c3c2a02690 100644 --- a/lib/phpunit/tests/basic_test.php +++ b/lib/phpunit/tests/basic_test.php @@ -145,6 +145,27 @@ STRING; self::assertTag(['id' => 'testid'], "