From 353e78765a75fadcafa4d82d445c27f4c51f8ad1 Mon Sep 17 00:00:00 2001 From: gthomas2 Date: Mon, 27 Feb 2017 15:04:37 +0000 Subject: [PATCH] MDL-58052 behat: user session function - use to edit current profile --- .../tests/behat/manipulate_forms.feature | 3 +- .../behat/tests/behat/nasty_strings.feature | 3 +- badges/tests/behat/award_badge.feature | 4 +- .../tests/behat/navigate_course_list.feature | 3 +- lib/behat/behat_base.php | 19 +++++++ .../tests/behat/accessibilitychecker.feature | 18 ++---- .../tests/behat/accessibilityhelper.feature | 6 +- .../plugins/align/tests/behat/align.feature | 9 +-- .../plugins/bold/tests/behat/bold.feature | 6 +- .../charmap/tests/behat/charmap.feature | 3 +- .../plugins/clear/tests/behat/clear.feature | 3 +- .../collapse/tests/behat/collapse.feature | 3 +- .../equation/tests/behat/equation.feature | 6 +- .../plugins/html/tests/behat/html.feature | 3 +- .../plugins/image/tests/behat/image.feature | 6 +- .../plugins/indent/tests/behat/indent.feature | 3 +- .../plugins/italic/tests/behat/italic.feature | 6 +- .../plugins/link/tests/behat/link.feature | 3 +- .../tests/behat/orderedlist.feature | 3 +- .../plugins/strike/tests/behat/strike.feature | 3 +- .../subscript/tests/behat/subscript.feature | 6 +- .../tests/behat/superscript.feature | 6 +- .../plugins/title/tests/behat/title.feature | 3 +- .../underline/tests/behat/underline.feature | 3 +- .../tests/behat/unorderedlist.feature | 3 +- lib/tests/behat/behat_navigation.php | 55 +++++++++++++++++++ tag/tests/behat/collections.feature | 3 +- tag/tests/behat/standard_tags.feature | 6 +- user/tests/behat/name_fields.feature | 4 ++ 29 files changed, 119 insertions(+), 83 deletions(-) diff --git a/admin/tool/behat/tests/behat/manipulate_forms.feature b/admin/tool/behat/tests/behat/manipulate_forms.feature index a26fd203efda2..5f5efdf6f018f 100644 --- a/admin/tool/behat/tests/behat/manipulate_forms.feature +++ b/admin/tool/behat/tests/behat/manipulate_forms.feature @@ -7,8 +7,7 @@ Feature: Forms manipulation @javascript Scenario: Basic forms manipulation Given I log in as "admin" - And I follow "Preferences" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode When I set the field "First name" to "Field value" And I set the field "Select a country" to "Japan" And I set the field "New password" to "TestPass" diff --git a/admin/tool/behat/tests/behat/nasty_strings.feature b/admin/tool/behat/tests/behat/nasty_strings.feature index 69812277a49b3..851ef00f0077c 100644 --- a/admin/tool/behat/tests/behat/nasty_strings.feature +++ b/admin/tool/behat/tests/behat/nasty_strings.feature @@ -10,8 +10,7 @@ Feature: Transform steps arguments | fullname | shortname | category | | Course 1 | C1 | 0 | And I log in as "admin" - And I follow "Preferences" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode Scenario: Use nasty strings on steps arguments When I set the field "Surname" to "$NASTYSTRING1" diff --git a/badges/tests/behat/award_badge.feature b/badges/tests/behat/award_badge.feature index e2f504e2cee47..2b0c928608e33 100644 --- a/badges/tests/behat/award_badge.feature +++ b/badges/tests/behat/award_badge.feature @@ -30,9 +30,7 @@ Feature: Award badges And I should not see "Criteria for this badge have not been set up yet." And I press "Enable access" And I press "Continue" - And I click on "Admin User" "link" - And I choose "Profile" in the open action menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I expand all fieldsets And I set the field "Phone" to "123456789" And I press "Update profile" diff --git a/course/tests/behat/navigate_course_list.feature b/course/tests/behat/navigate_course_list.feature index 41dc9b1aaf61b..acd8219f2473f 100644 --- a/course/tests/behat/navigate_course_list.feature +++ b/course/tests/behat/navigate_course_list.feature @@ -42,8 +42,7 @@ Feature: Browse course list and return back from enrolment page And I press "Save changes" And I log out When I log in as "user2" - And I follow "Preferences" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I expand "Courses" node And I expand "Sample category" node And I follow "Course 1" diff --git a/lib/behat/behat_base.php b/lib/behat/behat_base.php index 04dcb434002a1..e59bb584a815e 100644 --- a/lib/behat/behat_base.php +++ b/lib/behat/behat_base.php @@ -925,4 +925,23 @@ protected function execute($contextapi, $params = array()) { // Look for exceptions. $this->look_for_exceptions(); } + + /** + * Get the actual user in the behat session (note $USER does not correspond to the behat session's user). + * @return mixed + * @throws coding_exception + */ + protected function get_session_user() { + global $DB; + + $sid = $this->getSession()->getCookie('MoodleSession'); + if (empty($sid)) { + throw new coding_exception('failed to get moodle session'); + } + $userid = $DB->get_field('sessions', 'userid', ['sid' => $sid]); + if (empty($userid)) { + throw new coding_exception('failed to get user from seession id '.$sid); + } + return $DB->get_record('user', ['id' => $userid]); + } } diff --git a/lib/editor/atto/plugins/accessibilitychecker/tests/behat/accessibilitychecker.feature b/lib/editor/atto/plugins/accessibilitychecker/tests/behat/accessibilitychecker.feature index 90c53d7dba91a..ffb71fb746288 100644 --- a/lib/editor/atto/plugins/accessibilitychecker/tests/behat/accessibilitychecker.feature +++ b/lib/editor/atto/plugins/accessibilitychecker/tests/behat/accessibilitychecker.feature @@ -5,8 +5,7 @@ Feature: Atto accessibility checker @javascript Scenario: Images with no alt Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "

Some plain text

Some more text

" When I click on "Show more buttons" "button" And I click on "Accessibility checker" "button" @@ -31,8 +30,7 @@ Feature: Atto accessibility checker @javascript Scenario: Low contrast Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "

Hard to read

" When I click on "Show more buttons" "button" And I click on "Accessibility checker" "button" @@ -41,8 +39,7 @@ Feature: Atto accessibility checker @javascript Scenario: No headings Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "

Sweet roll oat cake jelly-o macaroon donut oat cake. Caramels macaroon cookie sweet roll croissant cheesecake candy jelly-o. Gummies sugar plum sugar plum gingerbread dessert. Tiramisu bonbon jujubes danish marshmallow cookie chocolate cake cupcake tiramisu. Bear claw oat cake chocolate bar croissant. Lollipop cookie topping liquorice croissant. Brownie cookie cupcake lollipop cupcake cupcake. Fruitcake dessert sweet biscuit dragée caramels marzipan brownie. Chupa chups gingerbread apple pie cookie liquorice caramels carrot cake cookie gingerbread. Croissant candy jelly beans. Tiramisu apple pie dessert apple pie macaroon soufflé. Brownie powder carrot cake chocolate. Tart applicake croissant dragée macaroon chocolate donut.

Jelly beans gingerbread tootsie roll. Sugar plum tiramisu cotton candy toffee pie cotton candy tiramisu. Carrot cake chocolate bar sesame snaps cupcake cake dessert sweet fruitcake wafer. Marshmallow cupcake gingerbread pie sweet candy canes powder gummi bears. Jujubes cake muffin marshmallow candy jelly beans tootsie roll pie. Gummi bears applicake chocolate cake sweet jelly sesame snaps lollipop lollipop carrot cake. Marshmallow cake jelly beans. Jelly beans sesame snaps muffin halvah cookie ice cream candy canes carrot cake. Halvah donut marshmallow tiramisu. Cookie dessert gummi bears. Sugar plum apple pie jelly beans gummi bears tart chupa chups. Liquorice macaroon gummi bears gummies macaroon marshmallow sweet roll cake topping. Lemon drops caramels pie icing danish. Chocolate cake oat cake dessert halvah danish carrot cake apple pie.

" When I click on "Show more buttons" "button" And I click on "Accessibility checker" "button" @@ -51,8 +48,7 @@ Feature: Atto accessibility checker @javascript Scenario: Merged cells Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "
Dogs that look good in pants
BreedCoolness
PoodleNOT COOL
Doberman
" When I click on "Show more buttons" "button" And I click on "Accessibility checker" "button" @@ -61,8 +57,7 @@ Feature: Atto accessibility checker @javascript Scenario: Table missing row/column headers Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "
Dogs that look good in pants
BreedCoolness
PoodleNOT COOL
DobermanCOOL
" When I click on "Show more buttons" "button" And I click on "Accessibility checker" "button" @@ -71,8 +66,7 @@ Feature: Atto accessibility checker @javascript Scenario: Table missing caption Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "
BreedCoolness
PoodleNOT COOL
DobermanCOOL
" When I click on "Show more buttons" "button" And I click on "Accessibility checker" "button" diff --git a/lib/editor/atto/plugins/accessibilityhelper/tests/behat/accessibilityhelper.feature b/lib/editor/atto/plugins/accessibilityhelper/tests/behat/accessibilityhelper.feature index 8d256d378c057..3d05e6c75214f 100644 --- a/lib/editor/atto/plugins/accessibilityhelper/tests/behat/accessibilityhelper.feature +++ b/lib/editor/atto/plugins/accessibilityhelper/tests/behat/accessibilityhelper.feature @@ -5,8 +5,7 @@ Feature: Atto accessibility helper @javascript Scenario: Images and links Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "

Some plain text

Image 1

Some link text

" And I select the text in the "Description" Atto editor When I click on "Show more buttons" "button" @@ -21,8 +20,7 @@ Feature: Atto accessibility helper @javascript Scenario: Styles Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "

Some plain text

" When I click on "Show more buttons" "button" And I select the text in the "Description" Atto editor diff --git a/lib/editor/atto/plugins/align/tests/behat/align.feature b/lib/editor/atto/plugins/align/tests/behat/align.feature index e6af81b5e89bd..9e3a9009c85e7 100644 --- a/lib/editor/atto/plugins/align/tests/behat/align.feature +++ b/lib/editor/atto/plugins/align/tests/behat/align.feature @@ -5,8 +5,7 @@ Feature: Atto align text @javascript Scenario: Right align some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "

Fascism

" And I click on "Show more buttons" "button" And I select the text in the "Description" Atto editor @@ -22,8 +21,7 @@ Feature: Atto align text @javascript Scenario: Left align some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "

Communism

" And I click on "Show more buttons" "button" And I select the text in the "Description" Atto editor @@ -40,8 +38,7 @@ Feature: Atto align text @javascript Scenario: Center align some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "

United Future

" And I click on "Show more buttons" "button" And I select the text in the "Description" Atto editor diff --git a/lib/editor/atto/plugins/bold/tests/behat/bold.feature b/lib/editor/atto/plugins/bold/tests/behat/bold.feature index 7baf1addcc7f2..98b369b01dd72 100644 --- a/lib/editor/atto/plugins/bold/tests/behat/bold.feature +++ b/lib/editor/atto/plugins/bold/tests/behat/bold.feature @@ -5,8 +5,7 @@ Feature: Atto bold button @javascript Scenario: Bold some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "Badger" And I select the text in the "Description" Atto editor When I click on "Bold" "button" @@ -21,8 +20,7 @@ Feature: Atto bold button @javascript Scenario: Unbold some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "Mouse" And I select the text in the "Description" Atto editor When I click on "Bold" "button" diff --git a/lib/editor/atto/plugins/charmap/tests/behat/charmap.feature b/lib/editor/atto/plugins/charmap/tests/behat/charmap.feature index 9da6cc936d98b..2ef4895fee168 100644 --- a/lib/editor/atto/plugins/charmap/tests/behat/charmap.feature +++ b/lib/editor/atto/plugins/charmap/tests/behat/charmap.feature @@ -5,8 +5,7 @@ Feature: Atto charmap button @javascript Scenario: Insert symbols Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "

1980 Mullet

" And I select the text in the "Description" Atto editor When I click on "Show more buttons" "button" diff --git a/lib/editor/atto/plugins/clear/tests/behat/clear.feature b/lib/editor/atto/plugins/clear/tests/behat/clear.feature index 0e63a89fe6a4f..883aaf51c3f40 100644 --- a/lib/editor/atto/plugins/clear/tests/behat/clear.feature +++ b/lib/editor/atto/plugins/clear/tests/behat/clear.feature @@ -5,8 +5,7 @@ Feature: Atto clear button @javascript Scenario: Clear formatting Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "Pisa" And I select the text in the "Description" Atto editor And I click on "Italic" "button" diff --git a/lib/editor/atto/plugins/collapse/tests/behat/collapse.feature b/lib/editor/atto/plugins/collapse/tests/behat/collapse.feature index f6ff8925ca5d0..ef2823be114e2 100644 --- a/lib/editor/atto/plugins/collapse/tests/behat/collapse.feature +++ b/lib/editor/atto/plugins/collapse/tests/behat/collapse.feature @@ -5,8 +5,7 @@ Feature: Atto collapse button @javascript Scenario: Toggle toolbar Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode When I click on "Show more buttons" "button" Then "Equation editor" "button" should be visible And I click on "Show fewer buttons" "button" diff --git a/lib/editor/atto/plugins/equation/tests/behat/equation.feature b/lib/editor/atto/plugins/equation/tests/behat/equation.feature index 9e219a28126d2..eaf0d09ecbfd1 100644 --- a/lib/editor/atto/plugins/equation/tests/behat/equation.feature +++ b/lib/editor/atto/plugins/equation/tests/behat/equation.feature @@ -5,8 +5,7 @@ Feature: Atto equation editor @javascript Scenario: Create an equation Given I log in as "admin" - When I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + When I open my profile in edit mode And I set the field "Description" to "

Equation test

" # Set field on the bottom of page, so equation editor dialogue is visible. And I expand all fieldsets @@ -24,8 +23,7 @@ Feature: Atto equation editor @javascript Scenario: Edit an equation Given I log in as "admin" - When I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + When I open my profile in edit mode And I set the field "Description" to "

\( \pi \)

" # Set field on the bottom of page, so equation editor dialogue is visible. And I expand all fieldsets diff --git a/lib/editor/atto/plugins/html/tests/behat/html.feature b/lib/editor/atto/plugins/html/tests/behat/html.feature index f4a747203e1d7..b67e427ed9b01 100644 --- a/lib/editor/atto/plugins/html/tests/behat/html.feature +++ b/lib/editor/atto/plugins/html/tests/behat/html.feature @@ -5,8 +5,7 @@ Feature: Atto edit HTML @javascript Scenario: Edit the html source Given I log in as "admin" - When I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + When I open my profile in edit mode And I set the field "Description" to "

Smurf

" And I click on "Show more buttons" "button" And I click on "HTML" "button" diff --git a/lib/editor/atto/plugins/image/tests/behat/image.feature b/lib/editor/atto/plugins/image/tests/behat/image.feature index c493d0043b8f2..e66929e736dee 100644 --- a/lib/editor/atto/plugins/image/tests/behat/image.feature +++ b/lib/editor/atto/plugins/image/tests/behat/image.feature @@ -8,8 +8,7 @@ Feature: Add images to Atto And I follow "Manage private files..." And I upload "lib/editor/atto/tests/fixtures/moodle-logo.png" file to "Files" filemanager And I click on "Save changes" "button" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode When I set the field "Description" to "

Image test

" And I select the text in the "Description" Atto editor And I click on "Image" "button" @@ -52,8 +51,7 @@ Feature: Add images to Atto @javascript Scenario: Manually inserting an image Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "

Image: .

" And I select the text in the "Description" Atto editor When I click on "Image" "button" diff --git a/lib/editor/atto/plugins/indent/tests/behat/indent.feature b/lib/editor/atto/plugins/indent/tests/behat/indent.feature index fc4a773e151a0..d9d5c041de236 100644 --- a/lib/editor/atto/plugins/indent/tests/behat/indent.feature +++ b/lib/editor/atto/plugins/indent/tests/behat/indent.feature @@ -22,8 +22,7 @@ Feature: Indent text in Atto @javascript Scenario: Indent and outdent Given I log in as "admin" - And I follow "Profile" in the user menu - When I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "

I need some space.

" And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" diff --git a/lib/editor/atto/plugins/italic/tests/behat/italic.feature b/lib/editor/atto/plugins/italic/tests/behat/italic.feature index 01770e6174aae..6449ef51f1524 100644 --- a/lib/editor/atto/plugins/italic/tests/behat/italic.feature +++ b/lib/editor/atto/plugins/italic/tests/behat/italic.feature @@ -5,8 +5,7 @@ Feature: Atto italic button @javascript Scenario: Italicise some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "Tower of Pisa" And I select the text in the "Description" Atto editor When I click on "Italic" "button" @@ -21,8 +20,7 @@ Feature: Atto italic button @javascript Scenario: Toggle italics in some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "GHD - for hair" And I select the text in the "Description" Atto editor When I click on "Italic" "button" diff --git a/lib/editor/atto/plugins/link/tests/behat/link.feature b/lib/editor/atto/plugins/link/tests/behat/link.feature index f9487330ee2bb..89fb46e1ffac8 100644 --- a/lib/editor/atto/plugins/link/tests/behat/link.feature +++ b/lib/editor/atto/plugins/link/tests/behat/link.feature @@ -8,8 +8,7 @@ Feature: Add links to Atto And I follow "Manage private files..." And I upload "lib/editor/atto/tests/fixtures/moodle-logo.png" file to "Files" filemanager And I click on "Save changes" "button" - When I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + When I open my profile in edit mode And I set the field "Description" to "Super cool" And I select the text in the "Description" Atto editor And I click on "Link" "button" diff --git a/lib/editor/atto/plugins/orderedlist/tests/behat/orderedlist.feature b/lib/editor/atto/plugins/orderedlist/tests/behat/orderedlist.feature index 0eddcfacdc6d0..9660494e09402 100644 --- a/lib/editor/atto/plugins/orderedlist/tests/behat/orderedlist.feature +++ b/lib/editor/atto/plugins/orderedlist/tests/behat/orderedlist.feature @@ -5,8 +5,7 @@ Feature: Atto ordered list button @javascript Scenario: Make a list from some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "Have you heard the news everyone's talking
Life is good 'cause everything's awesome
" And I select the text in the "Description" Atto editor When I click on "Ordered list" "button" diff --git a/lib/editor/atto/plugins/strike/tests/behat/strike.feature b/lib/editor/atto/plugins/strike/tests/behat/strike.feature index 26ad2bf221de2..57c55ea8f2f8e 100644 --- a/lib/editor/atto/plugins/strike/tests/behat/strike.feature +++ b/lib/editor/atto/plugins/strike/tests/behat/strike.feature @@ -5,8 +5,7 @@ Feature: Atto strike button @javascript Scenario: Strike some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "MUA" And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" diff --git a/lib/editor/atto/plugins/subscript/tests/behat/subscript.feature b/lib/editor/atto/plugins/subscript/tests/behat/subscript.feature index ac629cebdeb35..bce4211ed7f01 100644 --- a/lib/editor/atto/plugins/subscript/tests/behat/subscript.feature +++ b/lib/editor/atto/plugins/subscript/tests/behat/subscript.feature @@ -5,8 +5,7 @@ Feature: Atto subscript button @javascript Scenario: Subscript some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "Submarine" And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" @@ -22,8 +21,7 @@ Feature: Atto subscript button @javascript Scenario: Subscript some text in enclosed in superscript Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "Submarine" And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" diff --git a/lib/editor/atto/plugins/superscript/tests/behat/superscript.feature b/lib/editor/atto/plugins/superscript/tests/behat/superscript.feature index 44dd8715ec89d..ecf294ffb93e2 100644 --- a/lib/editor/atto/plugins/superscript/tests/behat/superscript.feature +++ b/lib/editor/atto/plugins/superscript/tests/behat/superscript.feature @@ -5,8 +5,7 @@ Feature: Atto superscript button @javascript Scenario: Subscript some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "Helicopter" And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" @@ -22,8 +21,7 @@ Feature: Atto superscript button @javascript Scenario: Superscript some text that is enclosed in subscript Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "Helicopter" And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" diff --git a/lib/editor/atto/plugins/title/tests/behat/title.feature b/lib/editor/atto/plugins/title/tests/behat/title.feature index f145be3f62828..1a62aad9a7083 100644 --- a/lib/editor/atto/plugins/title/tests/behat/title.feature +++ b/lib/editor/atto/plugins/title/tests/behat/title.feature @@ -5,8 +5,7 @@ Feature: Atto title @javascript Scenario: Create a heading Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "How The Rock Has Made the WWE World Heavyweight Title More Important Than Ever" And I select the text in the "Description" Atto editor When I click on "Paragraph styles" "button" diff --git a/lib/editor/atto/plugins/underline/tests/behat/underline.feature b/lib/editor/atto/plugins/underline/tests/behat/underline.feature index 5733155c0b65f..2a09ba11b7917 100644 --- a/lib/editor/atto/plugins/underline/tests/behat/underline.feature +++ b/lib/editor/atto/plugins/underline/tests/behat/underline.feature @@ -5,8 +5,7 @@ Feature: Atto underline button @javascript Scenario: Underline some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "Deprecated HTML Tag" And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" diff --git a/lib/editor/atto/plugins/unorderedlist/tests/behat/unorderedlist.feature b/lib/editor/atto/plugins/unorderedlist/tests/behat/unorderedlist.feature index 545ed08d7a0f2..16d4fe4a0dcc3 100644 --- a/lib/editor/atto/plugins/unorderedlist/tests/behat/unorderedlist.feature +++ b/lib/editor/atto/plugins/unorderedlist/tests/behat/unorderedlist.feature @@ -5,8 +5,7 @@ Feature: Atto unordered list button @javascript Scenario: Make a list from some text Given I log in as "admin" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I set the field "Description" to "Things, dogs, clogs, they're awesome
Rocks, clocks, and socks, they're awesome
Figs, and wigs, and twigs, that's awesome
Everything you see or think or say is awesome" And I select the text in the "Description" Atto editor When I click on "Unordered list" "button" diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index a5b375696521b..f49fdfbd750d0 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -533,4 +533,59 @@ public function i_navigate_to_in_site_administration($nodetext) { $lastnode = array_pop($parentnodes); $this->select_node_in_navigation($lastnode, $parentnodes); } + + /** + * Opens the current users profile page in edit mode. + * + * @Given /^I open my profile in edit mode$/ + * @throws coding_exception + * @return void + */ + public function i_open_my_profile_in_edit_mode() { + global $USER; + + $user = $this->get_session_user(); + $globuser = $USER; + $USER = $user; // We need this set to the behat session user so we can call isloggedin. + + $systemcontext = context_system::instance(); + + $bodynode = $this->find('xpath', 'body'); + $bodyclass = $bodynode->getAttribute('class'); + $matches = []; + if (preg_match('/(?<=^course-|\scourse-)\d/', $bodyclass, $matches) && !empty($matches)) { + $courseid = intval($matches[0]); + } else { + $courseid = SITEID; + } + + if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) { + if (is_siteadmin($user) || has_capability('moodle/user:update', $systemcontext)) { + $url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => SITEID, + 'returnto' => 'profile')); + } else if (has_capability('moodle/user:editownprofile', $systemcontext)) { + $userauthplugin = false; + if (!empty($user->auth)) { + $userauthplugin = get_auth_plugin($user->auth); + } + if ($userauthplugin && $userauthplugin->can_edit_profile()) { + $url = $userauthplugin->edit_profile_url(); + if (empty($url)) { + if (empty($course)) { + $url = new moodle_url('/user/edit.php', array('id' => $user->id, 'returnto' => 'profile')); + } else { + $url = new moodle_url('/user/edit.php', array('id' => $user->id, 'course' => $courseid, + 'returnto' => 'profile')); + } + } + + } + } + $this->getSession()->visit($this->locate_path($url->out_as_local_url())); + } + + // Restore global user variable. + $USER = $globuser; + } + } diff --git a/tag/tests/behat/collections.feature b/tag/tests/behat/collections.feature index 9ef942c1099b4..6e4dc2d3f23e1 100644 --- a/tag/tests/behat/collections.feature +++ b/tag/tests/behat/collections.feature @@ -85,8 +85,7 @@ Feature: Managers can create and manage tag collections And I log out Scenario: Moving tags when changing tag collections - And I follow "Preferences" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I expand all fieldsets And I set the field "List of interests" to "Swimming, Tag0, Tag3" And I press "Update profile" diff --git a/tag/tests/behat/standard_tags.feature b/tag/tests/behat/standard_tags.feature index 465c8ed181885..1e866e5dbee52 100644 --- a/tag/tests/behat/standard_tags.feature +++ b/tag/tests/behat/standard_tags.feature @@ -89,8 +89,7 @@ Feature: Manager can add standard tags and change the tag type of existing tags @javascript Scenario: Changing standard tags property of tag area When I log in as "manager1" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I expand all fieldsets And I should not see "Manage standard tags" And I set the following fields to these values: @@ -100,8 +99,7 @@ Feature: Manager can add standard tags and change the tag type of existing tags And I click on "Change standard tag usage" "link" in the "//table[contains(@class,'tag-areas-table')]//tr[contains(.,'User interests')]" "xpath_element" And the field "Change showing standard tags in area User interests" matches value "Don't suggest" And I set the field "Change showing standard tags in area User interests" to "Suggest" - And I follow "Profile" in the user menu - And I click on "Edit profile" "link" in the "region-main" "region" + And I open my profile in edit mode And I expand all fieldsets And I should see "Manage standard tags" And I navigate to "Manage tags" node in "Site administration > Appearance" diff --git a/user/tests/behat/name_fields.feature b/user/tests/behat/name_fields.feature index 96688c7b2c37c..d309ffd7bc496 100644 --- a/user/tests/behat/name_fields.feature +++ b/user/tests/behat/name_fields.feature @@ -27,8 +27,12 @@ Feature: Both first name and surname are always available for every user | username | firstname | lastname | email | | foobar | Foo | Bar | foo@bar.com | And I log in as "foobar" + # UI test covering "I open my profile in edit mode" - + # This should be one of the very few places where we directly call these 2 steps to open the current users profile + # in edit mode, the rest of the time you should use "I open my profile in edit mode" as it is faster. And I follow "Profile" in the user menu And I click on "Edit profile" "link" in the "region-main" "region" + # End UI test covering "I open my profile in edit mode" When I set the field "First name" to " " And I set the field "Surname" to " " And I click on "Update profile" "button"