From ef583b2ad3283d882a81230648f27a655523d20c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Fri, 30 Jun 2023 15:41:50 +0200 Subject: [PATCH 1/4] MDL-78280 pix: Add dot icon --- pix/i/dot.png | Bin 0 -> 204 bytes pix/i/dot.svg | 3 +++ 2 files changed, 3 insertions(+) create mode 100644 pix/i/dot.png create mode 100644 pix/i/dot.svg diff --git a/pix/i/dot.png b/pix/i/dot.png new file mode 100644 index 0000000000000000000000000000000000000000..ef1fc4e57a769fce2027118fbac4f31249e0335d GIT binary patch literal 204 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP>``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eBexj#~V@L(#+n$ZQ4F)_c|7SJ`-e~V?n + + From 96d6b3675fd092891ca9f575bab7efb8be995b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Mon, 3 Jul 2023 09:15:55 +0200 Subject: [PATCH 2/4] MDL-78280 completion: Add is_manual() method to cm_completion_details --- completion/classes/cm_completion_details.php | 13 +++++++ .../tests/cm_completion_details_test.php | 39 +++++++++++++++++++ completion/upgrade.txt | 3 ++ 3 files changed, 55 insertions(+) diff --git a/completion/classes/cm_completion_details.php b/completion/classes/cm_completion_details.php index 79004fb7da9..e80a1182266 100644 --- a/completion/classes/cm_completion_details.php +++ b/completion/classes/cm_completion_details.php @@ -222,6 +222,15 @@ class cm_completion_details { return $this->cminfo->completion == COMPLETION_TRACKING_AUTOMATIC; } + /** + * Whether this activity module instance tracks completion manually. + * + * @return bool + */ + public function is_manual(): bool { + return $this->cminfo->completion == COMPLETION_TRACKING_MANUAL; + } + /** * Fetches the user ID that has overridden the completion state of this activity for the user. * @@ -248,6 +257,10 @@ class cm_completion_details { public function show_manual_completion(): bool { global $PAGE; + if (!$this->is_manual()) { + return false; + } + if ($PAGE->context->contextlevel == CONTEXT_MODULE) { // Manual completion should always be shown on the activity page. return true; diff --git a/completion/tests/cm_completion_details_test.php b/completion/tests/cm_completion_details_test.php index 00d660a110d..b4379877a85 100644 --- a/completion/tests/cm_completion_details_test.php +++ b/completion/tests/cm_completion_details_test.php @@ -41,6 +41,7 @@ require_once($CFG->libdir . '/completionlib.php'); * @package core_completion * @copyright 2021 Jun Pataleta * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @coversDefaultClass \core_completion\cm_completion_details */ class cm_completion_details_test extends advanced_testcase { @@ -121,6 +122,7 @@ class cm_completion_details_test extends advanced_testcase { /** * Test for has_completion(). * + * @covers ::has_completion * @dataProvider has_completion_provider * @param int $completion The completion tracking mode. * @param bool $expectedresult Expected result. @@ -153,6 +155,7 @@ class cm_completion_details_test extends advanced_testcase { /** * Test for is_available(). * + * @covers ::is_automatic * @dataProvider is_automatic_provider * @param int $completion The completion tracking mode. * @param bool $expectedresult Expected result. @@ -163,6 +166,39 @@ class cm_completion_details_test extends advanced_testcase { $this->assertEquals($expectedresult, $cmcompletion->is_automatic()); } + /** + * Provides data for test_is_manual(). + * + * @return array[] + */ + public function is_manual_provider(): array { + return [ + 'Automatic' => [ + COMPLETION_TRACKING_AUTOMATIC, false + ], + 'Manual' => [ + COMPLETION_TRACKING_MANUAL, true + ], + 'None' => [ + COMPLETION_TRACKING_NONE, false + ], + ]; + } + + /** + * Test for is_manual(). + * + * @covers ::is_manual + * @dataProvider is_manual_provider + * @param int $completion The completion tracking mode. + * @param bool $expectedresult Expected result. + */ + public function test_is_manual(int $completion, bool $expectedresult) { + $cmcompletion = $this->setup_data($completion); + + $this->assertEquals($expectedresult, $cmcompletion->is_manual()); + } + /** * Data provider for test_get_overall_completion(). * @return array[] @@ -177,6 +213,7 @@ class cm_completion_details_test extends advanced_testcase { /** * Test for get_overall_completion(). * + * @covers ::get_overall_completion * @dataProvider overall_completion_provider * @param int $state */ @@ -316,6 +353,7 @@ class cm_completion_details_test extends advanced_testcase { /** * Test for \core_completion\cm_completion_details::get_details(). * + * @covers ::get_details * @dataProvider get_details_provider * @param int $completion The completion tracking mode. * @param int|null $completionview Completion status of the "view" completion condition. @@ -415,6 +453,7 @@ class cm_completion_details_test extends advanced_testcase { /** * Test custom sort order is functioning in \core_completion\cm_completion_details::get_details(). * + * @covers ::get_details * @dataProvider get_details_custom_order_provider * @param bool $completionview Completion status of the "view" completion condition. * @param bool $completiongrade Completion status of the "must receive grade" completion condition. diff --git a/completion/upgrade.txt b/completion/upgrade.txt index 52a90662f6d..53b96685cd5 100644 --- a/completion/upgrade.txt +++ b/completion/upgrade.txt @@ -1,6 +1,9 @@ This files describes API changes in /completion/* - completion, information provided here is intended especially for developers. +=== 4.3 === +* New method is_manual() has been added to `core_completion/cm_completion_details` + === 4.0 === * New method mark_course_completions_activity_criteria() has been added to mark course completions instantly. It is based on cron for completion_criteria_activity.php which is refactored to use it as well. From e5908a1ce4485ecfd3bd6117a2cb1ef606526619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Mon, 3 Jul 2023 09:58:29 +0200 Subject: [PATCH 3/4] MDL-78280 core_courseformat: New completion dropdown UI - Move completion information to a new output class 'core_courseformat\output\local\content\cm\completion' - Replace current dropdown with 'core\output\local\dropdown\dialog' - Modify manual conditions logic in course page. Now 'Mark as done' button will only be displayed to tracked users (with moodle/course:isincompletionreports capability) - Add new styles for completion dialog contents --- .../classes/output/activity_information.php | 1 + .../classes/output/local/content/cm.php | 40 ++---- .../output/local/content/cm/completion.php | 120 ++++++++++++++++++ .../local/content/cm/activity_info.mustache | 49 +++---- .../content/cm/completion_dialog.mustache | 96 ++++++++++++++ .../templates/completion_automatic.mustache | 16 +-- lang/en/completion.php | 2 + theme/boost/scss/moodle/course.scss | 11 ++ theme/boost/style/moodle.css | 11 ++ theme/classic/style/moodle.css | 11 ++ 10 files changed, 287 insertions(+), 70 deletions(-) create mode 100644 course/format/classes/output/local/content/cm/completion.php create mode 100644 course/format/templates/local/content/cm/completion_dialog.mustache diff --git a/course/classes/output/activity_information.php b/course/classes/output/activity_information.php index c28253d594f..18b456b93e5 100644 --- a/course/classes/output/activity_information.php +++ b/course/classes/output/activity_information.php @@ -121,6 +121,7 @@ class activity_information implements renderable, templatable { $data->hascompletion = $this->cmcompletion->has_completion(); $data->isautomatic = $this->cmcompletion->is_automatic(); + $data->ismanual = $this->cmcompletion->is_manual(); $data->showmanualcompletion = $this->cmcompletion->show_manual_completion(); // Get the name of the user overriding the completion condition, if available. diff --git a/course/format/classes/output/local/content/cm.php b/course/format/classes/output/local/content/cm.php index 2dff8d8a455..e9ee75ccbf8 100644 --- a/course/format/classes/output/local/content/cm.php +++ b/course/format/classes/output/local/content/cm.php @@ -25,13 +25,9 @@ namespace core_courseformat\output\local\content; use cm_info; -use core\activity_dates; use core\output\named_templatable; use core_availability\info_module; -use core_completion\cm_completion_details; -use core_course\output\activity_information; use core_courseformat\base as course_format; -use core_courseformat\output\activitybadge; use core_courseformat\output\local\courseformat_named_templatable; use renderable; use renderer_base; @@ -69,6 +65,9 @@ class cm implements named_templatable, renderable { /** @var string the activity availability class name */ protected $availabilityclass; + /** @var string the activity completion class name */ + protected $completionclass; + /** * Constructor. * @@ -90,6 +89,7 @@ class cm implements named_templatable, renderable { $this->cmnameclass = $format->get_output_classname('content\\cm\\cmname'); $this->controlmenuclass = $format->get_output_classname('content\\cm\\controlmenu'); $this->availabilityclass = $format->get_output_classname('content\\cm\\availability'); + $this->completionclass = $format->get_output_classname('content\\cm\\completion'); } /** @@ -205,33 +205,13 @@ class cm implements named_templatable, renderable { * @return bool the module has completion information */ protected function add_completion_data(stdClass &$data, renderer_base $output): bool { - global $USER; - $course = $this->mod->get_course(); - // Fetch completion details. - $showcompletionconditions = $course->showcompletionconditions == COMPLETION_SHOW_CONDITIONS; - $completiondetails = cm_completion_details::get_instance($this->mod, $USER->id, $showcompletionconditions); - - // Fetch activity dates. - $activitydates = []; - if ($course->showactivitydates) { - $activitydates = activity_dates::get_dates_for_module($this->mod, $USER->id); + $completion = new $this->completionclass($this->format, $this->section, $this->mod); + $templatedata = $completion->export_for_template($output); + if ($templatedata) { + $data->activityinfo = $templatedata; + return true; } - - $activityinfodata = (object) ['hasdates' => false, 'hascompletion' => false]; - // There are activity dates to be shown; or - // Completion info needs to be displayed - // * The activity tracks completion; AND - // * The showcompletionconditions setting is enabled OR an activity that tracks manual - // completion needs the manual completion button to be displayed on the course homepage. - $showcompletioninfo = $completiondetails->has_completion() && ($showcompletionconditions || - (!$completiondetails->is_automatic() && $completiondetails->show_manual_completion())); - if ($showcompletioninfo || !empty($activitydates)) { - $activityinfo = new activity_information($this->mod, $completiondetails, $activitydates); - $activityinfodata = $activityinfo->export_for_template($output); - } - - $data->activityinfo = $activityinfodata; - return $activityinfodata->hascompletion; + return false; } /** diff --git a/course/format/classes/output/local/content/cm/completion.php b/course/format/classes/output/local/content/cm/completion.php new file mode 100644 index 00000000000..999452f894e --- /dev/null +++ b/course/format/classes/output/local/content/cm/completion.php @@ -0,0 +1,120 @@ +. + +namespace core_courseformat\output\local\content\cm; + +use cm_info; +use section_info; +use renderable; +use stdClass; +use core\activity_dates; +use core\output\named_templatable; +use core\output\local\dropdown\dialog as dropdown_dialog; +use core_completion\cm_completion_details; +use core_course\output\activity_information; +use core_courseformat\base as course_format; +use core_courseformat\output\local\courseformat_named_templatable; + +/** + * Base class to render course module completion. + * + * @package core_courseformat + * @copyright 2023 Mikel Martin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class completion implements named_templatable, renderable { + + use courseformat_named_templatable; + + /** + * Constructor. + * + * @param course_format $format the course format + * @param section_info $section the section info + * @param cm_info $mod the course module ionfo + */ + public function __construct( + protected course_format $format, + protected section_info $section, + protected cm_info $mod, + ) { + } + + /** + * Export this data so it can be used as the context for a mustache template. + * + * @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 { + global $USER; + + $course = $this->mod->get_course(); + + $showcompletionconditions = $course->showcompletionconditions == COMPLETION_SHOW_CONDITIONS; + $completiondetails = cm_completion_details::get_instance($this->mod, $USER->id, $showcompletionconditions); + + $activitydates = []; + if ($course->showactivitydates) { + $activitydates = activity_dates::get_dates_for_module($this->mod, $USER->id); + } + + // There are activity dates to be shown; or + // Completion info needs to be displayed + // * The activity tracks completion; AND + // * The showcompletionconditions setting is enabled OR an activity that tracks manual + // completion needs the manual completion button to be displayed on the course homepage. + $showcompletioninfo = $completiondetails->has_completion() && ($showcompletionconditions || + (!$completiondetails->is_automatic() && $completiondetails->show_manual_completion())); + if (!$showcompletioninfo && empty($activitydates)) { + return null; + } + + $activityinfodata = (object) [ 'hasdates' => false, 'hascompletion' => false ]; + $activityinfo = new activity_information($this->mod, $completiondetails, $activitydates); + $activityinfodata = $activityinfo->export_for_template($output); + + if ($activityinfodata->isautomatic || ($activityinfodata->ismanual && !$activityinfodata->istrackeduser)) { + $activityinfodata->completiondialog = $this->get_completion_dialog($output, $activityinfodata); + } + + return $activityinfodata; + } + + /** + * Get the completion dialog. + * + * @param \renderer_base $output typically, the renderer that's calling this function + * @param stdClass $completioninfo the completion info + * @return array the completion dialog exported for template + */ + private function get_completion_dialog(\renderer_base $output, stdClass $completioninfo): array { + if ($completioninfo->istrackeduser) { + $buttoncontent = get_string('todo', 'completion'); + } else { + $buttoncontent = get_string('completionmenuitem', 'completion'); + } + $content = $output->render_from_template('core_courseformat/local/content/cm/completion_dialog', $completioninfo); + + $completiondialog = new dropdown_dialog($buttoncontent, $content, [ + 'classes' => 'completion-dropdown', + 'buttonclasses' => 'btn btn-sm btn-outline-secondary dropdown-toggle', + 'dropdownposition' => dropdown_dialog::POSITION['end'], + ]); + + return $completiondialog->export_for_template($output); + } +} diff --git a/course/format/templates/local/content/cm/activity_info.mustache b/course/format/templates/local/content/cm/activity_info.mustache index 3983056dd82..e355cc6bd56 100644 --- a/course/format/templates/local/content/cm/activity_info.mustache +++ b/course/format/templates/local/content/cm/activity_info.mustache @@ -27,6 +27,12 @@ "activityname": "Course announcements", "hascompletion": true, "uservisible": true, + "completiondialog": { + "buttoncontent": "To do", + "dialogcontent": "You must view this activity to complete it.", + "buttonclasses": "btn btn-sm btn-outline-secondary dropdown-toggle", + "classes": "completion-dropdown" + }, "isautomatic": true, "showmanualcompletion": true, "completiondetails": [ @@ -44,42 +50,21 @@
{{#uservisible}}
- {{#isautomatic}} -
- + {{! Completion dropdown dialog }} + {{#completiondialog}} +
+ {{> core/local/dropdown/dialog }}
- {{/isautomatic}} - {{^isautomatic}} - {{#showmanualcompletion}} + {{/completiondialog}} + + {{! Manual completion button }} + {{#showmanualcompletion}} + {{#istrackeduser}} {{$ core_course/completion_manual }} {{> core_course/completion_manual }} {{/ core_course/completion_manual }} - {{/showmanualcompletion}} - {{/isautomatic}} + {{/istrackeduser}} + {{/showmanualcompletion}}
{{/uservisible}}
diff --git a/course/format/templates/local/content/cm/completion_dialog.mustache b/course/format/templates/local/content/cm/completion_dialog.mustache new file mode 100644 index 00000000000..f59edfe4804 --- /dev/null +++ b/course/format/templates/local/content/cm/completion_dialog.mustache @@ -0,0 +1,96 @@ +{{! + This file is part of Moodle - http://moodle.org/ + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template core_courseformat/local/content/cm/completion_dialog + + Container to display activity completion dialog content. + + Example context (json): + { + "istrackeduser": true, + "completiondetails": [ + { + "statuscomplete": 1, + "description": "View" + }, + { + "statusincomplete": 1, + "description": "Receive a grade" + } + ] + } +}} +
+ {{! Dialog header. }} + {{#istrackeduser}} + {{#str}}youmust, completion{{/str}} + {{/istrackeduser}} + {{^istrackeduser}} + {{#str}}studentsmust, completion{{/str}} + {{/istrackeduser}} + + {{! Completion criterias.}} +
+ {{#completiondetails}} + {{! Show completion status and description to tracked users. }} + {{#istrackeduser}} + {{#statuscomplete}} +
+
+ {{#pix}}i/checked{{/pix}} + {{#str}}completion_automatic:done, core_course{{/str}} +
+ {{description}} +
+ {{/statuscomplete}} + {{#statuscompletefail}} +
+
+ {{#pix}}e/cancel{{/pix}} + {{#str}}completion_automatic:failed, core_course{{/str}} +
+ {{description}} +
+ {{/statuscompletefail}} + {{#statusincomplete}} +
+
+ {{#pix}}i/dot{{/pix}} + {{#str}}completion_automatic:todo, core_course{{/str}} +
+ {{description}} +
+ {{/statusincomplete}} + {{/istrackeduser}} + + {{! Show only description (without status) to non-tracked users. }} + {{^istrackeduser}} +
+
{{#pix}}i/dot{{/pix}}
+ {{description}} +
+ {{/istrackeduser}} + {{/completiondetails}} + + {{! Show also manual completion description in the list to non-tracked users. }} + {{#ismanual}} + {{^istrackeduser}} +
+
{{#pix}}i/dot{{/pix}}
+ {{#str}} completion_manual:markdone, core_course {{/str}} +
+ {{/istrackeduser}} + {{/ismanual}} +
+
diff --git a/course/templates/completion_automatic.mustache b/course/templates/completion_automatic.mustache index 96dfaae5e55..d2cb4fd2588 100644 --- a/course/templates/completion_automatic.mustache +++ b/course/templates/completion_automatic.mustache @@ -29,37 +29,37 @@ }} {{#istrackeduser}} {{#statuscomplete}} - {{#pix}}i/checked{{/pix}} {{#str}}completion_automatic:done, core_course{{/str}} {{description}} - +
{{/statuscomplete}} {{#statuscompletefail}} - {{#pix}}e/cancel{{/pix}} {{#str}}completion_automatic:failed, core_course{{/str}} {{description}} - + {{/statuscompletefail}} {{#statusincomplete}} - {{#str}}completion_automatic:todo, core_course{{/str}} {{description}} - + {{/statusincomplete}} {{/istrackeduser}} {{^istrackeduser}} - +
{{description}} - +
{{/istrackeduser}} diff --git a/lang/en/completion.php b/lang/en/completion.php index 5343502d685..bd2155400aa 100644 --- a/lang/en/completion.php +++ b/lang/en/completion.php @@ -235,6 +235,7 @@ $string['selfcompletion'] = 'Self completion'; $string['showcompletionconditions'] = 'Show activity completion conditions'; $string['showcompletionconditions_help'] = 'Activity completion conditions are always shown on the activity page. This setting determines whether activity completion conditions are also shown below each activity on the course page.'; $string['showinguser'] = 'Showing user'; +$string['studentsmust'] = 'Students must'; $string['timecompleted'] = 'Time completed'; $string['todo'] = 'To do'; $string['unenrolingfromcourse'] = 'Unenrolling from course'; @@ -250,6 +251,7 @@ $string['viewingactivity'] = 'Viewing the {$a}'; $string['withconditions'] = 'With conditions'; $string['writingcompletiondata'] = 'Writing completion data'; $string['xdays'] = '{$a} days'; +$string['youmust'] = 'You must'; // Deprecated since Moodle 4.0. $string['yourprogress'] = 'Your progress'; diff --git a/theme/boost/scss/moodle/course.scss b/theme/boost/scss/moodle/course.scss index eeda48b282a..388a374a709 100644 --- a/theme/boost/scss/moodle/course.scss +++ b/theme/boost/scss/moodle/course.scss @@ -1575,6 +1575,17 @@ $activity-add-hover: theme-color-level('primary', -10) !default; width: 100%; } } + .completion-dialog { + color: $gray-700; + font-size: $font-size-sm; + min-width: 12rem; + .icon { + font-size: $font-size-sm; + width: $font-size-sm; + height: $font-size-sm; + margin-right: map-get($spacers, 1); + } + } } .activity-groupmode-info { diff --git a/theme/boost/style/moodle.css b/theme/boost/style/moodle.css index 9cc7cadda0f..7746a9b2518 100644 --- a/theme/boost/style/moodle.css +++ b/theme/boost/style/moodle.css @@ -29183,6 +29183,17 @@ span.editinstructions .alert-link { width: 100%; } } +.activity-item .activity-info .completion-dialog { + color: #495057; + font-size: 0.8203125rem; + min-width: 12rem; +} +.activity-item .activity-info .completion-dialog .icon { + font-size: 0.8203125rem; + width: 0.8203125rem; + height: 0.8203125rem; + margin-right: 0.25rem; +} .activity-item .activity-groupmode-info { grid-area: groupmode; justify-self: end; diff --git a/theme/classic/style/moodle.css b/theme/classic/style/moodle.css index 188ecac4098..ca7819073b4 100644 --- a/theme/classic/style/moodle.css +++ b/theme/classic/style/moodle.css @@ -29183,6 +29183,17 @@ span.editinstructions .alert-link { width: 100%; } } +.activity-item .activity-info .completion-dialog { + color: #495057; + font-size: 0.8203125rem; + min-width: 12rem; +} +.activity-item .activity-info .completion-dialog .icon { + font-size: 0.8203125rem; + width: 0.8203125rem; + height: 0.8203125rem; + margin-right: 0.25rem; +} .activity-item .activity-groupmode-info { grid-area: groupmode; justify-self: end; From 530691b1ca31561081a3d178df5ce45fb27d395f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Mon, 3 Jul 2023 15:21:37 +0200 Subject: [PATCH 4/4] MDL-78280 completion: Fix behat for new completion UI - The following behat step definitions were modified to work correctly both for course page conditions dialog and activity page condition badges: 'activity_completion_condition_displayed_as', 'overridden_activity_completion_condition_displayed_as' and 'activity_should_have_the_completion_condition'. - Because now "Mark as done" manual completion button is not displayed for teachers in course homepage, some behat steps were also modified. --- completion/tests/behat/behat_completion.php | 26 ++++++++++++++----- .../completion_course_page_display.feature | 8 +++--- ...stom_completion_display_conditions.feature | 7 ++--- .../behat/assign_activity_completion.feature | 8 ++---- .../behat/chat_activity_completion.feature | 2 +- .../behat/label_activity_completion.feature | 6 ++--- .../completion_condition_end_reached.feature | 2 +- .../completion_condition_time_spent.feature | 2 +- ...completion_condition_attempts_used.feature | 12 ++++----- ...pletion_condition_minimum_attempts.feature | 18 ++++++------- ...completion_condition_passing_grade.feature | 1 + .../resource_activity_completion.feature | 6 ++--- .../tests/behat/survey_completion.feature | 5 ++-- .../behat/url_activity_completion.feature | 7 ++--- 14 files changed, 56 insertions(+), 54 deletions(-) diff --git a/completion/tests/behat/behat_completion.php b/completion/tests/behat/behat_completion.php index dbb62e869fe..c1b77b3a336 100644 --- a/completion/tests/behat/behat_completion.php +++ b/completion/tests/behat/behat_completion.php @@ -157,7 +157,7 @@ class behat_completion extends behat_base { /** * Checks if the activity with specified name is maked as complete. * - * @Given /^the "(?P(?:[^"]|\\")*)" completion condition of "(?P(?:[^"]|\\")*)" is displayed as "(?P(?:[^"]|\\")*)"$/ + * @When the :conditionname completion condition of :activityname is displayed as :completionstatus * @param string $conditionname The completion condition text. * @param string $activityname The activity name. * @param string $completionstatus The completion status. Must be either of the following: 'todo', 'done', 'failed'. @@ -169,7 +169,7 @@ class behat_completion extends behat_base { throw new coding_exception('Invalid completion status. It must be of type "todo", "done", or "failed".'); } - $text = get_string("completion_automatic:$completionstatus", 'core_course') . ' ' . $conditionname; + $text = get_string("completion_automatic:$completionstatus", 'core_course'); $conditionslistlabel = get_string('completionrequirements', 'core_course', $activityname); $selector = "div[aria-label='$conditionslistlabel']"; @@ -178,20 +178,21 @@ class behat_completion extends behat_base { // If there is a dropdown, open it. $dropdownnode = $this->find('css', $selector . ' .dropdown-menu'); if (!$dropdownnode->hasClass('show')) { - $params = [get_string('completionmenuitem', 'completion'), "button", $selector, "css_element"]; + $params = ["button.dropdown-toggle", "css_element", $selector, "css_element"]; $this->execute("behat_general::i_click_on_in_the", $params); } } catch (ElementNotFoundException $e) { // If the dropdown does not exist, we are in the activity page, all good. } - $this->execute("behat_general::assert_element_contains_text", [$text, $selector, "css_element"]); + $xpath = "//div[@aria-label='$conditionslistlabel']//span[text()='$conditionname']/.."; + $this->execute("behat_general::assert_element_contains_text", [$text, $xpath, "xpath_element"]); } /** * Checks if the activity with specified name is maked as complete. * - * @Given /^the "(?P(?:[^"]|\\")*)" completion condition of "(?P(?:[^"]|\\")*)" overridden by "(?P(?:[^"]|\\")*)" is displayed as "(?P(?:[^"]|\\")*)"$/ + * @When the :conditionname completion condition of :activityname overridden by :username is displayed as :completionstatus * @param string $conditionname The completion condition text. * @param string $activityname The activity name. * @param string $username The full name of the user overriding the student's activity completion. @@ -207,7 +208,7 @@ class behat_completion extends behat_base { 'condition' => $conditionname, 'setby' => $username, ]); - $conditionbadge = "span[aria-label='$conditionlabel']"; + $conditionbadge = "div[aria-label='$conditionlabel']"; $conditionslistlabel = get_string('completionrequirements', 'core_course', $activityname); $completionconditions = "div[aria-label='$conditionslistlabel']"; @@ -336,13 +337,24 @@ class behat_completion extends behat_base { /** * Check that the activity has the given automatic completion condition. * - * @Given /^"(?P(?:[^"]|\\")*)" should have the "(?P(?:[^"]|\\")*)" completion condition$/ + * @When :activityname should have the :conditionname completion condition * @param string $activityname The activity name. * @param string $conditionname The automatic condition name. */ public function activity_should_have_the_completion_condition(string $activityname, string $conditionname): void { $containerselector = "div[data-region=activity-information][data-activityname='$activityname']"; + try { + // If there is a dropdown, open it. + $dropdownnode = $this->find('css', $containerselector . ' .dropdown-menu'); + if (!$dropdownnode->hasClass('show')) { + $params = ["button.dropdown-toggle", "css_element", $containerselector, "css_element"]; + $this->execute("behat_general::i_click_on_in_the", $params); + } + } catch (ElementNotFoundException $e) { + // If the dropdown does not exist, we are in the activity page, all good. + } + $params = [$conditionname, $containerselector, 'css_element']; $this->execute("behat_general::assert_element_contains_text", $params); } diff --git a/completion/tests/behat/completion_course_page_display.feature b/completion/tests/behat/completion_course_page_display.feature index f09e8024788..cca37e0a4ac 100644 --- a/completion/tests/behat/completion_course_page_display.feature +++ b/completion/tests/behat/completion_course_page_display.feature @@ -1,4 +1,4 @@ -@core @core_completion +@core @core_completion @javascript Feature: Show activity completion status or activity completion configuration on the course page In order to understand the configuration or status of an activity's completion As a user @@ -38,16 +38,16 @@ Feature: Show activity completion status or activity completion configuration on Scenario: Show completion configuration to editing teachers Given I am on the "Course 1" course page logged in as teacher1 - And the manual completion button for "Test forum name" should be disabled + And "Test forum name" should have the "Mark as done" completion condition And "Test assignment name" should have the "View" completion condition And there should be no completion information shown for "Test quiz name" And I am on "Course 1" course homepage with editing mode on - And the manual completion button for "Test forum name" should be disabled + And "Test forum name" should have the "Mark as done" completion condition And "Test assignment name" should have the "View" completion condition And there should be no completion information shown for "Test quiz name" Scenario: Show completion configuration to non-editing teachers Given I am on the "Course 1" course page logged in as teacher2 - And the manual completion button for "Test forum name" should be disabled + And "Test forum name" should have the "Mark as done" completion condition And "Test assignment name" should have the "View" completion condition And there should be no completion information shown for "Test quiz name" diff --git a/completion/tests/behat/custom_completion_display_conditions.feature b/completion/tests/behat/custom_completion_display_conditions.feature index 73c484ed2ad..49a16b7a193 100644 --- a/completion/tests/behat/custom_completion_display_conditions.feature +++ b/completion/tests/behat/custom_completion_display_conditions.feature @@ -18,13 +18,14 @@ Feature: Allow teachers to edit the visibility of completion conditions in a cou | activity | course | idnumber | name | completion | completionsubmit | | choice | C1 | c1m | Test choice manual| 1 | 0 | | choice | C1 | c1a | Test choice auto | 2 | 1 | - + @javascript Scenario: Completion condition displaying for manual and auto completion Given I log in as "teacher1" When I am on "Course 1" course homepage - # The manual completion toggle button should be always displayed in both course homepage and activity view. - Then the manual completion button for "Test choice manual" should be disabled + # The manual completion "Mark as done" criteria should displayed in the dropdown in the course homepage. + Then "Test choice manual" should have the "Mark as done" completion condition And I follow "Test choice manual" + # The manual completion toggle button should be displayed in activity view. And the manual completion button for "Test choice manual" should be disabled # Automatic completion conditions should be displayed on both activity view page and course homepage if show completion conditions is enabled. And I am on "Course 1" course homepage diff --git a/mod/assign/tests/behat/assign_activity_completion.feature b/mod/assign/tests/behat/assign_activity_completion.feature index b2b9c7c0838..984bde118f8 100644 --- a/mod/assign/tests/behat/assign_activity_completion.feature +++ b/mod/assign/tests/behat/assign_activity_completion.feature @@ -43,8 +43,7 @@ Feature: View activity completion in the assignment activity Scenario: The manual completion button will be shown on the course page if the Show activity completion conditions is set to Yes Given I am on the "Course 1" course page logged in as teacher1 # Teacher view. - And the manual completion button for "Music history" should exist - And the manual completion button for "Music history" should be disabled + And "Music history" should have the "Mark as done" completion condition And I log out # Student view. When I log in as "student1" @@ -62,10 +61,7 @@ Feature: View activity completion in the assignment activity And I set the field "Show activity completion conditions" to "No" And I press "Save and display" # Teacher view. - And the manual completion button for "Music history" should not exist - And I am on the "Music history" "assign activity" page - And the manual completion button for "Music history" should exist - And the manual completion button for "Music history" should be disabled + And "Completion" "button" should not exist in the "Music history" "activity" And I log out # Student view. When I am on the "Course 1" course page logged in as "student1" diff --git a/mod/chat/tests/behat/chat_activity_completion.feature b/mod/chat/tests/behat/chat_activity_completion.feature index fd8e20f4334..99498fd1c94 100644 --- a/mod/chat/tests/behat/chat_activity_completion.feature +++ b/mod/chat/tests/behat/chat_activity_completion.feature @@ -55,7 +55,7 @@ Feature: View activity completion information in the chat activity | completion | 1 | And I am on "Course 1" course homepage # Teacher view. - And the manual completion button for "Music history" should be disabled + And "Music history" should have the "Mark as done" completion condition And I log out # Student view. And I am on the "Music history" Activity page logged in as student1 diff --git a/mod/label/tests/behat/label_activity_completion.feature b/mod/label/tests/behat/label_activity_completion.feature index c6a8cad300c..4c35f5733e3 100644 --- a/mod/label/tests/behat/label_activity_completion.feature +++ b/mod/label/tests/behat/label_activity_completion.feature @@ -35,8 +35,7 @@ Feature: View activity completion information for the label Scenario: The manual completion button will be shown on the course page if the Show activity completion conditions is set to No Given I am on "Course 1" course homepage # Teacher view. - And the manual completion button for "Test label 1" should exist - And the manual completion button for "Test label 1" should be disabled + And "Test label 1" should have the "Mark as done" completion condition And I log out # Student view. When I log in as "student1" @@ -54,8 +53,7 @@ Feature: View activity completion information for the label And I set the field "Show activity completion conditions" to "Yes" And I press "Save and display" # Teacher view. - And the manual completion button for "Test label 1" should exist - And the manual completion button for "Test label 1" should be disabled + And "Test label 1" should have the "Mark as done" completion condition And I log out # Student view. When I log in as "student1" diff --git a/mod/lesson/tests/behat/completion_condition_end_reached.feature b/mod/lesson/tests/behat/completion_condition_end_reached.feature index 8e03ff3cfca..1032660c9ff 100644 --- a/mod/lesson/tests/behat/completion_condition_end_reached.feature +++ b/mod/lesson/tests/behat/completion_condition_end_reached.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson +@mod @mod_lesson @javascript Feature: Set end of lesson reached as a completion condition for a lesson In order to ensure students really see all lesson pages As a teacher diff --git a/mod/lesson/tests/behat/completion_condition_time_spent.feature b/mod/lesson/tests/behat/completion_condition_time_spent.feature index 54d50c61e6f..88561b7e815 100644 --- a/mod/lesson/tests/behat/completion_condition_time_spent.feature +++ b/mod/lesson/tests/behat/completion_condition_time_spent.feature @@ -1,4 +1,4 @@ -@mod @mod_lesson +@mod @mod_lesson @javascript Feature: Set time spent as a completion condition for a lesson In order to ensure students spend the needed time to study lessons As a teacher diff --git a/mod/quiz/tests/behat/completion_condition_attempts_used.feature b/mod/quiz/tests/behat/completion_condition_attempts_used.feature index e520f959541..7351b1b73ce 100644 --- a/mod/quiz/tests/behat/completion_condition_attempts_used.feature +++ b/mod/quiz/tests/behat/completion_condition_attempts_used.feature @@ -1,4 +1,4 @@ -@mod @mod_quiz @core_completion +@mod @mod_quiz @core_completion @javascript Feature: Set a quiz to be marked complete when the student uses all attempts allowed In order to ensure a student has learned the material before being marked complete As a teacher @@ -35,8 +35,7 @@ Feature: Set a quiz to be marked complete when the student uses all attempts all | 1 | False | Scenario Outline: Student attempts the quiz - pass and fails - When I log in as "student1" - And I am on "Course 1" course homepage + When I am on the "Course 1" course page logged in as student1 And the "Receive a grade" completion condition of "Test quiz name" is displayed as "done" And the "Receive a passing grade" completion condition of "Test quiz name" is displayed as "failed" And the "Receive a pass grade or complete all available attempts" completion condition of "Test quiz name" is displayed as "todo" @@ -45,18 +44,17 @@ Feature: Set a quiz to be marked complete when the student uses all attempts all And I set the field "" to "1" And I press "Finish attempt ..." And I press "Submit all and finish" + And I click on "Submit all and finish" "button" in the "Submit all your answers and finish?" "dialogue" And I am on "Course 1" course homepage Then the "Receive a grade" completion condition of "Test quiz name" is displayed as "done" And the "Receive a passing grade" completion condition of "Test quiz name" is displayed as "" And the "Receive a pass grade or complete all available attempts" completion condition of "Test quiz name" is displayed as "done" - And I follow "Test quiz name" + And I click on "Test quiz name" "link" in the "region-main" "region" And the "Receive a grade" completion condition of "Test quiz name" is displayed as "done" And the "Receive a passing grade" completion condition of "Test quiz name" is displayed as "" And the "Receive a pass grade or complete all available attempts" completion condition of "Test quiz name" is displayed as "done" And I log out - And I log in as "teacher1" - And I am on "Course 1" course homepage - And I follow "Test quiz name" + And I am on the "Test quiz name" "quiz activity" page logged in as teacher1 And "Test quiz name" should have the "Receive a pass grade or complete all available attempts" completion condition And I am on "Course 1" course homepage And I navigate to "Reports" in current page administration diff --git a/mod/quiz/tests/behat/completion_condition_minimum_attempts.feature b/mod/quiz/tests/behat/completion_condition_minimum_attempts.feature index 01d5ed4bd21..1550e26058a 100644 --- a/mod/quiz/tests/behat/completion_condition_minimum_attempts.feature +++ b/mod/quiz/tests/behat/completion_condition_minimum_attempts.feature @@ -1,4 +1,4 @@ -@mod @mod_quiz @core_completion +@mod @mod_quiz @core_completion @javascript Feature: Set a quiz to be marked complete when the student completes a minimum amount of attempts In order to ensure a student has completed the quiz before being marked complete As a teacher @@ -35,26 +35,24 @@ Feature: Set a quiz to be marked complete when the student completes a minimum a | 1 | False | Scenario: student1 uses up both attempts without passing - When I log in as "teacher1" - And I am on "Course 1" course homepage + When I am on the "Course 1" course page logged in as teacher1 And "Completed: Test quiz name" "icon" should not exist in the "Test quiz name" "list_item" And I log out - And I log in as "student1" - And I am on "Course 1" course homepage + And I am on the "Course 1" course page logged in as student1 And the "Make attempts: 2" completion condition of "Test quiz name" is displayed as "todo" - And I follow "Test quiz name" + And I click on "Test quiz name" "link" in the "region-main" "region" And I press "Re-attempt quiz" And I set the field "False" to "1" And I press "Finish attempt ..." And I press "Submit all and finish" + And I click on "Submit all and finish" "button" in the "Submit all your answers and finish?" "dialogue" And I am on "Course 1" course homepage Then the "Make attempts: 2" completion condition of "Test quiz name" is displayed as "done" - And I follow "Test quiz name" + And I click on "Test quiz name" "link" in the "region-main" "region" And the "Make attempts: 2" completion condition of "Test quiz name" is displayed as "done" And I log out - And I log in as "teacher1" - And I am on "Course 1" course homepage - And I follow "Test quiz name" + And I am on the "Course 1" course page logged in as teacher1 + And I click on "Test quiz name" "link" in the "region-main" "region" And "Test quiz name" should have the "Make attempts: 2" completion condition And I am on "Course 1" course homepage And I navigate to "Reports" in current page administration diff --git a/mod/quiz/tests/behat/completion_condition_passing_grade.feature b/mod/quiz/tests/behat/completion_condition_passing_grade.feature index ff9bbfae821..cb8010ec04f 100644 --- a/mod/quiz/tests/behat/completion_condition_passing_grade.feature +++ b/mod/quiz/tests/behat/completion_condition_passing_grade.feature @@ -31,6 +31,7 @@ Feature: Set a quiz to be marked complete when the student passes | question | page | | First question | 1 | + @javascript Scenario: student1 passes on the first try When I log in as "student1" And I am on "Course 1" course homepage diff --git a/mod/resource/tests/behat/resource_activity_completion.feature b/mod/resource/tests/behat/resource_activity_completion.feature index 645a86be35d..4676bdf422e 100644 --- a/mod/resource/tests/behat/resource_activity_completion.feature +++ b/mod/resource/tests/behat/resource_activity_completion.feature @@ -33,8 +33,7 @@ Feature: View activity completion information for file resources | resource | C1 | Myfile | | 0 | 0 | 0 | 1 | mod/resource/tests/fixtures/samplefile.txt | 620 | 450 | 1 | And I am on "Course 1" course homepage with editing mode on # Teacher view. - And the manual completion button for "Myfile" should exist - And the manual completion button for "Myfile" should be disabled + And "Myfile" should have the "Mark as done" completion condition # Student view. When I am on the "Course 1" course page logged in as student1 Then the manual completion button for "Myfile" should exist @@ -64,8 +63,7 @@ Feature: View activity completion information for file resources | Completion tracking | Students can manually mark the activity as completed | And I click on "Save and return to course" "button" # Teacher view. - And the manual completion button for "Myfile" should exist - And the manual completion button for "Myfile" should be disabled + And "Myfile" should have the "Mark as done" completion condition And I am on the "Myfile" "resource activity" page And the manual completion button for "Myfile" should exist And the manual completion button for "Myfile" should be disabled diff --git a/mod/survey/tests/behat/survey_completion.feature b/mod/survey/tests/behat/survey_completion.feature index 40da03acc37..2c2c6810941 100644 --- a/mod/survey/tests/behat/survey_completion.feature +++ b/mod/survey/tests/behat/survey_completion.feature @@ -1,4 +1,4 @@ -@mod @mod_survey @core_completion +@mod @mod_survey @core_completion @javascript Feature: A teacher can use activity completion to track a student progress In order to use activity completion As a teacher @@ -50,14 +50,13 @@ Feature: A teacher can use activity completion to track a student progress And I follow "Test survey name" And the "Submit answers" completion condition of "Test survey name" is displayed as "done" - @javascript Scenario: Use manual completion Given the following "activities" exist: | activity | name | course | idnumber | completion | | survey | Test survey name | C1 | survey1 | 1 | And I am on "Course 1" course homepage # Teacher view. - And the manual completion button for "Test survey name" should be disabled + And "Test survey name" should have the "Mark as done" completion condition # Student view. When I am on the "survey1" Activity page logged in as student1 Then the manual completion button of "Test survey name" is displayed as "Mark as done" diff --git a/mod/url/tests/behat/url_activity_completion.feature b/mod/url/tests/behat/url_activity_completion.feature index f87c4c816b5..052c03a7e92 100644 --- a/mod/url/tests/behat/url_activity_completion.feature +++ b/mod/url/tests/behat/url_activity_completion.feature @@ -77,6 +77,7 @@ Feature: View activity completion information in the URL resource When I am on the "Music history" "url activity" page logged in as student1 Then the "View" completion condition of "Music history" is displayed as "done" + @javascript Scenario: View automatic completion items in open display mode as teacher Given the following "activity" exists: | activity | url | @@ -92,6 +93,7 @@ Feature: View activity completion information in the URL resource And I am on the "Course 1" course page Then "Music history" should have the "View" completion condition + @javascript Scenario: View automatic completion items in open display mode as student Given the following "activity" exists: | activity | url | @@ -172,7 +174,7 @@ Feature: View activity completion information in the URL resource And the manual completion button of "Music history" is displayed as "Done" @javascript - Scenario Outline: The manual completion button will be shown on the course page for Open, In pop-up and New window display mode if the Show activity completion conditions is set to No as teacher + Scenario Outline: The Mark as done completion condition will be shown on the course page for Open, In pop-up and New window display mode if the Show activity completion conditions is set to No as teacher Given the following "activity" exists: | activity | url | | course | C1 | @@ -186,8 +188,7 @@ Feature: View activity completion information in the URL resource | popupwidth | 620 | | popupheight | 450 | When I am on the "Course 1" course page logged in as teacher1 - Then the manual completion button for "Music history" should exist - And the manual completion button for "Music history" should be disabled + Then "Music history" should have the "Mark as done" completion condition Examples: | display | description |