From e3adee555bce683c66f3a77d3d1712cf073cd73c Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Wed, 11 Jun 2014 15:24:30 +0800 Subject: [PATCH] MDL-44871 Atto: Move custom select text step to atto specific step definition. --- lib/behat/form_field/behat_form_field.php | 8 --- .../tests/behat/accessibilityhelper.feature | 6 +- .../plugins/align/tests/behat/align.feature | 6 +- .../plugins/bold/tests/behat/bold.feature | 4 +- .../charmap/tests/behat/charmap.feature | 2 +- .../plugins/clear/tests/behat/clear.feature | 2 +- .../equation/tests/behat/equation.feature | 2 +- .../plugins/image/tests/behat/image.feature | 4 +- .../plugins/indent/tests/behat/indent.feature | 4 +- .../plugins/italic/tests/behat/italic.feature | 4 +- .../plugins/link/tests/behat/link.feature | 2 +- .../plugins/media/tests/behat/media.feature | 2 +- .../tests/behat/orderedlist.feature | 2 +- .../plugins/strike/tests/behat/strike.feature | 2 +- .../subscript/tests/behat/subscript.feature | 2 +- .../tests/behat/superscript.feature | 2 +- .../plugins/table/tests/behat/table.feature | 4 +- .../plugins/title/tests/behat/title.feature | 2 +- .../underline/tests/behat/underline.feature | 2 +- .../tests/behat/unorderedlist.feature | 2 +- .../atto/tests/behat/behat_editor_atto.php | 62 +++++++++++++++++++ lib/tests/behat/behat_forms.php | 29 --------- 22 files changed, 90 insertions(+), 65 deletions(-) create mode 100644 lib/editor/atto/tests/behat/behat_editor_atto.php diff --git a/lib/behat/form_field/behat_form_field.php b/lib/behat/form_field/behat_form_field.php index 6c2392135dc..d97ce537f63 100644 --- a/lib/behat/form_field/behat_form_field.php +++ b/lib/behat/form_field/behat_form_field.php @@ -235,12 +235,4 @@ class behat_form_field { return $this->fieldlocator; } - - /** - * Select all the text in the form field. - * - */ - public function select_text() { - throw new coding_exception('select_text() is not supported for this form field type: ' . get_class($this)); - } } diff --git a/lib/editor/atto/plugins/accessibilityhelper/tests/behat/accessibilityhelper.feature b/lib/editor/atto/plugins/accessibilityhelper/tests/behat/accessibilityhelper.feature index 3762a17b764..92dc58e13e4 100644 --- a/lib/editor/atto/plugins/accessibilityhelper/tests/behat/accessibilityhelper.feature +++ b/lib/editor/atto/plugins/accessibilityhelper/tests/behat/accessibilityhelper.feature @@ -8,7 +8,7 @@ Feature: Atto accessibility helper And I follow "Admin User" And I follow "Edit profile" And I set the field "Description" to "

Some plain text

Image 1

Some link text

" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor When I click on "Show more buttons" "button" And I click on "Screenreader helper" "button" Then I should see "Links in text editor" @@ -25,10 +25,10 @@ Feature: Atto accessibility helper And I follow "Edit profile" 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" field + And I select the text in the "Description" Atto editor And I click on "Unordered list" "button" And I click on "Screenreader helper" "button" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor # This shows the current HTML tags applied to the selected text. # This is required because they are not always read by a screen reader. Then I should see "UL, LI" diff --git a/lib/editor/atto/plugins/align/tests/behat/align.feature b/lib/editor/atto/plugins/align/tests/behat/align.feature index 51515a6af6c..893fcdbe7ce 100644 --- a/lib/editor/atto/plugins/align/tests/behat/align.feature +++ b/lib/editor/atto/plugins/align/tests/behat/align.feature @@ -10,7 +10,7 @@ Feature: Atto align text And I set the field "Description" to "

Fascism

