diff --git a/admin/presets/tests/helper_test.php b/admin/presets/tests/helper_test.php index f0e39c1ed97..3207c735276 100644 --- a/admin/presets/tests/helper_test.php +++ b/admin/presets/tests/helper_test.php @@ -364,7 +364,7 @@ class helper_test extends \advanced_testcase { 'preset' => 'unexisting', ], 'Valid XML file' => [ - 'preset' => __DIR__ . '/fixtures/import_settings_plugins.xml', + 'preset' => self::get_fixture_path(__NAMESPACE__, 'import_settings_plugins.xml'), 'settings' => [ 'allowemojipicker' => 1, 'enableportfolios' => 1, @@ -377,7 +377,7 @@ class helper_test extends \advanced_testcase { ], ], 'Invalid XML file' => [ - 'preset' => __DIR__ . '/fixtures/invalid_xml_file.xml', + 'preset' => self::get_fixture_path(__NAMESPACE__, 'invalid_xml_file.xml'), ], 'Unexisting XML file' => [ 'preset' => __DIR__ . '/fixtures/unexisting.xml', diff --git a/admin/presets/tests/manager_test.php b/admin/presets/tests/manager_test.php index 2ab19814ebc..642f04fcee4 100644 --- a/admin/presets/tests/manager_test.php +++ b/admin/presets/tests/manager_test.php @@ -537,19 +537,25 @@ class manager_test extends \advanced_testcase { 'expectedpreset' => false, ], 'Import settings and plugins from a valid XML file' => [ - 'filecontents' => file_get_contents(__DIR__ . '/fixtures/import_settings_plugins.xml'), + 'filecontents' => file_get_contents( + filename: self::get_fixture_path(__NAMESPACE__, 'import_settings_plugins.xml') + ), 'expectedpreset' => true, 'expectedsettings' => true, 'expectedplugins' => true, ], 'Import only settings from a valid XML file' => [ - 'filecontents' => file_get_contents(__DIR__ . '/fixtures/import_settings.xml'), + 'filecontents' => file_get_contents( + filename: self::get_fixture_path(__NAMESPACE__, 'import_settings.xml') + ), 'expectedpreset' => true, 'expectedsettings' => true, 'expectedplugins' => false, ], 'Import settings and plugins from a valid XML file with Starter name, which will be marked as non-core' => [ - 'filecontents' => file_get_contents(__DIR__ . '/fixtures/import_starter_name.xml'), + 'filecontents' => file_get_contents( + filename: self::get_fixture_path(__NAMESPACE__, 'import_starter_name.xml') + ), 'expectedpreset' => true, 'expectedsettings' => true, 'expectedplugins' => true, @@ -558,7 +564,9 @@ class manager_test extends \advanced_testcase { 'expectedpresetname' => 'Starter', ], 'Import settings from an invalid XML file' => [ - 'filecontents' => file_get_contents(__DIR__ . '/fixtures/invalid_xml_file.xml'), + 'filecontents' => file_get_contents( + filename: self::get_fixture_path(__NAMESPACE__, 'invalid_xml_file.xml') + ), 'expectedpreset' => false, 'expectedsettings' => false, 'expectedplugins' => false, @@ -566,20 +574,26 @@ class manager_test extends \advanced_testcase { 'expectedexception' => \Exception::class, ], 'Import unexisting settings category' => [ - 'filecontents' => file_get_contents(__DIR__ . '/fixtures/unexisting_category.xml'), + 'filecontents' => file_get_contents( + filename: self::get_fixture_path(__NAMESPACE__, 'unexisting_category.xml') + ), 'expectedpreset' => false, 'expectedsettings' => false, 'expectedplugins' => false, ], 'Import unexisting setting' => [ - 'filecontents' => file_get_contents(__DIR__ . '/fixtures/unexisting_setting.xml'), + 'filecontents' => file_get_contents( + filename: self::get_fixture_path(__NAMESPACE__, 'unexisting_setting.xml') + ), 'expectedpreset' => false, 'expectedsettings' => false, 'expectedplugins' => false, 'expecteddebugging' => true, ], 'Import valid settings with one unexisting setting too' => [ - 'filecontents' => file_get_contents(__DIR__ . '/fixtures/import_settings_with_unexisting_setting.xml'), + 'filecontents' => file_get_contents( + filename: self::get_fixture_path(__NAMESPACE__, 'import_settings_with_unexisting_setting.xml'), + ), 'expectedpreset' => true, 'expectedsettings' => false, 'expectedplugins' => false, diff --git a/admin/roles/tests/preset_test.php b/admin/roles/tests/preset_test.php index bc18626b12f..bc7b32c15fe 100644 --- a/admin/roles/tests/preset_test.php +++ b/admin/roles/tests/preset_test.php @@ -84,7 +84,7 @@ class preset_test extends \advanced_testcase { public function test_mixed_levels(): void { // The problem here is that we cannot guarantee plugin contexts // have unique short names, so we have to also support level numbers. - $xml = file_get_contents(__DIR__ . '/fixtures/mixed_levels.xml'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'mixed_levels.xml')); $this->assertTrue(\core_role_preset::is_valid_preset($xml)); $preset = \core_role_preset::parse_preset($xml); diff --git a/admin/tool/behat/tests/manager_util_test.php b/admin/tool/behat/tests/manager_util_test.php index 5bb6627231c..35ff061ffc4 100644 --- a/admin/tool/behat/tests/manager_util_test.php +++ b/admin/tool/behat/tests/manager_util_test.php @@ -107,11 +107,11 @@ class manager_util_test extends \advanced_testcase { */ private function get_behat_config_util($behatconfigutil, $notheme = false) { // Create a map of arguments to return values. - $map = array( - array('withfeatures', __DIR__.'/fixtures/theme/withfeatures'), - array('nofeatures', __DIR__.'/fixtures/theme/nofeatures'), - array('defaulttheme', __DIR__.'/fixtures/theme/defaulttheme'), - ); + $map = [ + ['withfeatures', self::get_fixture_path(__NAMESPACE__, 'theme/withfeatures')], + ['nofeatures', self::get_fixture_path(__NAMESPACE__, 'theme/nofeatures')], + ['defaulttheme', self::get_fixture_path(__NAMESPACE__, 'theme/defaulttheme')], + ]; // List of themes is const for test. if ($notheme) { $themelist = array('defaulttheme'); diff --git a/admin/tool/lpimportcsv/tests/import_test.php b/admin/tool/lpimportcsv/tests/import_test.php index fafbef13e15..cc6ef990a6c 100644 --- a/admin/tool/lpimportcsv/tests/import_test.php +++ b/admin/tool/lpimportcsv/tests/import_test.php @@ -31,7 +31,9 @@ class import_test extends \advanced_testcase { $this->resetAfterTest(true); $this->setAdminUser(); - $importer = new framework_importer(file_get_contents(__DIR__ . '/fixtures/example.csv')); + $importer = new framework_importer( + file_get_contents(self::get_fixture_path(__NAMESPACE__, 'example.csv')), + ); $this->assertEquals('', $importer->get_error()); diff --git a/admin/tool/uploadcourse/tests/course_test.php b/admin/tool/uploadcourse/tests/course_test.php index 70cdc183edf..5a40d5ed67f 100644 --- a/admin/tool/uploadcourse/tests/course_test.php +++ b/admin/tool/uploadcourse/tests/course_test.php @@ -967,8 +967,14 @@ class course_test extends \advanced_testcase { // Restore from a file, checking that the file takes priority over the templatecourse. $mode = tool_uploadcourse_processor::MODE_CREATE_NEW; $updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY; - $data = array('shortname' => 'A1', 'backupfile' => __DIR__ . '/fixtures/backup.mbz', - 'summary' => 'A', 'category' => 1, 'fullname' => 'A1', 'templatecourse' => $c1->shortname); + $data = [ + 'shortname' => 'A1', + 'backupfile' => self::get_fixture_path(__NAMESPACE__, 'backup.mbz'), + 'summary' => 'A', + 'category' => 1, + 'fullname' => 'A1', + 'templatecourse' => $c1->shortname, + ]; $co = new tool_uploadcourse_course($mode, $updatemode, $data); $this->assertTrue($co->prepare()); $co->proceed(); @@ -986,8 +992,13 @@ class course_test extends \advanced_testcase { $this->assertTrue($found); // Restoring twice from the same file should work. - $data = array('shortname' => 'B1', 'backupfile' => __DIR__ . '/fixtures/backup.mbz', - 'summary' => 'B', 'category' => 1, 'fullname' => 'B1'); + $data = [ + 'shortname' => 'B1', + 'backupfile' => self::get_fixture_path(__NAMESPACE__, 'backup.mbz'), + 'summary' => 'B', + 'category' => 1, + 'fullname' => 'B1', + ]; $co = new tool_uploadcourse_course($mode, $updatemode, $data); $this->assertTrue($co->prepare()); $co->proceed(); @@ -1020,8 +1031,14 @@ class course_test extends \advanced_testcase { $mode = tool_uploadcourse_processor::MODE_CREATE_NEW; $updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY; - $data = array('shortname' => 'A1', 'backupfile' => __DIR__ . '/fixtures/backup.mbz', - 'summary' => 'A', 'category' => 1, 'fullname' => 'A1', 'templatecourse' => $c1->shortname); + $data = [ + 'shortname' => 'A1', + 'backupfile' => self::get_fixture_path(__NAMESPACE__, 'backup.mbz'), + 'summary' => 'A', + 'category' => 1, + 'fullname' => 'A1', + 'templatecourse' => $c1->shortname, + ]; $co = new tool_uploadcourse_course($mode, $updatemode, $data); $this->assertTrue($co->prepare()); $co->proceed(); diff --git a/admin/tool/uploadcourse/tests/processor_test.php b/admin/tool/uploadcourse/tests/processor_test.php index 9ad956d2114..2b4bcb540e5 100644 --- a/admin/tool/uploadcourse/tests/processor_test.php +++ b/admin/tool/uploadcourse/tests/processor_test.php @@ -110,11 +110,11 @@ class processor_test extends \advanced_testcase { $cir->load_csv_content($content, 'utf-8', 'comma'); $cir->init(); - $options = array( + $options = [ 'mode' => tool_uploadcourse_processor::MODE_CREATE_NEW, - 'restorefile' => __DIR__ . '/fixtures/backup.mbz', - 'templatecourse' => 'DoesNotExist' // Restorefile takes priority. - ); + 'restorefile' => self::get_fixture_path(__NAMESPACE__, 'backup.mbz'), + 'templatecourse' => 'DoesNotExist', // Restorefile takes priority. + ]; $defaults = array('category' => '1'); $p = new tool_uploadcourse_processor($cir, $options, $defaults); diff --git a/admin/tool/usertours/tests/helper_test.php b/admin/tool/usertours/tests/helper_test.php index 2b118af6899..ddc7db3c78a 100644 --- a/admin/tool/usertours/tests/helper_test.php +++ b/admin/tool/usertours/tests/helper_test.php @@ -106,7 +106,7 @@ final class helper_test extends \advanced_testcase { \core\di::set( \core\hook\manager::class, \core\hook\manager::phpunit_get_instance([ - 'test_plugin1' => __DIR__ . '/fixtures/invalid_serverside_hook_fixture.php', + 'test_plugin1' => self::get_fixture_path(__NAMESPACE__, 'invalid_serverside_hook_fixture.php'), ]), ); @@ -118,7 +118,7 @@ final class helper_test extends \advanced_testcase { \core\di::set( \core\hook\manager::class, \core\hook\manager::phpunit_get_instance([ - 'test_plugin1' => __DIR__ . '/fixtures/clientside_filter_for_serverside_hook.php', + 'test_plugin1' => self::get_fixture_path(__NAMESPACE__, 'clientside_filter_for_serverside_hook.php'), ]), ); @@ -130,7 +130,7 @@ final class helper_test extends \advanced_testcase { \core\di::set( \core\hook\manager::class, \core\hook\manager::phpunit_get_instance([ - 'test_plugin1' => __DIR__ . '/fixtures/serverside_filter_for_clientside_hook.php', + 'test_plugin1' => self::get_fixture_path(__NAMESPACE__, 'serverside_filter_for_clientside_hook.php'), ]), ); @@ -142,7 +142,7 @@ final class helper_test extends \advanced_testcase { \core\di::set( \core\hook\manager::class, \core\hook\manager::phpunit_get_instance([ - 'test_plugin1' => __DIR__ . '/fixtures/hook_fixtures.php', + 'test_plugin1' => self::get_fixture_path(__NAMESPACE__, 'hook_fixtures.php'), ]), ); @@ -175,7 +175,7 @@ final class helper_test extends \advanced_testcase { \core\di::set( \core\hook\manager::class, \core\hook\manager::phpunit_get_instance([ - 'test_plugin1' => __DIR__ . '/fixtures/invalid_clientside_hook_fixture.php', + 'test_plugin1' => self::get_fixture_path(__NAMESPACE__, 'invalid_clientside_hook_fixture.php'), ]), ); diff --git a/analytics/tests/analysis_test.php b/analytics/tests/analysis_test.php index 5d6fa8804fc..c9e7db37115 100644 --- a/analytics/tests/analysis_test.php +++ b/analytics/tests/analysis_test.php @@ -30,7 +30,7 @@ class analysis_test extends \advanced_testcase { * @return null */ public function test_fill_firstanalyses_cache(): void { - require_once(__DIR__ . '/fixtures/test_timesplitting_upcoming_seconds.php'); + require_once(self::get_fixture_path(__NAMESPACE__, 'test_timesplitting_upcoming_seconds.php')); $this->resetAfterTest(); $modelid = 1; diff --git a/course/tests/course_image_cache_test.php b/course/tests/course_image_cache_test.php index 2a825e7dad0..ce0a9cef2f2 100644 --- a/course/tests/course_image_cache_test.php +++ b/course/tests/course_image_cache_test.php @@ -125,7 +125,9 @@ class course_image_cache_test extends \advanced_testcase { $cache = course_image::get_instance_for_cache(new cache_definition()); // Create course without one image. - $draftid1 = $this->fill_draft_area(['filename1.jpg' => file_get_contents(__DIR__ . '/fixtures/image.jpg')]); + $draftid1 = $this->fill_draft_area([ + 'filename1.jpg' => file_get_contents(self::get_fixture_path(__NAMESPACE__, 'image.jpg')), + ]); $course1 = $this->getDataGenerator()->create_course(['overviewfiles_filemanager' => $draftid1]); $expected = $this->build_expected_course_image_url($course1, 'filename1.jpg'); $this->assertEquals($expected, $method->invokeArgs($cache, [$course1])); @@ -140,8 +142,8 @@ class course_image_cache_test extends \advanced_testcase { // Create course with two image files. $draftid1 = $this->fill_draft_area([ - 'filename1.jpg' => file_get_contents(__DIR__ . '/fixtures/image.jpg'), - 'filename2.jpg' => file_get_contents(__DIR__ . '/fixtures/image.jpg'), + 'filename1.jpg' => file_get_contents(self::get_fixture_path(__NAMESPACE__, 'image.jpg')), + 'filename2.jpg' => file_get_contents(self::get_fixture_path(__NAMESPACE__, 'image.jpg')), ]); $course1 = $this->getDataGenerator()->create_course(['overviewfiles_filemanager' => $draftid1]); @@ -159,8 +161,8 @@ class course_image_cache_test extends \advanced_testcase { // Create course with two image files and one zip file. $draftid1 = $this->fill_draft_area([ 'filename1.zip' => 'Test file contents2', - 'filename2.jpg' => file_get_contents(__DIR__ . '/fixtures/image.jpg'), - 'filename3.jpg' => file_get_contents(__DIR__ . '/fixtures/image.jpg'), + 'filename2.jpg' => file_get_contents(self::get_fixture_path(__NAMESPACE__, 'image.jpg')), + 'filename3.jpg' => file_get_contents(self::get_fixture_path(__NAMESPACE__, 'image.jpg')), ]); $course1 = $this->getDataGenerator()->create_course(['overviewfiles_filemanager' => $draftid1]); diff --git a/course/tests/course_summary_exporter_test.php b/course/tests/course_summary_exporter_test.php index e95c7a77783..d697d6ad478 100644 --- a/course/tests/course_summary_exporter_test.php +++ b/course/tests/course_summary_exporter_test.php @@ -61,7 +61,7 @@ class course_summary_exporter_test extends \advanced_testcase { 'filepath' => '/', ]; $fs = get_file_storage(); - $fs->create_file_from_string($filerecord, file_get_contents(__DIR__ . '/fixtures/image.jpg')); + $fs->create_file_from_string($filerecord, file_get_contents(self::get_fixture_path(__NAMESPACE__, 'image.jpg'))); $course = $this->getDataGenerator()->create_course(['overviewfiles_filemanager' => $draftid]); $coursecontext = context_course::instance($course->id); diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index 0c4c8af2053..d72350c2922 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -2876,7 +2876,7 @@ final class externallib_test extends externallib_advanced_testcase { 'filepath' => '/', ]; $fs = get_file_storage(); - $fs->create_file_from_pathname($filerecord, __DIR__ . '/fixtures/image.jpg'); + $fs->create_file_from_pathname($filerecord, self::get_fixture_path('core_course', 'image.jpg')); $course2 = self::getDataGenerator()->create_course([ 'visible' => 0, 'category' => $category2->id, diff --git a/enrol/lti/tests/helper_test.php b/enrol/lti/tests/helper_test.php index e1e99fdb6c6..479215224f2 100644 --- a/enrol/lti/tests/helper_test.php +++ b/enrol/lti/tests/helper_test.php @@ -479,11 +479,11 @@ class helper_test extends \advanced_testcase { $function = $helper->getMethod('set_xpath'); $document = new \DOMDocument(); - $document->load(realpath(__DIR__ . '/fixtures/input.xml')); + $document->load(realpath(self::get_fixture_path(__NAMESPACE__, 'input.xml'))); $xpath = new \DOMXpath($document); $function->invokeArgs(null, [$xpath, $parameters]); $result = $document->saveXML(); - $expected = file_get_contents(realpath(__DIR__ . '/fixtures/' . $expected)); + $expected = file_get_contents(realpath(self::get_fixture_path(__NAMESPACE__, $expected))); $this->assertEquals($expected, $result); } @@ -503,7 +503,7 @@ class helper_test extends \advanced_testcase { $function = $helper->getMethod('set_xpath'); $document = new \DOMDocument(); - $document->load(realpath(__DIR__ . '/fixtures/input.xml')); + $document->load(realpath(self::get_fixture_path(__NAMESPACE__, 'input.xml'))); $xpath = new \DOMXpath($document); $this->expectException('coding_exception'); diff --git a/enrol/lti/tests/tool_provider_test.php b/enrol/lti/tests/tool_provider_test.php index 7d8754614a0..874c44bdd22 100644 --- a/enrol/lti/tests/tool_provider_test.php +++ b/enrol/lti/tests/tool_provider_test.php @@ -206,7 +206,7 @@ class tool_provider_test extends \advanced_testcase { $consumer->consumerVersion = 'TEST CONSUMER INFO VERSION'; $consumer->enabled = true; $consumer->protected = true; - $profilejson = file_get_contents(__DIR__ . '/fixtures/tool_consumer_profile.json'); + $profilejson = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'tool_consumer_profile.json')); $consumer->profile = json_decode($profilejson); $consumer->save(); @@ -239,7 +239,7 @@ class tool_provider_test extends \advanced_testcase { $consumer->consumerVersion = 'TEST CONSUMER INFO VERSION'; $consumer->enabled = true; $consumer->protected = true; - $profilejson = file_get_contents(__DIR__ . '/fixtures/tool_consumer_profile.json'); + $profilejson = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'tool_consumer_profile.json')); $consumer->profile = json_decode($profilejson); $consumer->save(); diff --git a/h5p/tests/api_test.php b/h5p/tests/api_test.php index b3fe6c3322d..ae497f4797b 100644 --- a/h5p/tests/api_test.php +++ b/h5p/tests/api_test.php @@ -287,7 +287,7 @@ class api_test extends \advanced_testcase { // Create the H5P data. $filename = 'find-the-words.h5p'; - $path = __DIR__ . '/fixtures/' . $filename; + $path = self::get_fixture_path(__NAMESPACE__, $filename); $fakefile = helper::create_fake_stored_file_from_path($path); $config = (object)[ 'frame' => 1, @@ -350,7 +350,7 @@ class api_test extends \advanced_testcase { // Create the original file. $filename = 'greeting-card.h5p'; - $path = __DIR__ . '/fixtures/' . $filename; + $path = self::get_fixture_path(__NAMESPACE__, $filename); $originalfile = helper::create_fake_stored_file_from_path($path); $originalfilerecord = [ 'contextid' => $originalfile->get_contextid(), @@ -492,7 +492,7 @@ class api_test extends \advanced_testcase { // Create the file. $filename = 'greeting-card.h5p'; - $path = __DIR__ . '/fixtures/' . $filename; + $path = self::get_fixture_path(__NAMESPACE__, $filename); if ($filecomponent === 'contentbank') { $generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank'); $contents = $generator->generate_contentbank_data( @@ -754,7 +754,7 @@ class api_test extends \advanced_testcase { // Create the H5P data. $filename = 'find-the-words.h5p'; - $path = __DIR__ . '/fixtures/' . $filename; + $path = self::get_fixture_path(__NAMESPACE__, $filename); $fakefile = helper::create_fake_stored_file_from_path($path); $config = (object)[ 'frame' => 1, @@ -812,7 +812,7 @@ class api_test extends \advanced_testcase { // Create the H5P data. $filename = 'find-the-words.h5p'; - $path = __DIR__ . '/fixtures/' . $filename; + $path = self::get_fixture_path(__NAMESPACE__, $filename); $fakefile = helper::create_fake_stored_file_from_path($path); $config = (object)[ 'frame' => 1, diff --git a/h5p/tests/editor_test.php b/h5p/tests/editor_test.php index b04e5c6c070..b0aed637542 100644 --- a/h5p/tests/editor_test.php +++ b/h5p/tests/editor_test.php @@ -84,7 +84,7 @@ class editor_test extends advanced_testcase { // Add H5P content. // This is a valid .H5P file. $filename = 'find-the-words.h5p'; - $path = __DIR__ . '/fixtures/' . $filename; + $path = self::get_fixture_path(__NAMESPACE__, $filename); $syscontext = \context_system::instance(); $filerecord = [ 'contextid' => $syscontext->id, diff --git a/h5p/tests/file_storage_test.php b/h5p/tests/file_storage_test.php index 065f0e516c2..4ab8353dff6 100644 --- a/h5p/tests/file_storage_test.php +++ b/h5p/tests/file_storage_test.php @@ -475,7 +475,7 @@ class file_storage_test extends \advanced_testcase { public function test_saveFileFromZip(): void { $ziparchive = new zip_archive(); - $path = __DIR__ . '/fixtures/h5ptest.zip'; + $path = self::get_fixture_path(__NAMESPACE__, 'h5ptest.zip'); $result = $ziparchive->open($path, file_archive::OPEN); $files = $ziparchive->list_files(); @@ -562,7 +562,7 @@ class file_storage_test extends \advanced_testcase { $admin = get_admin(); // Prepare a valid .H5P file. - $path = __DIR__ . '/fixtures/'.$filename; + $path = self::get_fixture_path(__NAMESPACE__, $filename); // Libraries can be updated when the file has been created by admin, even when the current user is not the admin. $this->setUser($admin); diff --git a/h5p/tests/framework_test.php b/h5p/tests/framework_test.php index c7d2fc32df6..116c024b257 100644 --- a/h5p/tests/framework_test.php +++ b/h5p/tests/framework_test.php @@ -803,7 +803,7 @@ class framework_test extends \advanced_testcase { $this->getDataGenerator()->enrol_user($user->id, $course->id, 'student'); // Create the .h5p file. - $path = __DIR__ . '/fixtures/h5ptest.zip'; + $path = self::get_fixture_path(__NAMESPACE__, 'h5ptest.zip'); // Admin and manager should have permission to update libraries. $file = helper::create_fake_stored_file_from_path($path, $admin->id, $contextsys); @@ -860,7 +860,7 @@ class framework_test extends \advanced_testcase { $user = $this->getDataGenerator()->create_user(); // The H5P file. - $path = __DIR__ . '/fixtures/h5ptest.zip'; + $path = self::get_fixture_path(__NAMESPACE__, 'h5ptest.zip'); // An error should be raised when it's called before initialitzing it. $this->expectException('coding_exception'); diff --git a/h5p/tests/helper_test.php b/h5p/tests/helper_test.php index a257d04e246..b538bf49532 100644 --- a/h5p/tests/helper_test.php +++ b/h5p/tests/helper_test.php @@ -137,7 +137,7 @@ class helper_test extends \advanced_testcase { $this->setUser($user); // This is a valid .H5P file. - $path = __DIR__ . '/fixtures/greeting-card.h5p'; + $path = self::get_fixture_path(__NAMESPACE__, 'greeting-card.h5p'); $file = helper::create_fake_stored_file_from_path($path, (int)$user->id); $factory->get_framework()->set_file($file); @@ -173,7 +173,7 @@ class helper_test extends \advanced_testcase { $this->setUser($user); // This is a valid .H5P file. - $path = __DIR__ . '/fixtures/greeting-card.h5p'; + $path = self::get_fixture_path(__NAMESPACE__, 'greeting-card.h5p'); $file = helper::create_fake_stored_file_from_path($path, (int)$user->id); $factory->get_framework()->set_file($file); @@ -217,7 +217,7 @@ class helper_test extends \advanced_testcase { $this->setUser($user); // This is a valid .H5P file. - $path = __DIR__ . '/fixtures/guess-the-answer.h5p'; + $path = self::get_fixture_path(__NAMESPACE__, 'guess-the-answer.h5p'); $file = helper::create_fake_stored_file_from_path($path, (int)$user->id); $factory->get_framework()->set_file($file); @@ -263,7 +263,7 @@ class helper_test extends \advanced_testcase { $this->setUser($user); // Prepare an invalid .H5P file. - $path = __DIR__ . '/fixtures/h5ptest.zip'; + $path = self::get_fixture_path(__NAMESPACE__, 'h5ptest.zip'); $file = helper::create_fake_stored_file_from_path($path, (int)$user->id); $factory->get_framework()->set_file($file); $config = (object)[ @@ -297,7 +297,7 @@ class helper_test extends \advanced_testcase { $admin = get_admin(); // Prepare a valid .H5P file. - $path = __DIR__ . '/fixtures/greeting-card.h5p'; + $path = self::get_fixture_path(__NAMESPACE__, 'greeting-card.h5p'); // Files created by users can't be deployed. $file = helper::create_fake_stored_file_from_path($path, (int)$user->id); @@ -335,7 +335,7 @@ class helper_test extends \advanced_testcase { $admin = get_admin(); // Prepare a valid .H5P file. - $path = __DIR__ . '/fixtures/greeting-card.h5p'; + $path = self::get_fixture_path(__NAMESPACE__, 'greeting-card.h5p'); // Libraries can't be updated when the file has been created by users. $file = helper::create_fake_stored_file_from_path($path, (int)$user->id); @@ -385,7 +385,7 @@ class helper_test extends \advanced_testcase { $this->assertCount(2, $messages->info); // When saving an invalid .h5p file, 6 errors should be raised. - $path = __DIR__ . '/fixtures/h5ptest.zip'; + $path = self::get_fixture_path(__NAMESPACE__, 'h5ptest.zip'); $file = helper::create_fake_stored_file_from_path($path); $factory->get_framework()->set_file($file); $config = (object)[ diff --git a/lib/tests/date_test.php b/lib/tests/date_test.php index 98f4396cb90..99405ee69e1 100644 --- a/lib/tests/date_test.php +++ b/lib/tests/date_test.php @@ -126,7 +126,7 @@ class date_test extends advanced_testcase { * @covers ::normalise_timezone */ public function test_windows_conversion(): void { - $file = __DIR__ . '/fixtures/timezonewindows.xml'; + $file = self::get_fixture_path('core', 'timezonewindows.xml'); $contents = file_get_contents($file); preg_match_all('//', $contents, $matches, PREG_SET_ORDER); diff --git a/lib/tests/update_code_manager_test.php b/lib/tests/update_code_manager_test.php index d5df6d54084..c223322037b 100644 --- a/lib/tests/update_code_manager_test.php +++ b/lib/tests/update_code_manager_test.php @@ -66,7 +66,7 @@ class update_code_manager_test extends \advanced_testcase { public function test_unzip_plugin_file(): void { $codeman = new \core\update\testable_code_manager(); - $zipfilepath = __DIR__.'/fixtures/update_validator/zips/invalidroot.zip'; + $zipfilepath = self::get_fixture_path(__NAMESPACE__, 'update_validator/zips/invalidroot.zip'); $targetdir = make_request_directory(); mkdir($targetdir.'/aaa_another'); @@ -102,13 +102,13 @@ class update_code_manager_test extends \advanced_testcase { } } - $zipfilepath = __DIR__.'/fixtures/update_validator/zips/bar.zip'; + $zipfilepath = self::get_fixture_path(__NAMESPACE__, 'update_validator/zips/bar.zip'); $files = $codeman->unzip_plugin_file($zipfilepath, $targetdir, 'bar'); } public function test_unzip_plugin_file_multidir(): void { $codeman = new \core\update\testable_code_manager(); - $zipfilepath = __DIR__.'/fixtures/update_validator/zips/multidir.zip'; + $zipfilepath = self::get_fixture_path(__NAMESPACE__, 'update_validator/zips/multidir.zip'); $targetdir = make_request_directory(); // Attempting to rename the root folder if there are multiple ones should lead to exception. $this->expectException(\moodle_exception::class); @@ -118,18 +118,18 @@ class update_code_manager_test extends \advanced_testcase { public function test_get_plugin_zip_root_dir(): void { $codeman = new \core\update\testable_code_manager(); - $zipfilepath = __DIR__.'/fixtures/update_validator/zips/invalidroot.zip'; + $zipfilepath = self::get_fixture_path(__NAMESPACE__, 'update_validator/zips/invalidroot.zip'); $this->assertEquals('invalid-root', $codeman->get_plugin_zip_root_dir($zipfilepath)); - $zipfilepath = __DIR__.'/fixtures/update_validator/zips/bar.zip'; + $zipfilepath = self::get_fixture_path(__NAMESPACE__, 'update_validator/zips/bar.zip'); $this->assertEquals('bar', $codeman->get_plugin_zip_root_dir($zipfilepath)); - $zipfilepath = __DIR__.'/fixtures/update_validator/zips/multidir.zip'; + $zipfilepath = self::get_fixture_path(__NAMESPACE__, 'update_validator/zips/multidir.zip'); $this->assertSame(false, $codeman->get_plugin_zip_root_dir($zipfilepath)); } public function test_list_plugin_folder_files(): void { - $fixtures = __DIR__.'/fixtures/update_validator/plugindir'; + $fixtures = self::get_fixture_path(__NAMESPACE__, 'update_validator/plugindir'); $codeman = new \core\update\testable_code_manager(); $files = $codeman->list_plugin_folder_files($fixtures.'/foobar'); $this->assertIsArray($files); @@ -140,7 +140,7 @@ class update_code_manager_test extends \advanced_testcase { } public function test_zip_plugin_folder(): void { - $fixtures = __DIR__.'/fixtures/update_validator/plugindir'; + $fixtures = self::get_fixture_path(__NAMESPACE__, 'update_validator/plugindir'); $storage = make_request_directory(); $codeman = new \core\update\testable_code_manager(); $codeman->zip_plugin_folder($fixtures.'/foobar', $storage.'/foobar.zip'); @@ -159,7 +159,7 @@ class update_code_manager_test extends \advanced_testcase { } public function test_archiving_plugin_version(): void { - $fixtures = __DIR__.'/fixtures/update_validator/plugindir'; + $fixtures = self::get_fixture_path(__NAMESPACE__, 'update_validator/plugindir'); $codeman = new \core\update\testable_code_manager(); $this->assertFalse($codeman->archive_plugin_version($fixtures.'/foobar', 'local_foobar', 0)); diff --git a/mod/book/tool/importhtml/tests/locallib_test.php b/mod/book/tool/importhtml/tests/locallib_test.php index 56c1166f1e1..cff080ecef6 100644 --- a/mod/book/tool/importhtml/tests/locallib_test.php +++ b/mod/book/tool/importhtml/tests/locallib_test.php @@ -57,7 +57,7 @@ class locallib_test extends \advanced_testcase { $record->filename = 'chapters.zip'; $fs = get_file_storage(); - $file = $fs->create_file_from_pathname($record, __DIR__ . '/fixtures/chapters.zip'); + $file = $fs->create_file_from_pathname($record, self::get_fixture_path(__NAMESPACE__, 'chapters.zip')); // Importing the chapters. $sink = $this->redirectEvents(); diff --git a/mod/data/tests/entries_export_test.php b/mod/data/tests/entries_export_test.php index 0323fbe7f56..84cda6b9d4b 100644 --- a/mod/data/tests/entries_export_test.php +++ b/mod/data/tests/entries_export_test.php @@ -130,7 +130,7 @@ class entries_export_test extends \advanced_testcase { $includefiles = false; utils::data_exportdata($data->id, $fields, $selectedfields, $exporter, $currentgroup, $context, $exportuser, $exporttime, $exportapproval, $tags, $includefiles); - $this->assertEquals(file_get_contents(__DIR__ . '/fixtures/test_data_export_without_files.csv'), + $this->assertEquals(file_get_contents(self::get_fixture_path(__NAMESPACE__, 'test_data_export_without_files.csv')), $exporter->send_file(false)); $this->assertEquals(1, $exporter->get_records_count()); @@ -158,7 +158,7 @@ class entries_export_test extends \advanced_testcase { // that the filenames in the csv file correspond to the names of the exported file. // It also verifies that files with identical file names in different fields (or records) will be numbered // automatically (samplefile.png, samplefile_1.png, ...). - 'testexportfile.csv' => __DIR__ . '/fixtures/test_data_export_with_files.csv' + 'testexportfile.csv' => self::get_fixture_path(__NAMESPACE__, 'test_data_export_with_files.csv'), ]; for ($i = 0; $i < $ziparchive->count(); $i++) { // We here iterate over all files in the zip archive and check if their content is identical to the files diff --git a/mod/data/tests/entries_import_test.php b/mod/data/tests/entries_import_test.php index 8c2dd51d971..416207bd98a 100644 --- a/mod/data/tests/entries_import_test.php +++ b/mod/data/tests/entries_import_test.php @@ -104,7 +104,7 @@ final class entries_import_test extends \advanced_testcase { 'teacher' => $teacher, ] = $this->get_test_data(); - $importer = new csv_entries_importer(__DIR__ . '/fixtures/test_data_import.csv', + $importer = new csv_entries_importer(self::get_fixture_path(__NAMESPACE__, 'test_data_import.csv'), 'test_data_import.csv'); $importer->import_csv($cm, $data, 'UTF-8', 'comma'); @@ -136,7 +136,7 @@ final class entries_import_test extends \advanced_testcase { 'student' => $student, ] = $this->get_test_data(); - $importer = new csv_entries_importer(__DIR__ . '/fixtures/test_data_import_with_userdata.csv', + $importer = new csv_entries_importer(self::get_fixture_path(__NAMESPACE__, 'test_data_import_with_userdata.csv'), 'test_data_import_with_userdata.csv'); $importer->import_csv($cm, $data, 'UTF-8', 'comma'); @@ -177,7 +177,7 @@ final class entries_import_test extends \advanced_testcase { $fieldrecord->type = 'text'; $generator->create_field($fieldrecord, $data); - $importer = new csv_entries_importer(__DIR__ . '/fixtures/test_data_import_with_field_username.csv', + $importer = new csv_entries_importer(self::get_fixture_path(__NAMESPACE__, 'test_data_import_with_field_username.csv'), 'test_data_import_with_field_username.csv'); $importer->import_csv($cm, $data, 'UTF-8', 'comma'); @@ -239,7 +239,7 @@ final class entries_import_test extends \advanced_testcase { $fieldrecord->type = 'text'; $generator->create_field($fieldrecord, $data); - $importer = new csv_entries_importer(__DIR__ . '/fixtures/test_data_import_with_userdata.csv', + $importer = new csv_entries_importer(self::get_fixture_path(__NAMESPACE__, 'test_data_import_with_userdata.csv'), 'test_data_import_with_userdata.csv'); $importer->import_csv($cm, $data, 'UTF-8', 'comma'); @@ -298,7 +298,7 @@ final class entries_import_test extends \advanced_testcase { $this->setUser($testdata[$user]); - $importer = new csv_entries_importer(__DIR__ . '/fixtures/test_data_import.csv', 'test_data_import.csv'); + $importer = new csv_entries_importer(self::get_fixture_path(__NAMESPACE__, 'test_data_import.csv'), 'test_data_import.csv'); $importer->import_csv($cm, $data, 'UTF-8', 'comma'); $records = $this->get_data_records($data->id); @@ -331,7 +331,7 @@ final class entries_import_test extends \advanced_testcase { $this->setUser($testdata[$user]); - $importer = new csv_entries_importer(__DIR__ . '/fixtures/test_data_import_with_approved.csv', + $importer = new csv_entries_importer(self::get_fixture_path(__NAMESPACE__, 'test_data_import_with_approved.csv'), 'test_data_import_with_approved.csv'); $importer->import_csv($cm, $data, 'UTF-8', 'comma'); @@ -348,13 +348,13 @@ final class entries_import_test extends \advanced_testcase { 'cm' => $cm, ] = $this->get_test_data(); - $importer = new csv_entries_importer(__DIR__ . '/fixtures/test_data_import_with_files.zip', + $importer = new csv_entries_importer(self::get_fixture_path(__NAMESPACE__, 'test_data_import_with_files.zip'), 'test_data_import_with_files.zip'); $importer->import_csv($cm, $data, 'UTF-8', 'comma'); $records = $this->get_data_records($data->id); $ziparchive = new zip_archive(); - $ziparchive->open(__DIR__ . '/fixtures/test_data_import_with_files.zip'); + $ziparchive->open(self::get_fixture_path(__NAMESPACE__, 'test_data_import_with_files.zip')); $importedcontent = array_values($records)[0]->items; $this->assertEquals(17, $importedcontent['ID']->content); @@ -395,13 +395,13 @@ final class entries_import_test extends \advanced_testcase { 'cm' => $cm, ] = $this->get_test_data(); - $importer = new csv_entries_importer(__DIR__ . '/fixtures/test_data_import_with_files_missing_file.zip', + $importer = new csv_entries_importer(self::get_fixture_path(__NAMESPACE__, 'test_data_import_with_files_missing_file.zip'), 'test_data_import_with_files_missing_file.zip'); $importer->import_csv($cm, $data, 'UTF-8', 'comma'); $records = $this->get_data_records($data->id); $ziparchive = new zip_archive(); - $ziparchive->open(__DIR__ . '/fixtures/test_data_import_with_files_missing_file.zip'); + $ziparchive->open(self::get_fixture_path(__NAMESPACE__, 'test_data_import_with_files_missing_file.zip')); $importedcontent = array_values($records)[0]->items; $this->assertEquals(17, $importedcontent['ID']->content); diff --git a/mod/quiz/accessrule/seb/tests/access_manager_test.php b/mod/quiz/accessrule/seb/tests/access_manager_test.php index b07acd4dd45..daf59d45c99 100644 --- a/mod/quiz/accessrule/seb/tests/access_manager_test.php +++ b/mod/quiz/accessrule/seb/tests/access_manager_test.php @@ -325,7 +325,7 @@ class access_manager_test extends \advanced_testcase { $this->quiz = $this->create_test_quiz($this->course, settings_provider::USE_SEB_CONFIG_MANUALLY); $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]); $quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG); // Doesn't check basic header. - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $this->create_module_test_file($xml, $this->quiz->cmid); $quizsettings->save(); $accessmanager = $this->get_access_manager(); diff --git a/mod/quiz/accessrule/seb/tests/backup_restore_test.php b/mod/quiz/accessrule/seb/tests/backup_restore_test.php index 3a6cb0e3db5..63cd799f63e 100644 --- a/mod/quiz/accessrule/seb/tests/backup_restore_test.php +++ b/mod/quiz/accessrule/seb/tests/backup_restore_test.php @@ -201,7 +201,7 @@ class backup_restore_test extends \advanced_testcase { $expected = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]); $expected->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG); - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $this->create_module_test_file($xml, $this->quiz->cmid); $expected->save(); diff --git a/mod/quiz/accessrule/seb/tests/config_key_test.php b/mod/quiz/accessrule/seb/tests/config_key_test.php index 7fcc0ed40c0..351c3fb167f 100644 --- a/mod/quiz/accessrule/seb/tests/config_key_test.php +++ b/mod/quiz/accessrule/seb/tests/config_key_test.php @@ -53,7 +53,7 @@ class config_key_test extends \advanced_testcase { * @dataProvider real_ck_hash_provider */ public function test_config_key_hash_is_derived_correctly($config, $hash): void { - $xml = file_get_contents(__DIR__ . '/fixtures/' . $config); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, $config)); $derivedhash = config_key::generate($xml)->get_hash(); $this->assertEquals($hash, $derivedhash); } @@ -62,8 +62,8 @@ class config_key_test extends \advanced_testcase { * Check that the Config Key hash is not altered if the originatorVersion is present in the XML or not. */ public function test_presence_of_originator_version_does_not_effect_hash(): void { - $xmlwithoriginatorversion = file_get_contents(__DIR__ . '/fixtures/simpleunencrypted.seb'); - $xmlwithoutoriginatorversion = file_get_contents(__DIR__ . '/fixtures/simpleunencryptedwithoutoriginator.seb'); + $xmlwithoriginatorversion = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'simpleunencrypted.seb')); + $xmlwithoutoriginatorversion = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'simpleunencryptedwithoutoriginator.seb')); $hashwithorigver = config_key::generate($xmlwithoriginatorversion)->get_hash(); $hashwithoutorigver = config_key::generate($xmlwithoutoriginatorversion)->get_hash(); $this->assertEquals($hashwithorigver, $hashwithoutorigver); diff --git a/mod/quiz/accessrule/seb/tests/property_list_test.php b/mod/quiz/accessrule/seb/tests/property_list_test.php index bcb513ef187..ab23fe88e8e 100644 --- a/mod/quiz/accessrule/seb/tests/property_list_test.php +++ b/mod/quiz/accessrule/seb/tests/property_list_test.php @@ -235,11 +235,11 @@ class property_list_test extends \advanced_testcase { * Test that the xml is exported to JSON from a real SEB config file. Expected JSON extracted from SEB logs. */ public function test_export_to_json_full_file(): void { - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted_mac_001.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted_mac_001.seb')); $plist = new property_list($xml); $plist->delete_element('originatorVersion'); // JSON should not contain originatorVersion key. $generatedjson = $plist->to_json(); - $json = trim(file_get_contents(__DIR__ . '/fixtures/JSON_unencrypted_mac_001.txt')); + $json = trim(file_get_contents(self::get_fixture_path(__NAMESPACE__, 'JSON_unencrypted_mac_001.txt'))); $this->assertEquals($json, $generatedjson); } diff --git a/mod/quiz/accessrule/seb/tests/quiz_settings_test.php b/mod/quiz/accessrule/seb/tests/quiz_settings_test.php index b70988aeb7a..feef8a5a21d 100644 --- a/mod/quiz/accessrule/seb/tests/quiz_settings_test.php +++ b/mod/quiz/accessrule/seb/tests/quiz_settings_test.php @@ -499,7 +499,7 @@ class quiz_settings_test extends \advanced_testcase { $this->save_settings_with_optional_template($quizsettings, settings_provider::USE_SEB_TEMPLATE, $templateid); // Case for USE_SEB_UPLOAD_CONFIG, ensure template id reverts to 0. - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $this->create_module_test_file($xml, $this->quiz->cmid); $this->save_settings_with_optional_template($quizsettings, settings_provider::USE_SEB_UPLOAD_CONFIG); $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]); @@ -709,7 +709,7 @@ class quiz_settings_test extends \advanced_testcase { $this->assertNull($quizsettings->get_config()); $quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG); - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $this->create_module_test_file($xml, $this->quiz->cmid); $quizsettings->save(); $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]); diff --git a/mod/quiz/accessrule/seb/tests/rule_test.php b/mod/quiz/accessrule/seb/tests/rule_test.php index 9a9305bed4c..cf083d9ec22 100644 --- a/mod/quiz/accessrule/seb/tests/rule_test.php +++ b/mod/quiz/accessrule/seb/tests/rule_test.php @@ -413,7 +413,7 @@ class rule_test extends \advanced_testcase { // Set quiz setting to require seb and save BEK. $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]); $quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG); - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $this->create_module_test_file($xml, $this->quiz->cmid); $quizsettings->save(); @@ -517,7 +517,7 @@ class rule_test extends \advanced_testcase { // Set quiz setting to require seb and save BEK. $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]); $quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG); - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $this->create_module_test_file($xml, $this->quiz->cmid); $quizsettings->save(); @@ -576,7 +576,7 @@ class rule_test extends \advanced_testcase { $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]); $quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG); $quizsettings->set('allowedbrowserexamkeys', $browserexamkey); - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $this->create_module_test_file($xml, $this->quiz->cmid); $quizsettings->save(); @@ -694,7 +694,7 @@ class rule_test extends \advanced_testcase { $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]); $quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG); $quizsettings->set('allowedbrowserexamkeys', $browserexamkey); - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $this->create_module_test_file($xml, $this->quiz->cmid); $quizsettings->save(); @@ -823,7 +823,7 @@ class rule_test extends \advanced_testcase { // Set quiz setting to require seb. $quizsettings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]); $quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG); // Doesn't check basic header. - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $this->create_module_test_file($xml, $this->quiz->cmid); $quizsettings->save(); @@ -1082,7 +1082,7 @@ class rule_test extends \advanced_testcase { // Should see links when using uploaded config. $quizsettings->set('requiresafeexambrowser', settings_provider::USE_SEB_UPLOAD_CONFIG); - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $this->create_module_test_file($xml, $this->quiz->cmid); $quizsettings->save(); $this->assertStringContainsString($this->get_seb_launch_link(), $method->invoke($this->make_rule())); diff --git a/mod/quiz/accessrule/seb/tests/settings_provider_test.php b/mod/quiz/accessrule/seb/tests/settings_provider_test.php index 821d1c9e36a..2fe2944370a 100644 --- a/mod/quiz/accessrule/seb/tests/settings_provider_test.php +++ b/mod/quiz/accessrule/seb/tests/settings_provider_test.php @@ -911,7 +911,7 @@ class settings_provider_test extends \advanced_testcase { $user = $this->getDataGenerator()->create_user(); $this->setUser($user); - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $itemid = $this->create_test_draftarea_file($xml); $file = settings_provider::get_current_user_draft_file($itemid); $content = $file->get_content(); @@ -929,7 +929,7 @@ class settings_provider_test extends \advanced_testcase { $this->context = \context_module::instance($this->quiz->cmid); $this->set_up_user_and_role(); - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $draftitemid = $this->create_test_draftarea_file($xml); @@ -951,7 +951,7 @@ class settings_provider_test extends \advanced_testcase { $this->context = \context_module::instance($this->quiz->cmid); $this->set_up_user_and_role(); - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $draftitemid = $this->create_test_draftarea_file($xml); settings_provider::save_filemanager_sebconfigfile_draftarea($draftitemid, $this->quiz->cmid); @@ -980,7 +980,7 @@ class settings_provider_test extends \advanced_testcase { $this->set_up_user_and_role(); - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $draftitemid = $this->create_test_draftarea_file($xml); $fs = get_file_storage(); @@ -1194,7 +1194,7 @@ class settings_provider_test extends \advanced_testcase { $this->context = \context_module::instance($this->quiz->cmid); // Save file. - $xml = file_get_contents(__DIR__ . '/fixtures/unencrypted.seb'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'unencrypted.seb')); $draftitemid = $this->create_test_draftarea_file($xml); settings_provider::save_filemanager_sebconfigfile_draftarea($draftitemid, $this->quiz->cmid); $settings = seb_quiz_settings::get_record(['quizid' => $this->quiz->id]); diff --git a/mod/quiz/tests/restore_attempt_test.php b/mod/quiz/tests/restore_attempt_test.php index 5fd21c18c9b..b44161a2c54 100644 --- a/mod/quiz/tests/restore_attempt_test.php +++ b/mod/quiz/tests/restore_attempt_test.php @@ -53,7 +53,7 @@ class restore_attempt_test extends \advanced_testcase { // Contains a quiz with four attempts from different users. The users are as follows (user ID -> user): // 3 -> User 01, 4 -> User 02, 5 -> User 03, 6 -> User 04. // The user details for User 02 and User 03 have been removed from the backup file. - $testfixture = __DIR__ . '/fixtures/question_attempts_missing_users.mbz'; + $testfixture = self::get_fixture_path(__NAMESPACE__, 'question_attempts_missing_users.mbz'); // Extract our test fixture, ready to be restored. $backuptempdir = 'aaa'; diff --git a/privacy/tests/moodle_content_writer_test.php b/privacy/tests/moodle_content_writer_test.php index d718f70ca6c..7b05e466e60 100644 --- a/privacy/tests/moodle_content_writer_test.php +++ b/privacy/tests/moodle_content_writer_test.php @@ -507,7 +507,7 @@ class moodle_content_writer_test extends advanced_testcase { 0, '/', 'logo.png', - file_get_contents(__DIR__ . '/fixtures/logo.png'), + file_get_contents(self::get_fixture_path('core_privacy', 'logo.png')), ], 'UTF8' => [ 'submission_content', diff --git a/privacy/tests/request_helper_test.php b/privacy/tests/request_helper_test.php index 06241f4b813..045312940e1 100644 --- a/privacy/tests/request_helper_test.php +++ b/privacy/tests/request_helper_test.php @@ -203,7 +203,7 @@ class request_helper_test extends advanced_testcase { 'filename' => 'logo.png', ); - $content = file_get_contents(__DIR__ . '/fixtures/logo.png'); + $content = file_get_contents(self::get_fixture_path('core_privacy', 'logo.png')); // Store the file. $fs = get_file_storage(); diff --git a/question/format/blackboard_six/tests/blackboardformatpool_test.php b/question/format/blackboard_six/tests/blackboardformatpool_test.php index bc905a2bf66..f11184c250b 100644 --- a/question/format/blackboard_six/tests/blackboardformatpool_test.php +++ b/question/format/blackboard_six/tests/blackboardformatpool_test.php @@ -41,7 +41,7 @@ class blackboardformatpool_test extends \question_testcase { public function make_test_xml() { $xmlfile = new qformat_blackboard_six_file(); $xmlfile->filetype = 2; - $xmlfile->text = file_get_contents(__DIR__ . '/fixtures/sample_blackboard_pool.dat'); + $xmlfile->text = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'sample_blackboard_pool.dat')); return array(0 => $xmlfile); } diff --git a/question/format/blackboard_six/tests/blackboardsixformatqti_test.php b/question/format/blackboard_six/tests/blackboardsixformatqti_test.php index 3482c722850..5e92e8929e3 100644 --- a/question/format/blackboard_six/tests/blackboardsixformatqti_test.php +++ b/question/format/blackboard_six/tests/blackboardsixformatqti_test.php @@ -41,7 +41,7 @@ class blackboardsixformatqti_test extends \question_testcase { public function make_test_xml() { $xmlfile = new qformat_blackboard_six_file(); $xmlfile->filetype = 1; - $xmlfile->text = file_get_contents(__DIR__ . '/fixtures/sample_blackboard_qti.dat'); + $xmlfile->text = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'sample_blackboard_qti.dat')); return array(0 => $xmlfile); } public function test_import_match(): void { diff --git a/question/format/multianswer/tests/multianswerformat_test.php b/question/format/multianswer/tests/multianswerformat_test.php index 6f9db955d0d..ad86c976309 100644 --- a/question/format/multianswer/tests/multianswerformat_test.php +++ b/question/format/multianswer/tests/multianswerformat_test.php @@ -37,7 +37,7 @@ require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); class multianswerformat_test extends \question_testcase { public function test_import(): void { - $lines = file(__DIR__ . '/fixtures/questions.multianswer.txt'); + $lines = file(self::get_fixture_path(__NAMESPACE__, 'questions.multianswer.txt')); $importer = new qformat_multianswer(); $qs = $importer->readquestions($lines); @@ -73,7 +73,7 @@ The capital of France is {#5}. } public function test_read_brokencloze_1(): void { - $lines = file(__DIR__ . '/fixtures/broken_multianswer_1.txt'); + $lines = file(self::get_fixture_path(__NAMESPACE__, 'broken_multianswer_1.txt')); $importer = new qformat_multianswer(); // The importer echoes some errors, so we need to capture and check that. @@ -92,7 +92,7 @@ The capital of France is {#5}. } public function test_read_brokencloze_2(): void { - $lines = file(__DIR__ . '/fixtures/broken_multianswer_2.txt'); + $lines = file(self::get_fixture_path(__NAMESPACE__, 'broken_multianswer_2.txt')); $importer = new qformat_multianswer(); // The importer echoes some errors, so we need to capture and check that. @@ -112,7 +112,7 @@ The capital of France is {#5}. } public function test_read_brokencloze_3(): void { - $lines = file(__DIR__ . '/fixtures/broken_multianswer_3.txt'); + $lines = file(self::get_fixture_path(__NAMESPACE__, 'broken_multianswer_3.txt')); $importer = new qformat_multianswer(); // The importer echoes some errors, so we need to capture and check that. @@ -131,7 +131,7 @@ The capital of France is {#5}. } public function test_read_brokencloze_4(): void { - $lines = file(__DIR__ . '/fixtures/broken_multianswer_4.txt'); + $lines = file(self::get_fixture_path(__NAMESPACE__, 'broken_multianswer_4.txt')); $importer = new qformat_multianswer(); // The importer echoes some errors, so we need to capture and check that. diff --git a/question/format/xml/tests/qformat_xml_import_export_test.php b/question/format/xml/tests/qformat_xml_import_export_test.php index 37be1dceb16..5b5bdea9a5a 100644 --- a/question/format/xml/tests/qformat_xml_import_export_test.php +++ b/question/format/xml/tests/qformat_xml_import_export_test.php @@ -295,7 +295,7 @@ class qformat_xml_import_export_test extends advanced_testcase { 'penalty' => '1']); $qformat->setCategory($category); - $expectedxml = file_get_contents(__DIR__ . '/fixtures/export_category.xml'); + $expectedxml = file_get_contents(self::get_fixture_path('qformat_xml', 'export_category.xml')); $this->assert_same_xml($expectedxml, $qformat->exportprocess()); } @@ -459,7 +459,7 @@ class qformat_xml_import_export_test extends advanced_testcase { 'penalty' => '1']); $qformat->setCategory($categoryiota); - $expectedxml = file_get_contents(__DIR__ . '/fixtures/nested_categories_with_questions.xml'); + $expectedxml = file_get_contents(self::get_fixture_path('qformat_xml', 'nested_categories_with_questions.xml')); $this->assert_same_xml($expectedxml, $qformat->exportprocess()); } @@ -498,7 +498,7 @@ class qformat_xml_import_export_test extends advanced_testcase { 'penalty' => '1']); $qformat->setCategory($category); - $expectedxml = file_get_contents(__DIR__ . '/fixtures/html_chars_in_idnumbers.xml'); + $expectedxml = file_get_contents(self::get_fixture_path('qformat_xml', 'html_chars_in_idnumbers.xml')); $this->assert_same_xml($expectedxml, $qformat->exportprocess()); } @@ -506,7 +506,7 @@ class qformat_xml_import_export_test extends advanced_testcase { * Test that bad multianswer questions are not imported. */ public function test_import_broken_multianswer_questions(): void { - $lines = file(__DIR__ . '/fixtures/broken_cloze_questions.xml'); + $lines = file(self::get_fixture_path('qformat_xml', 'broken_cloze_questions.xml')); $importer = $qformat = new qformat_xml(); // The importer echoes some errors, so we need to capture and check that. diff --git a/question/type/ordering/tests/questiontype_test.php b/question/type/ordering/tests/questiontype_test.php index 5a390258ba4..f376717c832 100644 --- a/question/type/ordering/tests/questiontype_test.php +++ b/question/type/ordering/tests/questiontype_test.php @@ -237,7 +237,7 @@ final class questiontype_test extends \question_testcase { public function test_xml_import(): void { $this->resetAfterTest(); // Import a question from XML. - $xml = file_get_contents(__DIR__ . '/fixtures/testimport.moodle.xml'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'testimport.moodle.xml')); $xmldata = xmlize($xml); $format = new qformat_xml(); $imported = $format->try_importing_using_qtypes( @@ -249,7 +249,7 @@ final class questiontype_test extends \question_testcase { public function test_xml_import_long(): void { $this->resetAfterTest(); // Import a question from XML. - $xml = file_get_contents(__DIR__ . '/fixtures/testimportlong.moodle.xml'); + $xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'testimportlong.moodle.xml')); $xmldata = xmlize($xml); $format = new qformat_xml(); $imported = $format->try_importing_using_qtypes( @@ -283,7 +283,7 @@ final class questiontype_test extends \question_testcase { $exporter = new qformat_xml(); $xml = $exporter->writequestion($questiondata); - $expectedxml = file_get_contents(__DIR__ . '/fixtures/testexport.moodle.xml'); + $expectedxml = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'testexport.moodle.xml')); $this->assert_same_xml($expectedxml, $xml); } @@ -291,7 +291,7 @@ final class questiontype_test extends \question_testcase { public function test_gift_import(): void { $this->resetAfterTest(); // Import a question from GIFT. - $gift = file_get_contents(__DIR__ . '/fixtures/testimport.gift.txt'); + $gift = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'testimport.gift.txt')); $format = new qformat_gift(); $lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift)); $imported = $format->readquestion($lines); @@ -314,7 +314,7 @@ final class questiontype_test extends \question_testcase { $exporter = new qformat_gift(); $gift = $exporter->writequestion($questiondata); - $expectedgift = file_get_contents(__DIR__ . '/fixtures/testexport.gift.txt'); + $expectedgift = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'testexport.gift.txt')); $this->assertEquals( phpunit_util::normalise_line_endings($expectedgift),