Skip to content

Commit

Permalink
MDL-76010 behat: Move feature to use attempts generator
Browse files Browse the repository at this point in the history
This moves away from manual attempts and uses the activity
attempts generator instead. Quicker and not exposed to the
problems with clicks, refreshes and missing attempts.

Note that there is a small change in the attempt generator
so, now, when a new attempt is created, if the activity has
tracking enabled, the final result / grades are recalculated.

That's the real behaviour when the activity settings are
changes in the edition form and it's natural to get them
recalculated without having to visit the form. Specifically,
this allows the 1st scenario to pass, because in that scenario
no changes to the form are being performed.

Also, little detail, amend a dupe scenario name.
  • Loading branch information
stronk7 committed Oct 18, 2022
1 parent 651a97e commit b1fe51c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
28 changes: 10 additions & 18 deletions mod/h5pactivity/tests/behat/grading_attempts.feature
Expand Up @@ -24,26 +24,18 @@ Feature: Change grading options in an H5P activity
| course | C1 |
| name | Awesome H5P package |
| packagefilepath | h5p/tests/fixtures/multiple-choice-2-6.h5p |
And I am on the "Awesome H5P package" "h5pactivity activity" page logged in as student1
And I switch to "h5p-player" class iframe
And I switch to "h5p-iframe" class iframe
And I click on "Wrong one" "text" in the ".h5p-question-content" "css_element"
And I click on "Check" "button" in the ".h5p-question-buttons" "css_element"
And I click on "Retry" "button" in the ".h5p-question-buttons" "css_element"
And I click on "Correct one" "text" in the ".h5p-question-content" "css_element"
And I click on "Check" "button" in the ".h5p-question-buttons" "css_element"
And I switch to the main frame
# H5P does not allow to Retry if the user checks the correct answer, we need to refresh the page.
And I reload the page
And I switch to "h5p-player" class iframe
And I switch to "h5p-iframe" class iframe
And I click on "Wrong one" "text" in the ".h5p-question-content" "css_element"
And I click on "Check" "button" in the ".h5p-question-buttons" "css_element"
And I switch to the main frame
And the following "mod_h5pactivity > attempts" exist:
| user | h5pactivity | attempt | interactiontype | rawscore | maxscore | duration | completion | success |
| student1 | Awesome H5P package | 1 | choice | 0 | 1 | 4 | 1 | 0 |
| student1 | Awesome H5P package | 2 | choice | 1 | 1 | 4 | 1 | 1 |
| student1 | Awesome H5P package | 3 | choice | 0 | 1 | 4 | 1 | 0 |

@javascript
Scenario: Default grading is max attempt grade
Given I am on the "Awesome H5P package" "h5pactivity activity" page logged in as teacher1
Given I am on the "Awesome H5P package" "h5pactivity activity editing" page logged in as teacher1
And I expand all fieldsets
And the field "Grading method" matches value "Highest grade"
And I click on "Save and return to course" "button"
When I navigate to "View > User report" in the course gradebook
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
Expand All @@ -63,7 +55,7 @@ Feature: Change grading options in an H5P activity
| Awesome H5P package | 0.00 | 0.00 % |

@javascript
Scenario: Change setting to first attempt
Scenario: Change setting to last attempt
Given I am on the "Awesome H5P package" "h5pactivity activity editing" page logged in as teacher1
When I set the following fields to these values:
| Grading method | Last attempt |
Expand Down
7 changes: 7 additions & 0 deletions mod/h5pactivity/tests/generator/lib.php
Expand Up @@ -191,6 +191,7 @@ public function create_content($instance, $record = []) {
* @param array $data the attempts data array
*/
public function create_attempt(array $data): void {
global $DB;

if (!isset($data['h5pactivityid'])) {
throw new coding_exception('Must specify h5pactivityid when creating a H5P attempt.');
Expand Down Expand Up @@ -218,6 +219,12 @@ public function create_attempt(array $data): void {
}

$this->insert_statement($data, $this->$method($data));

// If the activity has tracking enabled, try to recalculate grades.
$activity = $DB->get_record('h5pactivity', ['id' => $data['h5pactivityid']]);
if ($activity->enabletracking) {
h5pactivity_update_grades($activity, $data['userid']);
}
}

/**
Expand Down

0 comments on commit b1fe51c

Please sign in to comment.