" And I set the field "Text editor" to "Plain text area" And I click on "Show more buttons" "button" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor When I click on "Right align" "button" And I press "Update profile" And I follow "Edit profile" @@ -24,7 +24,7 @@ Feature: Atto align text And I set the field "Description" to "

Communism

" And I set the field "Text editor" to "Plain text area" And I click on "Show more buttons" "button" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor When I click on "Right align" "button" And I click on "Left align" "button" And I press "Update profile" @@ -39,7 +39,7 @@ Feature: Atto align text And I set the field "Description" to "

United Future

" And I set the field "Text editor" to "Plain text area" And I click on "Show more buttons" "button" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor When I click on "Center" "button" And I press "Update profile" And I follow "Edit profile" diff --git a/lib/editor/atto/plugins/bold/tests/behat/bold.feature b/lib/editor/atto/plugins/bold/tests/behat/bold.feature index 0a1b49a113e..3aef641972a 100644 --- a/lib/editor/atto/plugins/bold/tests/behat/bold.feature +++ b/lib/editor/atto/plugins/bold/tests/behat/bold.feature @@ -9,7 +9,7 @@ Feature: Atto bold button And I follow "Edit profile" And I set the field "Text editor" to "Plain text area" And I set the field "Description" to "Badger" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor When I click on "Bold" "button" And I press "Update profile" And I follow "Edit profile" @@ -22,7 +22,7 @@ Feature: Atto bold button And I follow "Edit profile" And I set the field "Text editor" to "Plain text area" And I set the field "Description" to "Mouse" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor When I click on "Bold" "button" And I click on "Bold" "button" And I press "Update profile" diff --git a/lib/editor/atto/plugins/charmap/tests/behat/charmap.feature b/lib/editor/atto/plugins/charmap/tests/behat/charmap.feature index eb5828ff87e..b68fddf2e52 100644 --- a/lib/editor/atto/plugins/charmap/tests/behat/charmap.feature +++ b/lib/editor/atto/plugins/charmap/tests/behat/charmap.feature @@ -9,7 +9,7 @@ Feature: Atto charmap button And I follow "Edit profile" And I set the field "Text editor" to "Plain text area" And I set the field "Description" to "

1980 Mullet

" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor When I click on "Show more buttons" "button" And I click on "Insert character" "button" And I click on "copyright sign" "button" diff --git a/lib/editor/atto/plugins/clear/tests/behat/clear.feature b/lib/editor/atto/plugins/clear/tests/behat/clear.feature index 59e38f90bff..18483996611 100644 --- a/lib/editor/atto/plugins/clear/tests/behat/clear.feature +++ b/lib/editor/atto/plugins/clear/tests/behat/clear.feature @@ -10,7 +10,7 @@ Feature: Atto clear button And I set the field "Text editor" to "Plain text area" And I set the field "Description" to "

Pisa

" When I click on "Show more buttons" "button" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor And I click on "Clear formatting" "button" And I press "Update profile" And I follow "Edit profile" diff --git a/lib/editor/atto/plugins/equation/tests/behat/equation.feature b/lib/editor/atto/plugins/equation/tests/behat/equation.feature index 31474091f1e..39754bbc2f7 100644 --- a/lib/editor/atto/plugins/equation/tests/behat/equation.feature +++ b/lib/editor/atto/plugins/equation/tests/behat/equation.feature @@ -8,7 +8,7 @@ Feature: Atto equation editor When I follow "Admin User" And I follow "Edit profile" And I set the field "Description" to "

Equation test

" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" And I click on "Equation editor" "button" And I set the field "Edit equation using" to " = 1 \div 0" diff --git a/lib/editor/atto/plugins/image/tests/behat/image.feature b/lib/editor/atto/plugins/image/tests/behat/image.feature index 566cc441863..984e5034103 100644 --- a/lib/editor/atto/plugins/image/tests/behat/image.feature +++ b/lib/editor/atto/plugins/image/tests/behat/image.feature @@ -11,7 +11,7 @@ Feature: Add images to Atto When I follow "Admin User" And I follow "Edit profile" And I set the field "Description" to "

