From ce4c177a9136c1371de4eb9a03f9c21cea4230d4 Mon Sep 17 00:00:00 2001 From: Irina Hoppe Date: Thu, 23 May 2024 10:30:39 +0200 Subject: [PATCH] modify behat tests for new ratingallocate navigation, check completion status after db queries --- locallib.php | 25 ++++++++++++++++++- .../completion_condition_allocation.feature | 2 +- tests/behat/completion_condition_vote.feature | 5 ++-- tests/behat/completion_manual.feature | 17 +++++++------ 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/locallib.php b/locallib.php index 6c06aa73..8a0976dd 100644 --- a/locallib.php +++ b/locallib.php @@ -605,6 +605,14 @@ private function process_action_delete_choice() { $DB->delete_records(this_db\ratingallocate_ch_gengroups::TABLE, ['choiceid' => $choiceid]); $DB->delete_records(this_db\ratingallocate_choices::TABLE, array('id' => $choiceid)); + $raters = $this->get_raters_in_course(); + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + foreach ($raters as $rater) { + $completion->update_state($this->coursemodule, COMPLETION_INCOMPLETE, $rater->id); + } + } + redirect(new moodle_url('/mod/ratingallocate/view.php', array('id' => $this->coursemodule->id, 'action' => ACTION_SHOW_CHOICES)), get_string('choice_deleted_notification', RATINGALLOCATE_MOD_NAME, @@ -979,6 +987,13 @@ public function distribute_users_without_choice(string $distributionalgorithm): // At this point we tried to assign all the users. It is possible that users remain undistributed, though. $transaction->allow_commit(); + + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + foreach ($possibleusers as $userid) { + $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $userid); + } + } } private function process_action_show_ratings_and_alloc_table() { @@ -1319,7 +1334,7 @@ public function distrubute_choices() { $raters = $this->get_raters_in_course(); if ($completion->is_enabled($this->coursemodule)) { foreach ($raters as $rater) { - $completion->update_state($this->coursemodule, COMPLETION_COMPLETE, $rater->id); + $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); } } @@ -1939,6 +1954,14 @@ public function save_manual_allocation_form($allocdata, $userdata) { $event->trigger(); $transaction->allow_commit(); + + $completion = new completion_info($this->course); + if ($completion->is_enabled($this->coursemodule)) { + foreach ($allusers as $rater) { + $completion->update_state($this->coursemodule, COMPLETION_UNKNOWN, $rater->id); + } + } + } catch (Exception $e) { if (isset($transaction)) { $transaction->rollback($e); diff --git a/tests/behat/completion_condition_allocation.feature b/tests/behat/completion_condition_allocation.feature index 66a5eb8e..532b9cec 100644 --- a/tests/behat/completion_condition_allocation.feature +++ b/tests/behat/completion_condition_allocation.feature @@ -32,7 +32,7 @@ Feature: Set a ratingallocate activity marked as completed when a user has been | C2 | student1 | 0 | | C2 | student2 | 0 | And I log in as "teacher1" - And I am on the "My Fair Allocation" "ratingallocate activity" page + And I am on the "My Fair Allocation" "mod_ratingallocate > View" page And I run the scheduled task "mod_ratingallocate\task\cron_task" And I press "Publish Allocation" And I log out diff --git a/tests/behat/completion_condition_vote.feature b/tests/behat/completion_condition_vote.feature index 82a376b8..b904d29f 100644 --- a/tests/behat/completion_condition_vote.feature +++ b/tests/behat/completion_condition_vote.feature @@ -22,8 +22,7 @@ Feature: Set a ratingallocate activity marked as completed when a user submits a | activity | course | idnumber | name | completion | completionvote | | ratingallocate | C1 | ra1 | My Fair Allocation | 2 | 1 | And I log in as "teacher1" - And I am on the "My Fair Allocation" "ratingallocate activity" page - And I press "Edit Choices" + And I am on the "My Fair Allocation" "mod_ratingallocate > Choices" page And I add a new choice with the values: | title | My first choice | | Description (optional) | Test 1 | @@ -32,7 +31,7 @@ Feature: Set a ratingallocate activity marked as completed when a user submits a @javascript Scenario: User completes ratingallocate only if they voted When I log in as "student1" - And I am on the "My Fair Allocation" "ratingallocate activity" page + And I am on the "My Fair Allocation" "mod_ratingallocate > View" page And I press "Edit Rating" And I press "Save changes" And I log out diff --git a/tests/behat/completion_manual.feature b/tests/behat/completion_manual.feature index 057ecd60..31a66cdd 100644 --- a/tests/behat/completion_manual.feature +++ b/tests/behat/completion_manual.feature @@ -20,20 +20,21 @@ Feature: Manually mark a ratingallocate activity as completed | activity | course | idnumber | name | completion | | ratingallocate | C1 | ra1 | My Fair Allocation | 1 | And I log in as "teacher1" - And I am on the "My Fair Allocation" "ratingallocate activity" page - And I press "Edit Choices" + And I am on the "My Fair Allocation" "mod_ratingallocate > Choices" page And I add a new choice with the values: | title | My first choice | | Description (optional) | Test 1 | | maxsize | 2 | @javascript - Scenario: Use manual completion - Given I am on the "My Fair Allocation" "ratingallocate activity" page logged in as teacher1 - And the manual completion button for "My Fair Allocation" should be disabled - And I log out - # Student view. - When I am on the "My Fair Allocation" "ratingallocate activity" page logged in as student1 + Scenario: Use manual completion as teacher + When I log in as "teacher1" + And I am on the "My Fair Allocation" "mod_ratingallocate > View" page + Then the manual completion button for "My Fair Allocation" should be disabled + + Scenario: Use manual completion student view + When I log in as "student1" + And I am on the "My Fair Allocation" "mod_ratingallocate > View" page Then the manual completion button of "My Fair Allocation" is displayed as "Mark as done" And I toggle the manual completion state of "My Fair Allocation" And the manual completion button of "My Fair Allocation" is displayed as "Done"