Skip to content

Commit

Permalink
modify behat tests for new ratingallocate navigation, check completio…
Browse files Browse the repository at this point in the history
…n status after db queries
  • Loading branch information
irinahpe committed May 23, 2024
1 parent 5d021f2 commit ce4c177
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
25 changes: 24 additions & 1 deletion locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}

}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/completion_condition_allocation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions tests/behat/completion_condition_vote.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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
Expand Down
17 changes: 9 additions & 8 deletions tests/behat/completion_manual.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit ce4c177

Please sign in to comment.