Image test

" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor And I click on "Image" "button" And I click on "Browse repositories..." "button" And I click on "Private files" "link" @@ -23,7 +23,7 @@ Feature: Add images to Atto And I click on "Save image" "button" And I click on "Update profile" "button" And I follow "Edit profile" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor And I click on "Image" "button" Then the field "Describe this image" matches value "It's the Moodle" diff --git a/lib/editor/atto/plugins/indent/tests/behat/indent.feature b/lib/editor/atto/plugins/indent/tests/behat/indent.feature index 5106de839cd..8ef72ab032e 100644 --- a/lib/editor/atto/plugins/indent/tests/behat/indent.feature +++ b/lib/editor/atto/plugins/indent/tests/behat/indent.feature @@ -9,7 +9,7 @@ Feature: Indent text in Atto And I follow "Edit profile" And I set the field "Description" to "

I need some space.

" And I set the field "Text editor" to "Plain text area" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" And I click on "Indent" "button" And I press "Update profile" @@ -23,7 +23,7 @@ Feature: Indent text in Atto And I follow "Edit profile" And I set the field "Description" to "

I need some space.

" And I set the field "Text editor" to "Plain text area" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" And I click on "Indent" "button" And I click on "Outdent" "button" diff --git a/lib/editor/atto/plugins/italic/tests/behat/italic.feature b/lib/editor/atto/plugins/italic/tests/behat/italic.feature index a582132a362..f1fca1d23fb 100644 --- a/lib/editor/atto/plugins/italic/tests/behat/italic.feature +++ b/lib/editor/atto/plugins/italic/tests/behat/italic.feature @@ -9,7 +9,7 @@ Feature: Atto italic button And I follow "Edit profile" And I set the field "Description" to "Tower of Pisa" And I set the field "Text editor" to "Plain text area" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor When I click on "Italic" "button" And I press "Update profile" And I follow "Edit profile" @@ -22,7 +22,7 @@ Feature: Atto italic button And I follow "Edit profile" And I set the field "Description" to "GHD - for hair" And I set the field "Text editor" to "Plain text area" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor When I click on "Italic" "button" And I click on "Italic" "button" And I press "Update profile" diff --git a/lib/editor/atto/plugins/link/tests/behat/link.feature b/lib/editor/atto/plugins/link/tests/behat/link.feature index 00a1e05d457..8edd2e4513b 100644 --- a/lib/editor/atto/plugins/link/tests/behat/link.feature +++ b/lib/editor/atto/plugins/link/tests/behat/link.feature @@ -12,7 +12,7 @@ Feature: Add links to Atto And I follow "Edit profile" And I set the field "Text editor" to "Plain text area" And I set the field "Description" to "Super cool" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor And I click on "Link" "button" And I click on "Browse repositories..." "button" And I click on "Private files" "link" diff --git a/lib/editor/atto/plugins/media/tests/behat/media.feature b/lib/editor/atto/plugins/media/tests/behat/media.feature index a8eff24ec76..d0d993dd359 100644 --- a/lib/editor/atto/plugins/media/tests/behat/media.feature +++ b/lib/editor/atto/plugins/media/tests/behat/media.feature @@ -13,7 +13,7 @@ Feature: Add media to Atto And I expand "Blogs" node And I follow "Add a new entry" And I set the field "Blog entry body" to "

Media test

