MDL-66903 testing: Helper to load fixture files

This commit is contained in:
Andrew Nicols
2024-07-15 12:22:17 +08:00
parent 7b0946129c
commit 85845b13d7
2 changed files with 35 additions and 0 deletions
+34
View File
@@ -745,4 +745,38 @@ abstract class advanced_testcase extends base_testcase {
}
$tasks->close();
}
/**
* 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);
}
}