From dbf67c06bb5c69310676103c3239c50c7fcecedd Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Thu, 15 Sep 2022 20:25:14 +0800 Subject: [PATCH 1/3] MDL-75759 courseformat: Fix stateactions test * Require lib/externallib.php in \core_courseformat\output\local\state\cm::export_for_template() * Point @coversDefaultClass to the proper class. --- course/format/classes/output/local/state/cm.php | 4 +++- course/format/tests/stateactions_test.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/course/format/classes/output/local/state/cm.php b/course/format/classes/output/local/state/cm.php index de51e585a43..b602c0540e1 100644 --- a/course/format/classes/output/local/state/cm.php +++ b/course/format/classes/output/local/state/cm.php @@ -18,6 +18,7 @@ namespace core_courseformat\output\local\state; use core_courseformat\base as course_format; use completion_info; +use renderer_base; use section_info; use cm_info; use renderable; @@ -70,8 +71,9 @@ class cm implements renderable { * @param renderer_base $output typically, the renderer that's calling this function * @return stdClass data context for a mustache template */ - public function export_for_template(\renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass { global $USER, $CFG; + require_once($CFG->libdir . '/externallib.php'); $format = $this->format; $section = $this->section; diff --git a/course/format/tests/stateactions_test.php b/course/format/tests/stateactions_test.php index f89eda42c27..0850d7feb1c 100644 --- a/course/format/tests/stateactions_test.php +++ b/course/format/tests/stateactions_test.php @@ -26,7 +26,7 @@ use stdClass; * @category test * @copyright 2021 Sara Arjona (sara@moodle.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @coversDefaultClass \core_course\stateactions + * @coversDefaultClass \core_courseformat\stateactions */ class stateactions_test extends \advanced_testcase { From e43fef8fc97f54129837d170c9724640189caebc Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Tue, 1 Nov 2022 14:08:33 +0800 Subject: [PATCH 2/3] MDL-75759 courseformat: fix documentation of stateupdates tests --- .../format/classes/external/update_course.php | 6 +++--- course/format/classes/stateupdates.php | 2 +- course/format/tests/stateactions_test.php | 2 +- course/format/tests/stateupdates_test.php | 18 +++++++++--------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/course/format/classes/external/update_course.php b/course/format/classes/external/update_course.php index d14cee3ee4f..2fad991a264 100644 --- a/course/format/classes/external/update_course.php +++ b/course/format/classes/external/update_course.php @@ -72,14 +72,14 @@ class update_course extends external_api { /** * This webservice will execute any action from the course editor. The default actions - * are located in core_course\stateactions but the format plugin can extend that class + * are located in core_courseformat\stateactions but the format plugin can extend that class * in format_XXX\course. * - * The specific action methods will register in a core_course\stateupdates all the affected + * The specific action methods will register in a core_courseformat\stateupdates all the affected * sections, cms and course attribute. This object (in JSON) will be send back to the * frontend editor to refresh the updated state elements. * - * By default, core_course\stateupdates will register only create, delete and update events + * By default, core_courseformat\stateupdates will register only create, delete and update events * on cms, sections and the general course data. However, if some plugin needs adhoc messages for * its own mutation module, it extend this class in format_XXX\course. * diff --git a/course/format/classes/stateupdates.php b/course/format/classes/stateupdates.php index a1b095bf74c..de4d79918ee 100644 --- a/course/format/classes/stateupdates.php +++ b/course/format/classes/stateupdates.php @@ -31,7 +31,7 @@ use JsonSerializable; * Each format plugin could extend this class to provide new updates to the frontend * mutation module. * Extended classes should be locate in "format_XXX\course" namespace and - * extends core_course\stateupdates. + * extends core_courseformat\stateupdates. * * @package core_course * @copyright 2021 Ferran Recio diff --git a/course/format/tests/stateactions_test.php b/course/format/tests/stateactions_test.php index 0850d7feb1c..1fdf7b96cb0 100644 --- a/course/format/tests/stateactions_test.php +++ b/course/format/tests/stateactions_test.php @@ -22,7 +22,7 @@ use stdClass; /** * Tests for the stateactions class. * - * @package core_course + * @package core_courseformat * @category test * @copyright 2021 Sara Arjona (sara@moodle.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/course/format/tests/stateupdates_test.php b/course/format/tests/stateupdates_test.php index e15f6415363..714d123fadb 100644 --- a/course/format/tests/stateupdates_test.php +++ b/course/format/tests/stateupdates_test.php @@ -19,13 +19,13 @@ namespace core_courseformat; use stdClass; /** - * Tests for the stateactions class. + * Tests for the stateupdates class. * - * @package core_course + * @package core_courseformat * @category test * @copyright 2021 Sara Arjona (sara@moodle.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @coversDefaultClass \core_course\stateactions + * @coversDefaultClass \core_courseformat\stateupdates */ class stateupdates_test extends \advanced_testcase { @@ -128,9 +128,9 @@ class stateupdates_test extends \advanced_testcase { * Add track about a section state update. * * @dataProvider add_section_provider - * @covers ::add_course_put - * @covers ::add_course_create - * @covers ::add_course_delete + * @covers ::add_section_create + * @covers ::add_section_remove + * @covers ::add_section_put * * @param string $action the action name * @param string $role the user role name @@ -242,10 +242,10 @@ class stateupdates_test extends \advanced_testcase { /** - * Add track about a section state update. + * Add track about a course module state update. * * @dataProvider add_cm_provider - * @covers ::add_cm_update + * @covers ::add_cm_put * @covers ::add_cm_create * @covers ::add_cm_remove * @@ -339,7 +339,7 @@ class stateupdates_test extends \advanced_testcase { } /** - * Data provider for test_add_section. + * Data provider for test_add_cm. * * @return array testing scenarios */ From a343faaa7d2da5d740c1f7d3a7d2aca89d270a7b Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Thu, 3 Nov 2022 11:55:42 +0800 Subject: [PATCH 3/3] MDL-75759 courseformat: Link classes in PHPDocs with @see tags - Linking classes/methods mentioned in PHPDoc with @see tags help devs checking the PHPDoc to quickly navigate to the class/method mentioned and also helps us ensure that it points to the correct class/method. - Some typo/grammar fixes as well in existing PHPDoc descriptions. - Fixed parameter type in execute()'s PHPDoc block. --- course/format/classes/external/update_course.php | 14 +++++++------- course/format/classes/stateupdates.php | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/course/format/classes/external/update_course.php b/course/format/classes/external/update_course.php index 2fad991a264..870ea6985ad 100644 --- a/course/format/classes/external/update_course.php +++ b/course/format/classes/external/update_course.php @@ -72,22 +72,22 @@ class update_course extends external_api { /** * This webservice will execute any action from the course editor. The default actions - * are located in core_courseformat\stateactions but the format plugin can extend that class + * are located in {@see \core_courseformat\stateactions} but the format plugin can extend that class * in format_XXX\course. * - * The specific action methods will register in a core_courseformat\stateupdates all the affected - * sections, cms and course attribute. This object (in JSON) will be send back to the + * The specific action methods will register in a {@see \core_courseformat\stateupdates} all the affected + * sections, cms and course attribute. This object (in JSON) will be sent back to the * frontend editor to refresh the updated state elements. * - * By default, core_courseformat\stateupdates will register only create, delete and update events + * By default, {@see \core_courseformat\stateupdates} will register only create, delete and update events * on cms, sections and the general course data. However, if some plugin needs adhoc messages for - * its own mutation module, it extend this class in format_XXX\course. + * its own mutation module, extend this class in format_XXX\course. * * @param string $action the action name to execute * @param int $courseid the course id * @param int[] $ids the affected ids (section or cm depending on the action) - * @param int $targetsectionid optional target section id (for move action) - * @param int $targetcmid optional target cm id (for move action) + * @param int|null $targetsectionid optional target section id (for move action) + * @param int|null $targetcmid optional target cm id (for move action) * @return string Course state in JSON */ public static function execute(string $action, int $courseid, array $ids = [], diff --git a/course/format/classes/stateupdates.php b/course/format/classes/stateupdates.php index de4d79918ee..eb2bfe2acb9 100644 --- a/course/format/classes/stateupdates.php +++ b/course/format/classes/stateupdates.php @@ -30,8 +30,8 @@ use JsonSerializable; * * Each format plugin could extend this class to provide new updates to the frontend * mutation module. - * Extended classes should be locate in "format_XXX\course" namespace and - * extends core_courseformat\stateupdates. + * Extended classes should be located in "format_XXX\course" namespace and + * extends {@see \core_courseformat\stateupdates}. * * @package core_course * @copyright 2021 Ferran Recio