" - And I select the text in the "Blog entry body" field + And I select the text in the "Blog entry body" Atto editor And I set the field "Entry title" to "The best video in the entire world (not really)" And I click on "Media" "button" And I click on "Browse repositories..." "button" diff --git a/lib/editor/atto/plugins/orderedlist/tests/behat/orderedlist.feature b/lib/editor/atto/plugins/orderedlist/tests/behat/orderedlist.feature index 8b85d903ca4..38140c3d397 100644 --- a/lib/editor/atto/plugins/orderedlist/tests/behat/orderedlist.feature +++ b/lib/editor/atto/plugins/orderedlist/tests/behat/orderedlist.feature @@ -9,7 +9,7 @@ Feature: Atto ordered list button And I follow "Edit profile" And I set the field "Description" to "Have you heard the news everyone's talking
Life is good 'cause everything's awesome
" And I set the field "Text editor" to "Plain text area" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor When I click on "Ordered list" "button" And I press "Update profile" And I follow "Edit profile" diff --git a/lib/editor/atto/plugins/strike/tests/behat/strike.feature b/lib/editor/atto/plugins/strike/tests/behat/strike.feature index 7eac7b50f99..c56f5297792 100644 --- a/lib/editor/atto/plugins/strike/tests/behat/strike.feature +++ b/lib/editor/atto/plugins/strike/tests/behat/strike.feature @@ -9,7 +9,7 @@ Feature: Atto strike button And I follow "Edit profile" And I set the field "Description" to "MUA" And I set the field "Text editor" to "Plain text area" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" When I click on "Strike through" "button" And I press "Update profile" diff --git a/lib/editor/atto/plugins/subscript/tests/behat/subscript.feature b/lib/editor/atto/plugins/subscript/tests/behat/subscript.feature index c918ad65986..9dbc8e7376b 100644 --- a/lib/editor/atto/plugins/subscript/tests/behat/subscript.feature +++ b/lib/editor/atto/plugins/subscript/tests/behat/subscript.feature @@ -9,7 +9,7 @@ Feature: Atto subscript button And I follow "Edit profile" And I set the field "Description" to "Submarine" And I set the field "Text editor" to "Plain text area" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" When I click on "Subscript" "button" And I press "Update profile" diff --git a/lib/editor/atto/plugins/superscript/tests/behat/superscript.feature b/lib/editor/atto/plugins/superscript/tests/behat/superscript.feature index ed3e0c9a497..cf9a563b3bd 100644 --- a/lib/editor/atto/plugins/superscript/tests/behat/superscript.feature +++ b/lib/editor/atto/plugins/superscript/tests/behat/superscript.feature @@ -9,7 +9,7 @@ Feature: Atto superscript button And I follow "Edit profile" And I set the field "Description" to "Helicopter" And I set the field "Text editor" to "Plain text area" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" When I click on "Superscript" "button" And I press "Update profile" diff --git a/lib/editor/atto/plugins/table/tests/behat/table.feature b/lib/editor/atto/plugins/table/tests/behat/table.feature index 8b79bcb393b..857d36a5527 100644 --- a/lib/editor/atto/plugins/table/tests/behat/table.feature +++ b/lib/editor/atto/plugins/table/tests/behat/table.feature @@ -11,7 +11,7 @@ Feature: Atto tables And I follow "Add a new entry" And I set the field "Entry title" to "How to make a table" And I set the field "Blog entry body" to "Table test" - And I select the text in the "Blog entry body" field + And I select the text in the "Blog entry body" Atto editor And I click on "Show more buttons" "button" When I click on "Table" "button" And I set the field "Caption" to "Dinner" @@ -28,7 +28,7 @@ Feature: Atto tables And I follow "Add a new entry" And I set the field "Entry title" to "How to make a table" And I set the field "Blog entry body" to "
Cell
" - And I select the text in the "Blog entry body" field + And I select the text in the "Blog entry body" Atto editor And I click on "Show more buttons" "button" And I click on "Table" "button" And I click on "Edit table" "link" diff --git a/lib/editor/atto/plugins/title/tests/behat/title.feature b/lib/editor/atto/plugins/title/tests/behat/title.feature index 900f0da222a..896a1249c08 100644 --- a/lib/editor/atto/plugins/title/tests/behat/title.feature +++ b/lib/editor/atto/plugins/title/tests/behat/title.feature @@ -9,7 +9,7 @@ Feature: Atto title And I follow "Edit profile" And I set the field "Text editor" to "Plain text area" 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" field + And I select the text in the "Description" Atto editor When I click on "Paragraph styles" "button" When I click on "Heading 1" "link" And I press "Update profile" diff --git a/lib/editor/atto/plugins/underline/tests/behat/underline.feature b/lib/editor/atto/plugins/underline/tests/behat/underline.feature index ffc56a751c6..a16913e356c 100644 --- a/lib/editor/atto/plugins/underline/tests/behat/underline.feature +++ b/lib/editor/atto/plugins/underline/tests/behat/underline.feature @@ -9,7 +9,7 @@ Feature: Atto underline button And I follow "Edit profile" And I set the field "Description" to "Deprecated HTML Tag" And I set the field "Text editor" to "Plain text area" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" When I click on "Underline" "button" And I press "Update profile" diff --git a/lib/editor/atto/plugins/unorderedlist/tests/behat/unorderedlist.feature b/lib/editor/atto/plugins/unorderedlist/tests/behat/unorderedlist.feature index f148bb9dfc9..38211117c9d 100644 --- a/lib/editor/atto/plugins/unorderedlist/tests/behat/unorderedlist.feature +++ b/lib/editor/atto/plugins/unorderedlist/tests/behat/unorderedlist.feature @@ -9,7 +9,7 @@ Feature: Atto unordered list button And I follow "Edit profile" 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 set the field "Text editor" to "Plain text area" - And I select the text in the "Description" field + And I select the text in the "Description" Atto editor When I click on "Unordered list" "button" And I press "Update profile" And I follow "Edit profile" diff --git a/lib/editor/atto/tests/behat/behat_editor_atto.php b/lib/editor/atto/tests/behat/behat_editor_atto.php new file mode 100644 index 00000000000..91723d841fb --- /dev/null +++ b/lib/editor/atto/tests/behat/behat_editor_atto.php @@ -0,0 +1,62 @@ +. + +/** + * Atto custom steps definitions. + * + * @package editor_atto + * @category test + * @copyright 2014 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. + +/** + * Steps definitions to deal with the atto text editor + * + * @package editor_atto + * @category test + * @copyright 2014 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_editor_atto extends behat_base { + + /** + * Select the text in an Atto field. + * + * @Given /^I select the text in the "([^"]*)" Atto editor$/ + * @throws ElementNotFoundException Thrown by behat_base::find + * @param string $field + * @return void + */ + public function select_the_text_in_the_atto_editor($fieldlocator) { + if (!$this->running_javascript()) { + throw new coding_exception('Selecting text requires javascript.'); + } + // We delegate to behat_form_field class, it will + // guess the type properly. + $field = behat_field_manager::get_form_field_from_label($fieldlocator, $this); + + if (!method_exists($field, 'select_text')) { + throw new coding_exception('Field does not support the select_text function.'); + } + $field->select_text(); + } + + +} + diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index a0af7f7031c..b686efbdc6d 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -155,18 +155,6 @@ class behat_forms extends behat_base { $this->set_field_value($field, $value); } - /** - * Select all the text in a field. - * - * @Given /^I select the text in the "([^"]*)" field$/ - * @throws ElementNotFoundException Thrown by behat_base::find - * @param string $field - * @return void - */ - public function i_select_the_text_in_the_field($field) { - $this->select_text($field); - } - /** * Checks, the field matches the value. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps. * @@ -344,23 +332,6 @@ class behat_forms extends behat_base { } } - /** - * Call select_text on the field. - * - * Internal API method, a generic *I select the text in the "FIELD" field* - * is based on it. - * - * @param string $fieldlocator The pointer to the field, it will depend on the field type. - * @return void - */ - protected function select_text($fieldlocator) { - - // We delegate to behat_form_field class, it will - // guess the type properly. - $field = behat_field_manager::get_form_field_from_label($fieldlocator, $this); - $field->select_text(); - } - /** * Generic field setter. *