From f19f31736a2b6b6f00e0d31a499e86b9a1b41c3d Mon Sep 17 00:00:00 2001 From: Angelia Dela Cruz Date: Mon, 7 Nov 2022 12:38:52 +0800 Subject: [PATCH 1/2] MDL-76065 behat: LTI behat generators use UI Replace steps that manually add LTI instances via the UI and use Behat generators. This improves the speed of the Behat test runs. --- mod/lti/tests/behat/addtype.feature | 3 +-- mod/lti/tests/behat/contentitem.feature | 13 +++++------- .../behat/lti_activity_completion.feature | 6 +----- .../behat/lti_completion_pass_grade.feature | 20 ++++--------------- 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/mod/lti/tests/behat/addtype.feature b/mod/lti/tests/behat/addtype.feature index 27e0752adac..cb229b3396e 100644 --- a/mod/lti/tests/behat/addtype.feature +++ b/mod/lti/tests/behat/addtype.feature @@ -64,7 +64,6 @@ Feature: Add preconfigured tools via teacher interface | name | Test tool activity | When I am on the "Test tool activity" "lti activity editing" page logged in as teacher1 And I set the field "Tool URL" to local url "/mod/lti/tests/fixtures/tool_provider.php" - And I press "Save and return to course" - And I am on the "Test tool activity" "lti activity" page + And I press "Save and display" And I switch to "contentframe" iframe Then I should see "This represents a tool provider" diff --git a/mod/lti/tests/behat/contentitem.feature b/mod/lti/tests/behat/contentitem.feature index 6b1c6ee9537..504e8cf4997 100644 --- a/mod/lti/tests/behat/contentitem.feature +++ b/mod/lti/tests/behat/contentitem.feature @@ -87,14 +87,11 @@ Feature: Content-Item support @javascript Scenario: Editing a manually configured external tool - Given I log in as "teacher1" - And I am on "Course 1" course homepage with editing mode on - And I add a "External tool" to section "1" - And the field "Preconfigured tool" matches value "Automatic, based on tool URL" - And I set the field "Activity name" to "Test tool activity 1" - And the "Select content" "button" should be disabled - And I set the field "Tool URL" to local url "/mod/lti/tests/fixtures/tool_provider.php" - And I press "Save and return to course" + Given the following "activities" exist: + | activity | course | name | typeid | toolurl | + | lti | C1 | Test tool activity 1 | 0 | /mod/lti/tests/fixtures/tool_provider.php | + And I am on the "Course 1" course page logged in as teacher1 + And I turn editing mode on When I open "Test tool activity 1" actions menu And I choose "Edit settings" in the open action menu Then the field "Preconfigured tool" matches value "Automatic, based on tool URL" diff --git a/mod/lti/tests/behat/lti_activity_completion.feature b/mod/lti/tests/behat/lti_activity_completion.feature index 73d0aaafde9..a93a15249d4 100644 --- a/mod/lti/tests/behat/lti_activity_completion.feature +++ b/mod/lti/tests/behat/lti_activity_completion.feature @@ -29,13 +29,11 @@ Feature: View activity completion information in the LTI activity Given I am on the "Music history" "lti activity" page logged in as student1 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 "todo" - And I log out And I am on the "Course 1" course page logged in as teacher1 And I navigate to "View > Grader report" in the course gradebook And I turn editing mode on And I give the grade "90.00" to the user "Vinnie Student1" for the grade item "Music history" And I press "Save changes" - And I log out When I am on the "Music history" "lti activity" page logged in as student1 Then the "Receive a grade" completion condition of "Music history" is displayed as "done" And the "View" completion condition of "Music history" is displayed as "done" @@ -44,11 +42,9 @@ Feature: View activity completion information in the LTI activity Given I am on the "Music history" "lti activity editing" page logged in as teacher1 And I expand all fieldsets And I set the field "Completion tracking" to "Students can manually mark the activity as completed" - And I press "Save and return to course" + And I press "Save and display" # Teacher view. - Given I am on the "Music history" "lti 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" "lti activity" page logged in as student1 Then the manual completion button of "Music history" is displayed as "Mark as done" diff --git a/mod/lti/tests/behat/lti_completion_pass_grade.feature b/mod/lti/tests/behat/lti_completion_pass_grade.feature index 26b471a2247..6c1cdce7482 100644 --- a/mod/lti/tests/behat/lti_completion_pass_grade.feature +++ b/mod/lti/tests/behat/lti_completion_pass_grade.feature @@ -20,17 +20,13 @@ Feature: Pass grade activity completion information in the LTI activity And the following "activities" exist: | activity | name | course | idnumber | | lti | Music history | C1 | lti1 | - And I log in as "teacher1" - And I am on "Course 1" course homepage - And I navigate to "Settings" in current page administration + And I am on the "Course 1" "course editing" page logged in as teacher1 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 turn editing mode on - When I open "Music history" actions menu - And I click on "Edit settings" "link" in the "Music history" activity + And I am on the "Music history" "lti activity editing" page And I set the following fields to these values: | Completion tracking | Show activity as complete when conditions are met | | Require view | 1 | @@ -38,7 +34,6 @@ Feature: Pass grade activity completion information in the LTI activity | gradepass | 50 | | completionpassgrade | 1 | And I press "Save and return to course" - And I log out Scenario: View automatic completion items as a teacher Given I am on the "Music history" "lti activity" page logged in as teacher1 @@ -51,32 +46,25 @@ Feature: Pass grade activity completion information in the LTI 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 "todo" And the "Receive a passing grade" completion condition of "Music history" is displayed as "todo" - 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 I navigate to "View > Grader report" in the course gradebook And I turn editing mode on And I give the grade "90.00" to the user "Vinnie Student1" for the grade item "Music history" And I give the grade "20.00" to the user "Vinnie Student2" for the grade item "Music history" And I press "Save changes" - And I log out When I am on the "Music history" "lti activity" page logged in as student1 Then the "Receive a grade" completion condition of "Music history" is displayed as "done" Then the "Receive a passing grade" completion condition of "Music history" is displayed as "done" And the "View" completion condition of "Music history" is displayed as "done" - And I log out When I am on the "Music history" "lti activity" page logged in as student2 Then the "Receive a grade" completion condition of "Music history" is displayed as "done" Then the "Receive a passing grade" completion condition of "Music history" is displayed as "failed" And the "View" completion condition of "Music history" is displayed as "done" - And I log out When I am on the "Music history" "lti activity" page logged in as student3 Then the "Receive a grade" completion condition of "Music history" is displayed as "todo" Then the "Receive a passing grade" completion condition of "Music history" is displayed as "todo" And the "View" completion condition of "Music history" is displayed as "done" - 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 From 1936b30c88fdf9fee6aefe70f7937ab0694b2697 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Thu, 18 May 2023 12:05:11 +0800 Subject: [PATCH 2/2] MDL-76065 behat: Review and enhance mod_lti Behat tests In this commit, the following improvements were made to the mod_lti Behat tests: * Replaced manual steps with data generators to set completion. * Eliminated unnecessary user and course enrolments data generation as some tests can be performed as an admin. * Removed the @javascript tag from non-JS tests. * Updated the LTI data generator to generate an internal Moodle URL in the toolurl field, enabling the use of XML files. --- mod/lti/tests/behat/addtype.feature | 33 ++++++------------- mod/lti/tests/behat/contentitem.feature | 9 ++--- .../behat/lti_activity_completion.feature | 4 ++- .../behat/lti_completion_pass_grade.feature | 25 ++++---------- mod/lti/tests/behat/renametool.feature | 17 ++++------ .../siteadmin_managetool_breadcrumbs.feature | 2 +- mod/lti/tests/behat/toolconfigure.feature | 13 +------- mod/lti/tests/behat/viewtools.feature | 12 +++---- mod/lti/tests/generator/lib.php | 3 ++ 9 files changed, 37 insertions(+), 81 deletions(-) diff --git a/mod/lti/tests/behat/addtype.feature b/mod/lti/tests/behat/addtype.feature index cb229b3396e..8d2869bbec2 100644 --- a/mod/lti/tests/behat/addtype.feature +++ b/mod/lti/tests/behat/addtype.feature @@ -14,17 +14,12 @@ Feature: Add preconfigured tools via teacher interface And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | + And the following "activities" exist: + | activity | course | name | typeid | toolurl | + | lti | C1 | Test tool | 0 | /mod/lti/tests/fixtures/ims_cartridge_basic_lti_link.xml | - @javascript Scenario: Add a tool from a cartridge - Given the following "activity" exists: - | course | C1 | - | activity | lti | - | name | Test tool activity | - When I am on the "Test tool activity" "lti activity editing" page logged in as teacher1 - And I set the field "Tool URL" to local url "/mod/lti/tests/fixtures/ims_cartridge_basic_lti_link.xml" - And I press "Save and return to course" - And I am on the "Test tool activity" "lti activity editing" page + Given I am on the "Test tool" "lti activity editing" page logged in as teacher1 And I expand all fieldsets Then the field "Tool URL" matches value "http://www.example.com/lti/provider.php" And the field "Secure tool URL" matches value "https://www.example.com/lti/provider.php" @@ -33,11 +28,7 @@ Feature: Add preconfigured tools via teacher interface @javascript @_switch_window Scenario: Add a preconfigured tool from a cartridge - Given the following "activity" exists: - | course | C1 | - | activity | lti | - | name | Test tool activity 1 | - When I am on the "Test tool activity 1" "lti activity editing" page logged in as teacher1 + Given I am on the "Test tool" "lti activity editing" page logged in as teacher1 And I follow "Add preconfigured tool" And I switch to "add_tool" window And I set the field "Tool name" to "Placeholder" @@ -46,24 +37,20 @@ Feature: Add preconfigured tools via teacher interface And I switch to the main window And I wait "2" seconds And I follow "Edit preconfigured tool" - And I switch to "edit_tool" window + When I switch to "edit_tool" window Then the field "Tool URL" matches value "http://www.example.com/lti/provider.php" And the field "Icon URL" matches value "http://download.moodle.org/unittest/test.jpg" And the field "Secure icon URL" matches value "https://download.moodle.org/unittest/test.jpg" And I press "Cancel" And I switch to the main window - And I press "Save and return to course" - And I am on the "Test tool activity 1" "lti activity editing" page + And I press "Save and display" + And I am on the "Test tool" "lti activity editing" page And the field "Preconfigured tool" matches value "Placeholder" @javascript @_switch_window Scenario: Add and use a preconfigured tool - Given the following "activity" exists: - | course | C1 | - | activity | lti | - | name | Test tool activity | - When I am on the "Test tool activity" "lti activity editing" page logged in as teacher1 + Given I am on the "Test tool" "lti activity editing" page logged in as teacher1 And I set the field "Tool URL" to local url "/mod/lti/tests/fixtures/tool_provider.php" And I press "Save and display" - And I switch to "contentframe" iframe + When I switch to "contentframe" iframe Then I should see "This represents a tool provider" diff --git a/mod/lti/tests/behat/contentitem.feature b/mod/lti/tests/behat/contentitem.feature index 504e8cf4997..fe56ef5e081 100644 --- a/mod/lti/tests/behat/contentitem.feature +++ b/mod/lti/tests/behat/contentitem.feature @@ -88,11 +88,8 @@ Feature: Content-Item support @javascript Scenario: Editing a manually configured external tool Given the following "activities" exist: - | activity | course | name | typeid | toolurl | - | lti | C1 | Test tool activity 1 | 0 | /mod/lti/tests/fixtures/tool_provider.php | - And I am on the "Course 1" course page logged in as teacher1 - And I turn editing mode on - When I open "Test tool activity 1" actions menu - And I choose "Edit settings" in the open action menu + | activity | course | name | typeid | toolurl | + | lti | C1 | Test tool | 0 | /mod/lti/tests/fixtures/tool_provider.php | + And I am on the "Test tool" "lti activity editing" page logged in as teacher1 Then the field "Preconfigured tool" matches value "Automatic, based on tool URL" And the "Select content" "button" should be disabled diff --git a/mod/lti/tests/behat/lti_activity_completion.feature b/mod/lti/tests/behat/lti_activity_completion.feature index a93a15249d4..46f34547775 100644 --- a/mod/lti/tests/behat/lti_activity_completion.feature +++ b/mod/lti/tests/behat/lti_activity_completion.feature @@ -1,4 +1,4 @@ -@mod @mod_lti @core_completion @javascript +@mod @mod_lti @core_completion Feature: View activity completion information in the LTI activity In order to have visibility of LTI completion requirements As a student @@ -25,6 +25,7 @@ Feature: View activity completion information in the LTI activity Then "Music history" should have the "Receive a grade" completion condition And "Music history" should have the "View" completion condition + @javascript Scenario: View automatic completion items as a student Given I am on the "Music history" "lti activity" page logged in as student1 And the "View" completion condition of "Music history" is displayed as "done" @@ -38,6 +39,7 @@ Feature: View activity completion information in the LTI activity Then the "Receive a grade" completion condition of "Music history" is displayed as "done" And the "View" completion condition of "Music history" is displayed as "done" + @javascript Scenario: Use manual completion Given I am on the "Music history" "lti activity editing" page logged in as teacher1 And I expand all fieldsets diff --git a/mod/lti/tests/behat/lti_completion_pass_grade.feature b/mod/lti/tests/behat/lti_completion_pass_grade.feature index 6c1cdce7482..bf4b65c1745 100644 --- a/mod/lti/tests/behat/lti_completion_pass_grade.feature +++ b/mod/lti/tests/behat/lti_completion_pass_grade.feature @@ -1,4 +1,4 @@ -@mod @mod_lti @core_completion @javascript +@mod @mod_lti @core_completion Feature: Pass grade activity completion information in the LTI activity Background: @@ -9,8 +9,8 @@ Feature: Pass grade activity completion information in the LTI activity | student3 | Vinnie | Student3 | student3@example.com | | teacher1 | Darrell | Teacher1 | teacher1@example.com | And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | + | fullname | shortname | category | enablecompletion | showcompletionconditions | + | Course 1 | C1 | 0 | 1 | 1 | And the following "course enrolments" exist: | user | course | role | | student1 | C1 | student | @@ -18,22 +18,8 @@ Feature: Pass grade activity completion information in the LTI activity | student3 | C1 | student | | teacher1 | C1 | editingteacher | And the following "activities" exist: - | activity | name | course | idnumber | - | lti | Music history | C1 | lti1 | - And I am on the "Course 1" "course editing" page logged in as teacher1 - 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 the "Music history" "lti activity editing" page - And I set the following fields to these values: - | Completion tracking | Show activity as complete when conditions are met | - | Require view | 1 | - | Require grade | 1 | - | gradepass | 50 | - | completionpassgrade | 1 | - And I press "Save and return to course" + | activity | name | course | gradepass | completion | completionview | completionusegrade | completionpassgrade | + | lti | Music history | C1 | 50 | 2 | 1 | 1 | 1 | Scenario: View automatic completion items as a teacher Given I am on the "Music history" "lti activity" page logged in as teacher1 @@ -41,6 +27,7 @@ Feature: Pass grade activity completion information in the LTI activity And "Music history" should have the "Receive a grade" completion condition And "Music history" should have the "Receive a passing grade" completion condition + @javascript Scenario: View automatic completion items as a student Given I am on the "Music history" "lti activity" page logged in as student1 And the "View" completion condition of "Music history" is displayed as "done" diff --git a/mod/lti/tests/behat/renametool.feature b/mod/lti/tests/behat/renametool.feature index 48eee71af4c..c7fd83f7d05 100644 --- a/mod/lti/tests/behat/renametool.feature +++ b/mod/lti/tests/behat/renametool.feature @@ -5,23 +5,18 @@ Feature: Rename external tools via inline editing I need to be able to rename the LTI tool and have it's name change in the gradebook Background: - Given the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Terry1 | Teacher1 | teacher1@example.com | - And the following "courses" exist: + Given the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | + And the following "activities" exist: + | activity | course | name | + | lti | C1 | Test tool activity 1 | @javascript Scenario: Add a tool and inline edit - When I log in as "teacher1" + When I log in as "admin" And I am on "Course 1" course homepage with editing mode on - And I add a "External tool" to section "1" and I fill the form with: - | Activity name | Test tool activity 1 | - And I set the field "Edit title" in the "li#section-1" "css_element" to "Test tool activity renamed" + And I set the field "Edit title" in the "Test tool activity 1" "activity" to "Test tool activity renamed" And I navigate to "Setup > Gradebook setup" in the course gradebook Then I should not see "Test tool activity 1" And I should see "Test tool activity renamed" diff --git a/mod/lti/tests/behat/siteadmin_managetool_breadcrumbs.feature b/mod/lti/tests/behat/siteadmin_managetool_breadcrumbs.feature index eb1a36721c5..46d5f9a1ba3 100644 --- a/mod/lti/tests/behat/siteadmin_managetool_breadcrumbs.feature +++ b/mod/lti/tests/behat/siteadmin_managetool_breadcrumbs.feature @@ -1,4 +1,4 @@ -@mod @mod_lti @javascript +@mod @mod_lti Feature: Verify the breadcrumbs in manage tools site administration pages Whenever I navigate to manage tools page in site administration As an admin diff --git a/mod/lti/tests/behat/toolconfigure.feature b/mod/lti/tests/behat/toolconfigure.feature index 3622bf80962..9271010fbfb 100644 --- a/mod/lti/tests/behat/toolconfigure.feature +++ b/mod/lti/tests/behat/toolconfigure.feature @@ -5,18 +5,7 @@ Feature: Configure tool types I need to be able to add, remove and configure tool types Background: - Given the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Terry1 | Teacher1 | teacher1@example.com | - | student1 | Sam1 | Student1 | student1@example.com | - And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - And I log in as "admin" + Given I log in as "admin" And I navigate to "Plugins > Activity modules > External tool > Manage tools" in site administration @javascript diff --git a/mod/lti/tests/behat/viewtools.feature b/mod/lti/tests/behat/viewtools.feature index 0827135c7e3..87f08ab4f64 100644 --- a/mod/lti/tests/behat/viewtools.feature +++ b/mod/lti/tests/behat/viewtools.feature @@ -9,26 +9,22 @@ Feature: Navigate existing LTI tool types using pagination |name |Test tool [count] | |description |Example description [count] | |baseurl |https://www.example.com/tool[count]| + And I log in as "admin" + And I navigate to "Plugins > Activity modules > External tool > Manage tools" in site administration @javascript Scenario: View first page of tool types. - Given I log in as "admin" - When I navigate to "Plugins > Activity modules > External tool > Manage tools" in site administration Then I should see "Test tool 30" And "Test tool 70" "text" should not be visible @javascript Scenario: View second page of tool types using page 2 button. - Given I log in as "admin" - When I navigate to "Plugins > Activity modules > External tool > Manage tools" in site administration - And I click on "2" "link" + When I click on "2" "link" Then I should see "Test tool 70" And "Test tool 30" "text" should not be visible @javascript Scenario: View last page of tool types using page 2 button. - Given I log in as "admin" - When I navigate to "Plugins > Activity modules > External tool > Manage tools" in site administration - And I click on "Last" "link" + When I click on "Last" "link" Then I should see "Test tool 70" And "Test tool 30" "text" should not be visible diff --git a/mod/lti/tests/generator/lib.php b/mod/lti/tests/generator/lib.php index 5095d35dbab..15f38afe1fe 100644 --- a/mod/lti/tests/generator/lib.php +++ b/mod/lti/tests/generator/lib.php @@ -45,6 +45,9 @@ class mod_lti_generator extends testing_module_generator { if (!isset($record->toolurl)) { $record->toolurl = ''; + } else { + $toolurl = new moodle_url($record->toolurl); + $record->toolurl = $toolurl->out(false); } if (!isset($record->resourcekey)) { $record->resourcekey = '12345';