diff --git a/.github/workflows/moodle-plugin-ci.yml b/.github/workflows/moodle-plugin-ci.yml index 5aebd95e7..7d67179eb 100644 --- a/.github/workflows/moodle-plugin-ci.yml +++ b/.github/workflows/moodle-plugin-ci.yml @@ -8,7 +8,7 @@ jobs: services: postgres: - image: postgres:13 + image: postgres:14 env: POSTGRES_USER: 'postgres' POSTGRES_HOST_AUTH_METHOD: 'trust' @@ -31,7 +31,7 @@ jobs: fail-fast: false matrix: php: ['8.1', '8.2', '8.3'] - moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE', 'MOODLE_405_STABLE'] + moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE', 'MOODLE_405_STABLE', 'MOODLE_500_STABLE'] database: [pgsql, mariadb] exclude: - php: '8.2' @@ -42,6 +42,8 @@ jobs: moodle-branch: 'MOODLE_402_STABLE' - php: '8.3' moodle-branch: 'MOODLE_403_STABLE' + - php: '8.1' + moodle-branch: 'MOODLE_500_STABLE' steps: - name: Check out repository code diff --git a/src/transformer/repos/Repository.php b/src/transformer/repos/Repository.php index 1bc0364c5..746aeee56 100644 --- a/src/transformer/repos/Repository.php +++ b/src/transformer/repos/Repository.php @@ -49,7 +49,7 @@ abstract public function read_records(string $type, array $query, string $sort = */ public function read_record(string $type, array $query) { $records = $this->read_records($type, $query); - $record = $records[0]; + $record = $records[0] ?? null; if (!$record) { throw new \Exception("$type not found."); } diff --git a/tests/core/badge_revoked/user_forfeited_badge/user_forfeited_badge_test.php b/tests/core/badge_revoked/user_forfeited_badge/user_forfeited_badge_test.php index 86c328eeb..70509741c 100644 --- a/tests/core/badge_revoked/user_forfeited_badge/user_forfeited_badge_test.php +++ b/tests/core/badge_revoked/user_forfeited_badge/user_forfeited_badge_test.php @@ -23,13 +23,13 @@ require_once($CFG->dirroot . '/admin/tool/log/store/xapi/tests/xapi_test_case.php'); /** - * Unit test for mod_quiz attempt submitted (multichoice set with choices) event. + * Unit test for user forfeited badge event. * * @package logstore_xapi * @copyright Daniel Bell * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class user_achieved_badge_test extends \logstore_xapi\xapi_test_case { +class user_forfeited_badge_test extends \logstore_xapi\xapi_test_case { /** * Retrieve the directory of the unit test. @@ -48,7 +48,7 @@ protected function get_test_dir() { protected function get_plugin_type() { return "core"; } - + /** * Retrieve the plugin name being tested. * diff --git a/tests/core/course_resources_list_viewed/existing_course_resources_list_viewed/existing_course_resources_list_viewed_test.php b/tests/core/course_resources_list_viewed/existing_course_resources_list_viewed/existing_course_resources_list_viewed_test.php index be72fc474..d7b66a67b 100644 --- a/tests/core/course_resources_list_viewed/existing_course_resources_list_viewed/existing_course_resources_list_viewed_test.php +++ b/tests/core/course_resources_list_viewed/existing_course_resources_list_viewed/existing_course_resources_list_viewed_test.php @@ -29,7 +29,7 @@ * @copyright Milt Reder * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class existing_course_resource_list_viewed extends \logstore_xapi\xapi_test_case { +class existing_course_resources_list_viewed_test extends \logstore_xapi\xapi_test_case { /** * Retrieve the directory of the unit test. diff --git a/tests/mod_feedback/response_submitted/textarea_anon/textarea_test.php b/tests/mod_feedback/response_submitted/textarea_anon/textarea_anon_test.php similarity index 100% rename from tests/mod_feedback/response_submitted/textarea_anon/textarea_test.php rename to tests/mod_feedback/response_submitted/textarea_anon/textarea_anon_test.php diff --git a/tests/mod_lesson/essay_assessed/essay_assessed_test.php b/tests/mod_lesson/essay_assessed/essay_assessed_test.php index 9b1ab8531..9b16222be 100644 --- a/tests/mod_lesson/essay_assessed/essay_assessed_test.php +++ b/tests/mod_lesson/essay_assessed/essay_assessed_test.php @@ -31,47 +31,60 @@ */ class essay_assessed_test extends \logstore_xapi\xapi_test_case { - /** - * Retrieve the directory of the unit test. - * - * @return string - */ - protected function get_test_dir() { - return __DIR__; - } + public function setUp(): void { + parent::setUp(); - /** - * Retrieve the plugin type being tested. - * - * @return string - */ - protected function get_plugin_type() { - return "mod"; + if (!defined('LESSON_PAGE_SHORTANSWER')) { + define('LESSON_PAGE_SHORTANSWER', 1); + define('LESSON_PAGE_ESSAY', 10); + define('LESSON_PAGE_TRUEFALSE', 2); + define('LESSON_PAGE_MULTICHOICE', 3); + define('LESSON_PAGE_MATCHING', 5); + define('LESSON_PAGE_NUMERICAL', 8); } + } - /** - * Retrieve the plugin name being tested. - * - * @return string - */ - protected function get_plugin_name() { - return "glossary"; - } + /** + * Retrieve the directory of the unit test. + * + * @return string + */ + protected function get_test_dir() { + return __DIR__; + } + + /** + * Retrieve the plugin type being tested. + * + * @return string + */ + protected function get_plugin_type() { + return "mod"; + } + + /** + * Retrieve the plugin name being tested. + * + * @return string + */ + protected function get_plugin_name() { + return "glossary"; + } - /** - * Appease auto-detecting of test cases. xapi_test_case has default test cases. - * - * @covers ::essay_assessed - * @return void - */ - public function test_init() { - if (!defined('LESSON_PAGE_SHORTANSWER')) { - define('LESSON_PAGE_SHORTANSWER', 1); - define('LESSON_PAGE_ESSAY', 10); - define('LESSON_PAGE_TRUEFALSE', 2); - define('LESSON_PAGE_MULTICHOICE', 3); - define('LESSON_PAGE_MATCHING', 5); - define('LESSON_PAGE_NUMERICAL', 8); - } + /** + * Appease auto-detecting of test cases. xapi_test_case has default test cases. + * + * @covers ::essay_assessed + * @return void + */ + public function test_init() { + if (!defined('LESSON_PAGE_SHORTANSWER')) { + define('LESSON_PAGE_SHORTANSWER', 1); + define('LESSON_PAGE_ESSAY', 10); + define('LESSON_PAGE_TRUEFALSE', 2); + define('LESSON_PAGE_MULTICHOICE', 3); + define('LESSON_PAGE_MATCHING', 5); + define('LESSON_PAGE_NUMERICAL', 8); } + } } diff --git a/tests/mod_survey/course_module_viewed/existing_module/existing_module_test.php b/tests/mod_survey/course_module_viewed/existing_module/existing_module_test.php index 73184bfa9..87c739099 100644 --- a/tests/mod_survey/course_module_viewed/existing_module/existing_module_test.php +++ b/tests/mod_survey/course_module_viewed/existing_module/existing_module_test.php @@ -33,40 +33,55 @@ */ class existing_module_test extends \logstore_xapi\xapi_test_case { - /** - * Retrieve the directory of the unit test. - * - * @return string - */ - protected function get_test_dir() { - return __DIR__; - } + /** + * Initialize, skipping if mod_survey is not present. + * + * @return void + */ + public function setUp(): void { + global $CFG; + parent::setUp(); - /** - * Retrieve the plugin type being tested. - * - * @return string - */ - protected function get_plugin_type() { - return "mod"; + // Skip tests if mod_survey is not present (i.e., Moodle 5.0+). + if (!is_dir($CFG->dirroot . '/mod/survey')) { + $this->markTestSkipped('mod_survey is not available in Moodle 5.0 and above.'); } + } - /** - * Retrieve the plugin name being tested. - * - * @return string - */ - protected function get_plugin_name() { - return "survey"; - } + /** + * Retrieve the directory of the unit test. + * + * @return string + */ + protected function get_test_dir() { + return __DIR__; + } - /** - * Appease auto-detecting of test cases. xapi_test_case has default test cases. - * - * @covers ::course_module_viewed - * @return void - */ - public function test_init() { + /** + * Retrieve the plugin type being tested. + * + * @return string + */ + protected function get_plugin_type() { + return "mod"; + } - } + /** + * Retrieve the plugin name being tested. + * + * @return string + */ + protected function get_plugin_name() { + return "survey"; + } + + /** + * Appease auto-detecting of test cases. xapi_test_case has default test cases. + * + * @covers ::course_module_viewed + * @return void + */ + public function test_init() { + + } } diff --git a/tests/mod_survey/report_viewed/report_viewed_test.php b/tests/mod_survey/report_viewed/report_viewed_test.php index a4c79c59f..26ba0d314 100644 --- a/tests/mod_survey/report_viewed/report_viewed_test.php +++ b/tests/mod_survey/report_viewed/report_viewed_test.php @@ -31,40 +31,55 @@ */ class report_viewed_test extends \logstore_xapi\xapi_test_case { - /** - * Retrieve the directory of the unit test. - * - * @return string - */ - protected function get_test_dir() { - return __DIR__; - } + /** + * Initialize, skipping if mod_survey is not present. + * + * @return void + */ + public function setUp(): void { + global $CFG; + parent::setUp(); - /** - * Retrieve the plugin type being tested. - * - * @return string - */ - protected function get_plugin_type() { - return "core"; + // Skip tests if mod_survey is not present (i.e., Moodle 5.0+). + if (!is_dir($CFG->dirroot . '/mod/survey')) { + $this->markTestSkipped('mod_survey is not available in Moodle 5.0 and above.'); } + } - /** - * Retrieve the plugin name being tested. - * - * @return string - */ - protected function get_plugin_name() { - return "mod_survey"; - } + /** + * Retrieve the directory of the unit test. + * + * @return string + */ + protected function get_test_dir() { + return __DIR__; + } - /** - * Appease auto-detecting of test cases. xapi_test_case has default test cases. - * - * @covers ::report_viewed - * @return void - */ - public function test_init() { + /** + * Retrieve the plugin type being tested. + * + * @return string + */ + protected function get_plugin_type() { + return "core"; + } - } + /** + * Retrieve the plugin name being tested. + * + * @return string + */ + protected function get_plugin_name() { + return "mod_survey"; + } + + /** + * Appease auto-detecting of test cases. xapi_test_case has default test cases. + * + * @covers ::report_viewed + * @return void + */ + public function test_init() { + + } } diff --git a/tests/mod_survey/response_submitted/response_submitted_test.php b/tests/mod_survey/response_submitted/response_submitted_test.php index be0f1a9e3..ae9ad53c1 100644 --- a/tests/mod_survey/response_submitted/response_submitted_test.php +++ b/tests/mod_survey/response_submitted/response_submitted_test.php @@ -31,40 +31,55 @@ */ class response_submitted_test extends \logstore_xapi\xapi_test_case { - /** - * Retrieve the directory of the unit test. - * - * @return string - */ - protected function get_test_dir() { - return __DIR__; - } + /** + * Initialize, skipping if mod_survey is not present. + * + * @return void + */ + public function setUp(): void { + global $CFG; + parent::setUp(); - /** - * Retrieve the plugin type being tested. - * - * @return string - */ - protected function get_plugin_type() { - return "core"; + // Skip tests if mod_survey is not present (i.e., Moodle 5.0+). + if (!is_dir($CFG->dirroot . '/mod/survey')) { + $this->markTestSkipped('mod_survey is not available in Moodle 5.0 and above.'); } + } - /** - * Retrieve the plugin name being tested. - * - * @return string - */ - protected function get_plugin_name() { - return "mod_survey"; - } + /** + * Retrieve the directory of the unit test. + * + * @return string + */ + protected function get_test_dir() { + return __DIR__; + } - /** - * Appease auto-detecting of test cases. xapi_test_case has default test cases. - * - * @covers ::response_submitted - * @return void - */ - public function test_init() { + /** + * Retrieve the plugin type being tested. + * + * @return string + */ + protected function get_plugin_type() { + return "core"; + } - } + /** + * Retrieve the plugin name being tested. + * + * @return string + */ + protected function get_plugin_name() { + return "mod_survey"; + } + + /** + * Appease auto-detecting of test cases. xapi_test_case has default test cases. + * + * @covers ::response_submitted + * @return void + */ + public function test_init() { + + } }