Merge branch 'MDL-77789-master' of https://github.com/sarjona/moodle

This commit is contained in:
Paul Holden 2023-03-30 14:32:21 +01:00
commit c59d7f0174
No known key found for this signature in database
GPG key ID: A81A96D6045F6164
3 changed files with 28 additions and 7 deletions

View file

@ -87,7 +87,7 @@ class attempt {
// Remove any xAPI State associated to this attempt. // Remove any xAPI State associated to this attempt.
$context = \context_module::instance($cm->id); $context = \context_module::instance($cm->id);
$xapihandler = handler::create('mod_h5pactivity'); $xapihandler = handler::create('mod_h5pactivity');
$xapihandler->wipe_states($context->id); $xapihandler->wipe_states($context->id, $user->id);
return new attempt($record); return new attempt($record);
} }

View file

@ -8,6 +8,7 @@ Feature: Users can save the current state of an H5P activity
Given the following "users" exist: Given the following "users" exist:
| username | firstname | lastname | email | | username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com | | student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
| teacher1 | Teacher | 1 | teacher1@example.com | | teacher1 | Teacher | 1 | teacher1@example.com |
And the following "course" exists: And the following "course" exists:
| fullname | Course 1 | | fullname | Course 1 |
@ -15,6 +16,7 @@ Feature: Users can save the current state of an H5P activity
And the following "course enrolments" exist: And the following "course enrolments" exist:
| user | course | role | | user | course | role |
| student1 | C1 | student | | student1 | C1 | student |
| student2 | C1 | student |
| teacher1 | C1 | editingteacher | | teacher1 | C1 | editingteacher |
And the following "permission overrides" exist: And the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference | | capability | permission | role | contextlevel | reference |
@ -126,10 +128,14 @@ Feature: Users can save the current state of an H5P activity
Scenario: Content state is removed when an attempt is created Scenario: Content state is removed when an attempt is created
Given the following config values are set as admin: Given the following config values are set as admin:
| enablesavestate | 1 | mod_h5pactivity| | enablesavestate | 1 | mod_h5pactivity|
# Save state content for student2, to check this data is not removed when student1 finishes their attempt.
And I am on the "Awesome H5P package" "h5pactivity activity" page logged in as student2
When I switch to "h5p-player" class iframe
And I switch to "h5p-iframe" class iframe
And I set the field with xpath "//input[contains(@aria-label,\"Blank input 1 of 4\")]" to "Vallhonesta"
# Create an attempt for student1.
And I am on the "Awesome H5P package" "h5pactivity activity" page logged in as student1 And I am on the "Awesome H5P package" "h5pactivity activity" page logged in as student1
# Check there are no attempts.
And I should not see "Attempts report" And I should not see "Attempts report"
# Create an attempt.
When I switch to "h5p-player" class iframe When I switch to "h5p-player" class iframe
And I switch to "h5p-iframe" class iframe And I switch to "h5p-iframe" class iframe
And I set the field with xpath "//input[contains(@aria-label,\"Blank input 1 of 4\")]" to "Narnia" And I set the field with xpath "//input[contains(@aria-label,\"Blank input 1 of 4\")]" to "Narnia"
@ -141,3 +147,9 @@ Feature: Users can save the current state of an H5P activity
And I switch to "h5p-player" class iframe And I switch to "h5p-player" class iframe
And I switch to "h5p-iframe" class iframe And I switch to "h5p-iframe" class iframe
And the field with xpath "//input[contains(@aria-label,\"Blank input 1 of 4\")]" does not match value "Narnia" And the field with xpath "//input[contains(@aria-label,\"Blank input 1 of 4\")]" does not match value "Narnia"
And I switch to the main frame
# Check the state content for student2 is still there.
And I am on the "Awesome H5P package" "h5pactivity activity" page logged in as student2
And I switch to "h5p-player" class iframe
And I switch to "h5p-iframe" class iframe
And the field with xpath "//input[contains(@aria-label,\"Blank input 1 of 4\")]" matches value "Vallhonesta"

View file

@ -68,22 +68,31 @@ class attempt_test extends \advanced_testcase {
global $CFG, $DB; global $CFG, $DB;
require_once($CFG->dirroot.'/lib/xapi/tests/helper.php'); require_once($CFG->dirroot.'/lib/xapi/tests/helper.php');
list($cm, $student) = $this->generate_testing_scenario(); [$cm, $student, $course] = $this->generate_testing_scenario();
$student2 = $this->getDataGenerator()->create_and_enrol($course, 'student');
// Save the current state for this activity (before creating the first attempt). // Save the current state for this activity for student1 and student2 (before creating the first attempt).
$manager = manager::create_from_coursemodule($cm); $manager = manager::create_from_coursemodule($cm);
$this->setUser($student2);
test_helper::create_state([ test_helper::create_state([
'activity' => item_activity::create_from_id($manager->get_context()->id), 'activity' => item_activity::create_from_id($manager->get_context()->id),
'component' => 'mod_h5pactivity', 'component' => 'mod_h5pactivity',
], true); ], true);
$this->assertEquals(1, $DB->count_records('xapi_states')); $this->setUser($student);
test_helper::create_state([
'activity' => item_activity::create_from_id($manager->get_context()->id),
'component' => 'mod_h5pactivity',
], true);
$this->assertEquals(2, $DB->count_records('xapi_states'));
// Create first attempt. // Create first attempt.
$attempt = attempt::new_attempt($student, $cm); $attempt = attempt::new_attempt($student, $cm);
$this->assertEquals($student->id, $attempt->get_userid()); $this->assertEquals($student->id, $attempt->get_userid());
$this->assertEquals($cm->instance, $attempt->get_h5pactivityid()); $this->assertEquals($cm->instance, $attempt->get_h5pactivityid());
$this->assertEquals(1, $attempt->get_attempt()); $this->assertEquals(1, $attempt->get_attempt());
$this->assertEquals(0, $DB->count_records('xapi_states')); $this->assertEquals(1, $DB->count_records('xapi_states'));
$this->assertEquals(0, $DB->count_records('xapi_states', ['userid' => $student->id]));
// Create a second attempt. // Create a second attempt.
$attempt = attempt::new_attempt($student, $cm); $attempt = attempt::new_attempt($student, $cm);