From 644c2af56aa107818cb454d8ef1f1b4f68aecb0a Mon Sep 17 00:00:00 2001 From: Peter Mayer Date: Fri, 4 Aug 2023 15:23:54 +0200 Subject: [PATCH] MBS-7802: Changes due to failing core unit tests --- classes/frontend.php | 26 ++++++++++++++++++-------- tests/condition_test.php | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/classes/frontend.php b/classes/frontend.php index ef2f268..7b0caae 100644 --- a/classes/frontend.php +++ b/classes/frontend.php @@ -67,10 +67,15 @@ protected function get_javascript_init_params($course, \cm_info $cm = null, \sec ]; } - $roles = explode(',', get_config('availability_role', 'coursecatroles')); - foreach ($roles as $rec) { - $rec = $DB->get_record('role', ['id' => $rec]); - if (empty($rec->id)) continue; + $roleids = explode(',', get_config('availability_role', 'coursecatroles')); + foreach ($roleids as $roleid) { + if(empty($roleid)){ + continue; + } + $rec = $DB->get_record('role', ['id' => $roleid]); + if (empty($rec->id)) { + continue; + } $jsarray[] = (object)[ 'id' => $rec->id, 'name' => (!empty($rec->name) ? $rec->name : $rec->shortname), @@ -79,10 +84,15 @@ protected function get_javascript_init_params($course, \cm_info $cm = null, \sec ]; } - $roles = explode(',', get_config('availability_role', 'globalroles')); - foreach ($roles as $rec) { - $rec = $DB->get_record('role', ['id' => $rec]); - if (empty($rec->id)) continue; + $roleids = explode(',', get_config('availability_role', 'globalroles')); + foreach ($roleids as $roleid) { + if (empty($roleid)) { + continue; + } + $rec = $DB->get_record('role', ['id' => $roleid]); + if (empty($rec->id)) { + continue; + } $jsarray[] = (object)[ 'id' => $rec->id, 'name' => (!empty($rec->name) ? $rec->name : $rec->shortname), diff --git a/tests/condition_test.php b/tests/condition_test.php index 7dfbdb2..95c154f 100644 --- a/tests/condition_test.php +++ b/tests/condition_test.php @@ -86,6 +86,7 @@ public function test_save() { $structure = (object)['id' => 123]; $cond = new condition($structure); $structure->type = 'role'; + $structure->typeid = 0; $this->assertEquals($structure, $cond->save()); } }