From c0e9e7e0a0ee6446926943e39f5e26538bf1881d Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Wed, 3 May 2017 07:38:57 +0100 Subject: [PATCH 1/2] MDL-58788 behat: backport of course navigation step These got introduced in master on 3353cfd8c1f0466eb117fc2aa9ce7095bb9952bf / MDL-58265 It will be useful for third party devs sharing feature files between multiple branches. --- .../behat/backported_step_definitions.feature | 29 +++++++++++++++++++ lib/tests/behat/behat_navigation.php | 15 ++++++++++ lib/upgrade.txt | 5 ++++ 3 files changed, 49 insertions(+) create mode 100644 admin/tool/behat/tests/behat/backported_step_definitions.feature diff --git a/admin/tool/behat/tests/behat/backported_step_definitions.feature b/admin/tool/behat/tests/behat/backported_step_definitions.feature new file mode 100644 index 00000000000..4bf25377042 --- /dev/null +++ b/admin/tool/behat/tests/behat/backported_step_definitions.feature @@ -0,0 +1,29 @@ +@tool @tool_behat +Feature: Backported behat step definitions + In order to provide feature file compatibility between multiple Moodle versions + As a developer + I need to be able to use backported steps from newer Moodle versiosn + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | format | + | Course 1 | C101 | topics | + And the following "course enrolments" exist: + | user | course | role | + | student1 | C101 | student | + | teacher1 | C101 | teacher | + + Scenario: I am on the course homepage + When I log in as "student1" + And I am on "Course 1" course homepage + Then I should see "Topic 1" + + @javascript + Scenario: I am on the course homepage + When I log in as "teacher1" + And I am on "Course 1" course homepage + Then I should see "Topic 1" diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index bab8ba1e011..36ee65d978b 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -572,4 +572,19 @@ class behat_navigation extends behat_base { // Restore global user variable. $USER = $globuser; } + + /** + * Opens the course homepage. + * + * @Given /^I am on "(?P(?:[^"]|\\")*)" course homepage$/ + * @throws coding_exception + * @param string $coursefullname The full name of the course. + * @return void + */ + public function i_am_on_course_homepage($coursefullname) { + global $DB; + $course = $DB->get_record("course", array("fullname" => $coursefullname), 'id', MUST_EXIST); + $url = new moodle_url('/course/view.php', ['id' => $course->id]); + $this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); + } } diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 5d779ac636c..64772010701 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -1,6 +1,11 @@ This files describes API changes in core libraries and APIs, information provided here is intended especially for developers. +=== 3.1.6 === + +* Behat compatibility changes are now being documented at + https://docs.moodle.org/dev/Acceptance_testing/Compatibility_changes + === 3.1.5 === * get_user_capability_course() now has an additional parameter 'limit'. This can be used to return a set number of records with From 04f5ebb886e4902886be1e90b93e02d63c0dff78 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Wed, 3 May 2017 17:31:23 +0100 Subject: [PATCH 2/2] MDL-58788 behat: backport of course navigation with editing step --- .../behat/backported_step_definitions.feature | 17 +++++++++++++++-- lib/tests/behat/behat_navigation.php | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/admin/tool/behat/tests/behat/backported_step_definitions.feature b/admin/tool/behat/tests/behat/backported_step_definitions.feature index 4bf25377042..919dcbebb2c 100644 --- a/admin/tool/behat/tests/behat/backported_step_definitions.feature +++ b/admin/tool/behat/tests/behat/backported_step_definitions.feature @@ -15,7 +15,7 @@ Feature: Backported behat step definitions And the following "course enrolments" exist: | user | course | role | | student1 | C101 | student | - | teacher1 | C101 | teacher | + | teacher1 | C101 | editingteacher | Scenario: I am on the course homepage When I log in as "student1" @@ -23,7 +23,20 @@ Feature: Backported behat step definitions Then I should see "Topic 1" @javascript - Scenario: I am on the course homepage + Scenario: I am on the course homepage with JS When I log in as "teacher1" And I am on "Course 1" course homepage Then I should see "Topic 1" + + Scenario: I am on the course homepage with editing + When I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + Then I should see "Topic 1" + And I should see "Add an activity or resource" + + @javascript + Scenario: I am on the course homepage with editing and JS + When I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + Then I should see "Topic 1" + And I should see "Add an activity or resource" \ No newline at end of file diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index 36ee65d978b..67e69a4a639 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -587,4 +587,20 @@ class behat_navigation extends behat_base { $url = new moodle_url('/course/view.php', ['id' => $course->id]); $this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); } + + /** + * Opens the course homepage with editing mode on. + * + * @Given /^I am on "(?P(?:[^"]|\\")*)" course homepage with editing mode on$/ + * @throws coding_exception + * @param string $coursefullname The course full name of the course. + * @return void + */ + public function i_am_on_course_homepage_with_editing_mode_on($coursefullname) { + global $DB; + $course = $DB->get_record("course", array("fullname" => $coursefullname), 'id', MUST_EXIST); + $url = new moodle_url('/course/view.php', ['id' => $course->id]); + $this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); + $this->execute("behat_forms::press_button", get_string('turneditingon')); + } }