MDL-66903 testing: Helper to load fixture files

This commit is contained in:
Andrew Nicols
2024-07-15 13:07:42 +08:00
parent 25df1ed645
commit aa55779ba0
2 changed files with 44 additions and 0 deletions
+34
View File
@@ -828,4 +828,38 @@ abstract class advanced_testcase extends base_testcase {
$mockedcomponent->setStaticPropertyValue('plugins', $plugins);
$this->resetDebugging();
}
/**
* Convenience method to load a fixture from a component's fixture directory.
*
* @param string $component
* @param string $path
* @throws coding_exception
*/
protected static function load_fixture(
string $component,
string $path,
): void {
$fullpath = sprintf(
"%s/tests/fixtures/%s",
\core_component::get_component_directory($component),
$path,
);
if (!file_exists($fullpath)) {
throw new \coding_exception("Fixture file not found: $fullpath");
}
global $ADMIN;
global $CFG;
global $DB;
global $SITE;
global $USER;
global $OUTPUT;
global $PAGE;
global $SESSION;
global $COURSE;
global $SITE;
require_once($fullpath);
}
}