From 68edc3c42a4e6f14528f193e1289f7606b777c03 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 20 Jul 2021 14:15:59 +0800 Subject: [PATCH] MDL-72179 behat: Add activity editing page resolution --- .../behat/tests/behat/i_am_on_page.feature | 2 + .../behat/activities_edit_completion.feature | 16 +++---- lib/tests/behat/behat_navigation.php | 24 ++++++++-- .../tests/behat/change_response.feature | 44 ++++++++++--------- 4 files changed, 53 insertions(+), 33 deletions(-) diff --git a/admin/tool/behat/tests/behat/i_am_on_page.feature b/admin/tool/behat/tests/behat/i_am_on_page.feature index bb04f9e4a4c..43e1869e956 100644 --- a/admin/tool/behat/tests/behat/i_am_on_page.feature +++ b/admin/tool/behat/tests/behat/i_am_on_page.feature @@ -29,6 +29,7 @@ Feature: Use core page resolvers for the I am on the page steps | Course Short name | ECON101 | COURSE | Fundamentals of Economics | | Course idnumber | "2021-econ101" | Course | Fundamentals of Economics | | Forum idnumber | fundamentalsofeconomics | Activity | Add a new discussion | + | Generic activity editing | fundamentalsofeconomics | "Activity editing" | Updating: Forum | Scenario Outline: When I am on an instance logged in as Given the following "categories" exist: @@ -55,6 +56,7 @@ Feature: Use core page resolvers for the I am on the page steps | Course Short name | ECON101 | COURSE | Fundamentals of Economics | | Course idnumber | "2021-econ101" | Course | Fundamentals of Economics | | Forum idnumber | fundamentalsofeconomics | Activity | Add a new discussion | + | Generic activity editing | fundamentalsofeconomics | "Activity editing" | Updating: Forum | Scenario Outline: When I am on a named page Given I log in as "admin" diff --git a/course/tests/behat/activities_edit_completion.feature b/course/tests/behat/activities_edit_completion.feature index c22719accd6..d190a4db554 100644 --- a/course/tests/behat/activities_edit_completion.feature +++ b/course/tests/behat/activities_edit_completion.feature @@ -11,25 +11,23 @@ Feature: Edit completion settings of an activity And the following "activities" exist: | activity | course | idnumber | intro | name | completion | completionview | | page | C1 | p1 | x | TestPage | 2 | 1 | - And I log in as "admin" - And I am on "Course 1" course homepage with editing mode on Scenario: Completion is not locked when the activity has not yet been viewed - Given I click on "Edit settings" "link" in the "TestPage" activity + Given I am on the TestPage "Page Activity editing" page logged in as admin When I expand all fieldsets Then I should see "Completion tracking" And I should not see "Completion options locked" Scenario: Completion is locked after the activity has been viewed - Given I follow "TestPage" - When I follow "Edit settings" + Given I am on the TestPage "Page Activity" page logged in as admin + When I am on the TestPage "Page Activity editing" page And I expand all fieldsets Then I should see "Completion options locked" @javascript Scenario: Pressing the unlock button allows the user to edit completion settings - Given I follow "TestPage" - When I navigate to "Edit settings" in current page administration + Given I am on the TestPage "Page Activity" page logged in as admin + When I am on the TestPage "Page Activity editing" page And I expand all fieldsets And I press "Unlock completion options" Then I should see "Completion options unlocked" @@ -41,8 +39,8 @@ Feature: Edit completion settings of an activity @javascript Scenario: Even when completion is locked, the user can still set the date - Given I follow "TestPage" - When I navigate to "Edit settings" in current page administration + Given I am on the TestPage "Page Activity" page logged in as admin + And I am on the TestPage "Page Activity editing" page And I expand all fieldsets When I click on "id_completionexpected_enabled" "checkbox" And I set the field "id_completionexpected_year" to "2013" diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index de796facf28..252cb6fedef 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -715,10 +715,17 @@ class behat_navigation extends behat_base { * Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'. * * Recognised page names are: - * | Page type | Identifier meaning | description | - * | Category | category idnumber | List of courses in that category. | - * | Course | course shortname | Main course home pag | - * | Activity | activity idnumber | Start page for that activity | + * | Page type | Identifier meaning | description | + * | Category | category idnumber | List of courses in that category. | + * | Course | course shortname | Main course home pag | + * | Activity | activity idnumber | Start page for that activity | + * | Activity editing | activity idnumber | Edit settings page for that activity | + * | [modname] Activity | activity name or idnumber | Start page for that activity | + * | [modname] Activity editing | activity name or idnumber | Edit settings page for that activity | + * + * Examples: + * + * When I am on the "Welcome to ECON101" "forum activity" page logged in as student1 * * @param string $type identifies which type of page this is, e.g. 'Category page'. * @param string $identifier identifies the particular page, e.g. 'test-cat'. @@ -751,6 +758,15 @@ class behat_navigation extends behat_base { } return $cm->url; + case 'activity editing': + $cm = $this->get_course_module_for_identifier($identifier); + if (!$cm) { + throw new Exception('The specified activity with idnumber "' . $identifier . '" does not exist'); + } + return new moodle_url('/course/modedit.php', [ + 'update' => $cm->id, + ]); + default: throw new Exception('Unrecognised core page type "' . $type . '."'); } diff --git a/mod/choice/tests/behat/change_response.feature b/mod/choice/tests/behat/change_response.feature index 765285c7a5b..150e6de9fe0 100644 --- a/mod/choice/tests/behat/change_response.feature +++ b/mod/choice/tests/behat/change_response.feature @@ -4,7 +4,7 @@ Feature: Teacher can choose whether to allow students to change their choice res As a teacher I need to enable the option to change the choice - Scenario: Add a choice activity and complete the activity as a student + Background: Given the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@example.com | @@ -16,34 +16,38 @@ Feature: Teacher can choose whether to allow students to change their choice res | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | - And the following "activity" exists: + + Scenario: Change a choice response as a student + Given the following "activity" exists: | activity | choice | | course | C1 | - | idnumber | choice1 | + | idnumber | Choice name | | name | Choice name | | intro | Choice Description | | section | 1 | | option | Option 1, Option 2 | | allowupdate | 0 | - When I log in as "student1" - And I am on "Course 1" course homepage + When I am on the "Course 1" course page logged in as student1 And I choose "Option 1" from "Choice name" choice activity - Then I should see "Your selection: Option 1" - And I should see "Your choice has been saved" - And "Save my choice" "button" should not exist - And I log out - And I log in as "teacher1" - And I am on "Course 1" course homepage - And I follow "Choice name" - And I follow "Edit settings" - And I set the following fields to these values: - | Allow choice to be updated | Yes | - And I press "Save and display" - And I log out - And I log in as "student1" - And I am on "Course 1" course homepage - And I follow "Choice name" And I should see "Your selection: Option 1" + And I should see "Your choice has been saved" + Then "Save my choice" "button" should not exist + + Scenario: Change a choice response as a student + Given the following "activity" exists: + | activity | choice | + | course | C1 | + | idnumber | Choice name | + | name | Choice name | + | intro | Choice Description | + | section | 1 | + | option | Option 1, Option 2 | + | allowupdate | 1 | + When I am on the "Course 1" course page logged in as student1 + And I choose "Option 1" from "Choice name" choice activity + And I should see "Your selection: Option 1" + And I should see "Your choice has been saved" + Then I should see "Your selection: Option 1" And "Save my choice" "button" should exist And "Remove my choice" "link" should exist And I set the field "Option 2" to "1"