MDL-76010 behat: Move feature to use attempts generator
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.
This commit is contained in:
@@ -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:
|
||||
@@ -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 |
|
||||
|
||||
@@ -191,6 +191,7 @@ class mod_h5pactivity_generator extends testing_module_generator {
|
||||
* @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.');
|
||||
@@ -218,6 +219,12 @@ class mod_h5pactivity_generator extends testing_module_generator {
|
||||
}
|
||||
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user