MDL-86452 core: Reset navigation data between tests
This commit is contained in:
@@ -1017,7 +1017,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -205,6 +205,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;
|
||||
|
||||
@@ -333,4 +333,25 @@ STRING;
|
||||
$this->assertFalse($DB->is_transaction_started());
|
||||
$this->assertEquals($originalname, $DB->get_field('course', 'fullname', ['id' => $COURSE->id]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the navigation node URL is overridden correctly.
|
||||
*/
|
||||
public function test_set_navigation_url(): void {
|
||||
\navigation_node::override_active_url(new \core\url('/foo/bar/baz'));
|
||||
$this->assertNotNull(
|
||||
(new \ReflectionClass(\navigation_node::class))->getStaticPropertyValue('fullmeurl', null),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the after-test teardown correctly resets the navigation node URL.
|
||||
*
|
||||
* @depends test_set_navigation_url
|
||||
*/
|
||||
public function test_navigation_url_reset(): void {
|
||||
$this->assertNull(
|
||||
(new \ReflectionClass(\navigation_node::class))->getStaticPropertyValue('fullmeurl', null),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ final class navigationlib_test extends \advanced_testcase {
|
||||
protected function setup_node() {
|
||||
global $PAGE, $SITE;
|
||||
|
||||
// Perform a reset between tests to reset the PAGE.
|
||||
$this->resetAfterTest();
|
||||
|
||||
$PAGE->set_url('/');
|
||||
$PAGE->set_course($SITE);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user