From 2a50790048357c13b930b23103a8e4342c2e5f1c Mon Sep 17 00:00:00 2001 From: Angelia Dela Cruz Date: Mon, 13 Jun 2022 16:49:10 +0800 Subject: [PATCH] MDL-74861 behat: H5P behat generators use UI Replace steps that manually add H5Pactivity instances via the UI and use Behat generators. This improves the speed of the Behat test runs. Co-authored-by: Simey Lameze --- .../tests/behat/add_h5pactivity.feature | 86 +++++++++---------- .../tests/behat/grading_attempts.feature | 15 ++-- .../behat/h5pactivity_completion.feature | 21 ++--- .../h5pactivity_completion_pass_grade.feature | 35 +++----- .../tests/behat/recent_activity.feature | 11 ++- .../tests/behat/result_fillin.feature | 16 ++-- .../tests/behat/result_longfillin.feature | 16 ++-- .../tests/behat/sending_attempt.feature | 19 ++-- mod/h5pactivity/tests/generator/lib.php | 2 + 9 files changed, 93 insertions(+), 128 deletions(-) diff --git a/mod/h5pactivity/tests/behat/add_h5pactivity.feature b/mod/h5pactivity/tests/behat/add_h5pactivity.feature index 2e746f02957..2145d8bcac6 100644 --- a/mod/h5pactivity/tests/behat/add_h5pactivity.feature +++ b/mod/h5pactivity/tests/behat/add_h5pactivity.feature @@ -22,13 +22,13 @@ Feature: Add H5P activity @javascript Scenario: Add a h5pactivity activity to a course - When I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Awesome H5P package | - | Description | H5P activity Description | - And I upload "h5p/tests/fixtures/ipsums.h5p" file to "Package file" filemanager - And I click on "Save and display" "button" - And I wait until the page is ready + Given the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Awesome H5P package | + | intro | H5P activity Description | + | packagefilepath | h5p/tests/fixtures/ipsums.h5p | + When I am on the "Awesome H5P package" "h5pactivity activity" page Then I should see "H5P activity Description" And I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe @@ -40,13 +40,13 @@ Feature: Add H5P activity @javascript Scenario: Add a h5pactivity activity with download - When I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Awesome H5P package | - | Description | Description | - | Allow download | 1 | - And I upload "h5p/tests/fixtures/ipsums.h5p" file to "Package file" filemanager - And I click on "Save and display" "button" + Given the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Awesome H5P package | + | displayoptions | 12 | + | packagefilepath | h5p/tests/fixtures/ipsums.h5p | + When I am on the "Awesome H5P package" "h5pactivity activity" page And I wait until the page is ready Then I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe @@ -57,13 +57,13 @@ Feature: Add H5P activity @javascript Scenario: Add a h5pactivity activity with embed - When I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Awesome H5P package | - | Description | Description | - | Embed button | 1 | - And I upload "h5p/tests/fixtures/ipsums.h5p" file to "Package file" filemanager - And I click on "Save and display" "button" + Given the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Awesome H5P package | + | displayoptions | 10 | + | packagefilepath | h5p/tests/fixtures/ipsums.h5p | + When I am on the "Awesome H5P package" "h5pactivity activity" page And I wait until the page is ready Then I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe @@ -74,13 +74,13 @@ Feature: Add H5P activity @javascript Scenario: Add a h5pactivity activity with copyright - When I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Awesome H5P package | - | Description | Description | - | Copyright button | 1 | - And I upload "h5p/tests/fixtures/guess-the-answer.h5p" file to "Package file" filemanager - And I click on "Save and display" "button" + Given the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Awesome H5P package | + | displayoptions | 6 | + | packagefilepath | h5p/tests/fixtures/guess-the-answer.h5p | + When I am on the "Awesome H5P package" "h5pactivity activity" page And I wait until the page is ready Then I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe @@ -91,13 +91,13 @@ Feature: Add H5P activity @javascript Scenario: Add a h5pactivity activity with copyright in a content without copyright - When I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Awesome H5P package | - | Description | Description | - | Copyright button | 1 | - And I upload "h5p/tests/fixtures/ipsums.h5p" file to "Package file" filemanager - And I click on "Save and display" "button" + Given the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Awesome H5P package | + | displayoptions | 6 | + | packagefilepath | h5p/tests/fixtures/ipsums.h5p | + When I am on the "Awesome H5P package" "h5pactivity activity" page And I wait until the page is ready Then I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe @@ -108,15 +108,13 @@ Feature: Add H5P activity @javascript Scenario: Add a h5pactivity activity to a course with all display options enabled - When I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Awesome H5P package | - | Description | Description | - | Allow download | 1 | - | Embed button | 1 | - | Copyright button | 1 | - And I upload "h5p/tests/fixtures/guess-the-answer.h5p" file to "Package file" filemanager - And I click on "Save and display" "button" + Given the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Awesome H5P package | + | displayoptions | 0 | + | packagefilepath | h5p/tests/fixtures/guess-the-answer.h5p | + When I am on the "Awesome H5P package" "h5pactivity activity" page And I wait until the page is ready Then I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe diff --git a/mod/h5pactivity/tests/behat/grading_attempts.feature b/mod/h5pactivity/tests/behat/grading_attempts.feature index 568e8e3c089..14f9e7a8f7d 100644 --- a/mod/h5pactivity/tests/behat/grading_attempts.feature +++ b/mod/h5pactivity/tests/behat/grading_attempts.feature @@ -19,15 +19,11 @@ Feature: Change grading options in an H5P activity And the following "permission overrides" exist: | capability | permission | role | contextlevel | reference | | moodle/h5p:updatelibraries | Allow | editingteacher | System | | - And I log in as "teacher1" - And I am on "Course 1" course homepage with editing mode on - And I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Awesome H5P package | - | Description | Description | - And I upload "h5p/tests/fixtures/multiple-choice-2-6.h5p" file to "Package file" filemanager - And I click on "Save and display" "button" - And I log out + And the following "activity" exists: + | activity | h5pactivity | + | 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 @@ -44,7 +40,6 @@ Feature: Change grading options in an H5P activity 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 I log out @javascript Scenario: Default grading is max attempt grade diff --git a/mod/h5pactivity/tests/behat/h5pactivity_completion.feature b/mod/h5pactivity/tests/behat/h5pactivity_completion.feature index 9787de78d10..97a7868b70f 100644 --- a/mod/h5pactivity/tests/behat/h5pactivity_completion.feature +++ b/mod/h5pactivity/tests/behat/h5pactivity_completion.feature @@ -16,24 +16,20 @@ Feature: View activity completion information in the h5p activity | user | course | role | | student1 | C1 | student | | teacher1 | C1 | editingteacher | - And I log in as "admin" - And I am on "Course 1" course homepage with editing mode on - And I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Music history | - | Completion tracking | Show activity as complete when conditions are met | - | Require view | 1 | - | Require grade | 1 | - And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Package file" filemanager - And I click on "Save and display" "button" - And I log out + And the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Music history | + | completion | 2 | + | completionview | 1 | + | completionusegrade | 1 | + | packagefilepath | h5p/tests/fixtures/filltheblanks.h5p | Scenario: View automatic completion items Given I am on the "Music history" "h5pactivity activity" page logged in as teacher1 # Teacher view. And "Music history" should have the "View" completion condition And "Music history" should have the "Receive a grade" completion condition - And I log out # Student view. When I am on the "Music history" "h5pactivity activity" page logged in as student1 And I switch to "h5p-player" class iframe @@ -51,7 +47,6 @@ Feature: View activity completion information in the h5p activity # Teacher view. And I am on the "Music history" "h5pactivity activity" page And the manual completion button for "Music history" should be disabled - And I log out # Student view. When I am on the "Music history" "h5pactivity activity" page logged in as student1 Then the manual completion button of "Music history" is displayed as "Mark as done" diff --git a/mod/h5pactivity/tests/behat/h5pactivity_completion_pass_grade.feature b/mod/h5pactivity/tests/behat/h5pactivity_completion_pass_grade.feature index ac664b555a8..65db8ba44b3 100644 --- a/mod/h5pactivity/tests/behat/h5pactivity_completion_pass_grade.feature +++ b/mod/h5pactivity/tests/behat/h5pactivity_completion_pass_grade.feature @@ -17,47 +17,38 @@ Feature: Pass grade activity completion information in the h5p activity | student2 | C1 | student | | student3 | C1 | student | | teacher1 | C1 | editingteacher | - And I log in as "admin" - And I am on "Course 1" course homepage + And I am on the "Course 1" "Course" page logged in as "admin" And I navigate to "Settings" in current page administration And I expand all fieldsets And I set the following fields to these values: | Enable completion tracking | Yes | | Show activity completion conditions | Yes | And I press "Save and display" - And I am on "Course 1" course homepage with editing mode on - And I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Music history | - | Completion tracking | Show activity as complete when conditions are met | - | Require view | 1 | - | Require grade | 1 | - | completionpassgrade | 1 | - | gradepass | 25 | - And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Package file" filemanager - And I click on "Save and display" "button" + And the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Music history | + | completion | 2 | + | completionview | 1 | + | completionusegrade | 1 | + | completionpassgrade | 1 | + | gradepass | 25 | + | packagefilepath | h5p/tests/fixtures/filltheblanks.h5p | And I log out Scenario: View automatic completion items # Teacher view. Given I am on the "Music history" "h5pactivity activity" page logged in as teacher1 -# Given I log in as "teacher1" -# And I am on "Course 1" course homepage -# And I follow "Music history" And "Music history" should have the "View" completion condition And "Music history" should have the "Receive a grade" completion condition And "Music history" should have the "Receive a passing grade" completion condition And I log out # Student view. When I am on the "Music history" "h5pactivity activity" page logged in as student1 -# When I log in as "student1" -# And I am on "Course 1" course homepage -# And I follow "Music history" And I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe And I click on "Check" "button" in the ".h5p-question-buttons" "css_element" And I reload the page - And I log out And I am on the "Music history" "h5pactivity activity" page logged in as student2 And I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe @@ -76,9 +67,7 @@ Feature: Pass grade activity completion information in the h5p activity And the "View" completion condition of "Music history" is displayed as "done" And the "Receive a grade" completion condition of "Music history" is displayed as "done" And the "Receive a passing grade" completion condition of "Music history" is displayed as "failed" - And I log out - And I log in as "teacher1" - And I am on "Course 1" course homepage + And I am on the "Course 1" "course" page logged in as "teacher1" And "Vinnie Student1" user has completed "Music history" activity And "Vinnie Student2" user has completed "Music history" activity And "Vinnie Student3" user has not completed "Music history" activity diff --git a/mod/h5pactivity/tests/behat/recent_activity.feature b/mod/h5pactivity/tests/behat/recent_activity.feature index e53ca2844ad..f28045fa0dc 100644 --- a/mod/h5pactivity/tests/behat/recent_activity.feature +++ b/mod/h5pactivity/tests/behat/recent_activity.feature @@ -21,14 +21,13 @@ Feature: Users can see the H5P recent activity from the recent activity block And the following "permission overrides" exist: | capability | permission | role | contextlevel | reference | | moodle/h5p:updatelibraries | Allow | editingteacher | System | | + And the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Awesome H5P package | + | packagefilepath | h5p/tests/fixtures/multiple-choice-2-6.h5p | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Awesome H5P package | - | Description | Description | - And I upload "h5p/tests/fixtures/multiple-choice-2-6.h5p" file to "Package file" filemanager - And I click on "Save and return to course" "button" And I add the "Recent activity" block And I log out And I am on the "Awesome H5P package" "h5pactivity activity" page logged in as student1 diff --git a/mod/h5pactivity/tests/behat/result_fillin.feature b/mod/h5pactivity/tests/behat/result_fillin.feature index 3f16be74b2a..057eea12d1e 100644 --- a/mod/h5pactivity/tests/behat/result_fillin.feature +++ b/mod/h5pactivity/tests/behat/result_fillin.feature @@ -17,16 +17,12 @@ Feature: View fill the blanks attempt report And the following config values are set as admin: # No HTML should appear even with formatstringstriptags disabled. | formatstringstriptags | 0 | - And I log in as "admin" - And I am on "Course 1" course homepage with editing mode on - And I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Awesome H5P package | - | Description | Description | - | Grading method | Average grade | - And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Package file" filemanager - And I click on "Save and display" "button" - And I log out + And the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Awesome H5P package | + | grademethod | 2 | + | packagefilepath | h5p/tests/fixtures/filltheblanks.h5p | Scenario: View attempt in a fill the blanks content Given I am on the "Awesome H5P package" "h5pactivity activity" page logged in as student1 diff --git a/mod/h5pactivity/tests/behat/result_longfillin.feature b/mod/h5pactivity/tests/behat/result_longfillin.feature index 1963d6379fe..043836c9b81 100644 --- a/mod/h5pactivity/tests/behat/result_longfillin.feature +++ b/mod/h5pactivity/tests/behat/result_longfillin.feature @@ -17,16 +17,12 @@ Feature: View essay attempt report And the following config values are set as admin: # No HTML should appear even with formatstringstriptags disabled. | formatstringstriptags | 0 | - And I log in as "admin" - And I am on "Course 1" course homepage with editing mode on - And I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Awesome H5P package | - | Description | Description | - | Grading method | Average grade | - And I upload "h5p/tests/fixtures/basic_essay.h5p" file to "Package file" filemanager - And I click on "Save and display" "button" - And I log out + And the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Awesome H5P package | + | grademethod | 2 | + | packagefilepath | h5p/tests/fixtures/basic_essay.h5p | Scenario: View attempt essay content # Do an attempt. diff --git a/mod/h5pactivity/tests/behat/sending_attempt.feature b/mod/h5pactivity/tests/behat/sending_attempt.feature index 37ce18ac5f6..29400702477 100644 --- a/mod/h5pactivity/tests/behat/sending_attempt.feature +++ b/mod/h5pactivity/tests/behat/sending_attempt.feature @@ -19,25 +19,20 @@ Feature: Do a H5P attempt And the following "permission overrides" exist: | capability | permission | role | contextlevel | reference | | moodle/h5p:updatelibraries | Allow | editingteacher | System | | - And I log in as "teacher1" - And I am on "Course 1" course homepage with editing mode on - And I add a "H5P" to section "1" - And I set the following fields to these values: - | Name | Awesome H5P package | - | Description | Description | - And I upload "h5p/tests/fixtures/multiple-choice-2-6.h5p" file to "Package file" filemanager + And the following "activity" exists: + | activity | h5pactivity | + | course | C1 | + | name | Awesome H5P package | + | packagefilepath | h5p/tests/fixtures/multiple-choice-2-6.h5p | - @javascript Scenario: View an H5P as a teacher - When I click on "Save and display" "button" + When I am on the "Awesome H5P package" "h5pactivity activity" page logged in as teacher1 And I wait until the page is ready Then I should see "This content is displayed in preview mode" @javascript Scenario: To an attempts and check on course log report - When I click on "Save and return to course" "button" - And I log out - Given I am on the "Awesome H5P package" "h5pactivity activity" page logged in as student1 + When I am on the "Awesome H5P package" "h5pactivity activity" page logged in as student1 And I wait until the page is ready And I should not see "This content is displayed in preview mode" And I switch to "h5p-player" class iframe diff --git a/mod/h5pactivity/tests/generator/lib.php b/mod/h5pactivity/tests/generator/lib.php index be255f42832..161d59caba8 100644 --- a/mod/h5pactivity/tests/generator/lib.php +++ b/mod/h5pactivity/tests/generator/lib.php @@ -55,6 +55,8 @@ class mod_h5pactivity_generator extends testing_module_generator { // Fill in optional values if not specified. if (!isset($record->packagefilepath)) { $record->packagefilepath = $CFG->dirroot.'/h5p/tests/fixtures/h5ptest.zip'; + } else if (strpos($record->packagefilepath, $CFG->dirroot) !== 0) { + $record->packagefilepath = "{$CFG->dirroot}/{$record->packagefilepath}"; } if (!isset($record->grade)) { $record->grade = 100;