diff --git a/htdocs/testing/frameworks/behat/classes/BehatForms.php b/htdocs/testing/frameworks/behat/classes/BehatForms.php index b7db2ad293011fd873d5daf21c396bfcda3322bf..e1fde3359fc3073acf362badb2ec01db2bf59e2e 100644 --- a/htdocs/testing/frameworks/behat/classes/BehatForms.php +++ b/htdocs/testing/frameworks/behat/classes/BehatForms.php @@ -93,13 +93,13 @@ class BehatForms extends BehatBase { } /** - * Selects a list of values in a select2 multiple-select field + * Fills in Select2 field with specified * - * @When /^I set the select2 field "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)"$/ + * @When /^(?:|I )set the select2 field "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)"$/ + * @When /^(?:|I )set the select2 value "(?P(?:[^"]|\\")*)" for "(?P(?:[^"]|\\")*)"$/ */ - public function i_set_the_select2_field_to($field, $textValues) { + public function iFillInSelect2Field($field, $textValues) { $page = $this->getSession()->getPage(); - $values = []; foreach(preg_split('/,\s*/', $textValues) as $value) { $option = $page->find('xpath', '//select[@id="' . $field . '"]//option[text()="' . $value . '"]'); @@ -109,6 +109,88 @@ class BehatForms extends BehatBase { $values = json_encode($values); $this->getSession()->executeScript("jQuery('#{$field}').val({$values}).trigger('change');"); } + /** + * Fill Select2 input field + * + * @When /^(?:|I )fill in select2 input "(?P(?:[^"]|\\")*)" with "(?P(?:[^"]|\\")*)"$/ + */ + public function iFillInSelect2InputWith($field, $value) { + $page = $this->getSession()->getPage(); + $this->select2OpenField($page, $field); + $this->select2FillSearchField($page, $field, $value); + } + /** + * Fill Select2 input field and select a value + * + * @When /^(?:|I )fill in select2 input "(?P(?:[^"]|\\")*)" with "(?P(?:[^"]|\\")*)" and select "(?P(?:[^"]|\\")*)"$/ + */ + public function iFillInSelect2InputWithAndSelect($field, $value, $entry) { + $page = $this->getSession()->getPage(); + $this->select2OpenField($page, $field); + $this->select2FillSearchField($page, $field, $value); + $this->select2Value($page, $field, $entry); + $this->getSession()->executeScript("jQuery('#{$field}').trigger('change');"); + } + /** + * Open Select2 choice list + * + * @param DocumentElement $page + * @param string $field + * @throws \Exception + */ + private function select2OpenField($page, $field) { + $fieldName = sprintf('#%s', $field); + $inputField = $page->find('css', $fieldName); + if (!$inputField) { + throw new \Exception(sprintf('No field "%s" found', $field)); + } + $choice = $inputField->getParent()->find('css', '.select2-selection'); + if (!$choice) { + throw new \Exception(sprintf('No select2 choice found for "%s"', $field)); + } + $choice->press(); + } + /** + * Fill Select2 search field + * + * @param DocumentElement $page + * @param string $field + * @param string $value + * @throws \Exception + */ + private function select2FillSearchField($page, $field, $value) { + $driver = $this->getSession()->getDriver(); + if ('MaharaSelenium2Driver' === get_class($driver)) { + // Can't use $this->getSession()->getPage()->find() because of https://github.com/minkphp/MinkSelenium2Driver/issues/188 + $select2Input = $this->getSession()->getDriver()->getWebDriverSession()->element('xpath', "//html/descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' select2-search__field ')]"); + if (!$select2Input) { + throw new \Exception(sprintf('No field "%s" found', $field)); + } + $select2Input->postValue(['value' => [$value]]); + } + else { + throw new \Exception(sprintf('Not able to select via ajax. Need MaharaSelenium2Driver')); + } + $this->getSession()->wait(10000, "(jQuery('#select2-{$field}-results .loading-results').length === 0)"); + } + /** + * Select value in choice list + * + * @param DocumentElement $page + * @param string $field + * @param string $value + * @throws \Exception + */ + private function select2Value($page, $field, $value) { + $chosenResults = $page->findAll('css', '.select2-results ul li'); + foreach ($chosenResults as $result) { + if ($result->getText() == $value) { + $result->click(); + return; + } + } + throw new \Exception(sprintf('Value "%s" not found for "%s"', $value, $field)); + } /** * Checks, the field matches the value. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps. diff --git a/test/behat/features/artefact/collections/page_number_interval_sharedwithme.feature b/test/behat/features/artefact/collections/page_number_interval_sharedwithme.feature index 273955aa74fa1b5686c81988162c06675dc0c41c..bc28b337142d08763e67e5414c36c769012e798f 100644 --- a/test/behat/features/artefact/collections/page_number_interval_sharedwithme.feature +++ b/test/behat/features/artefact/collections/page_number_interval_sharedwithme.feature @@ -38,7 +38,7 @@ And I follow "A's Page 01" And I follow "Edit this page" And I follow "Share page" - And I set the select2 field "editaccess_views" to "A's Page 01, A's Page 02, A's Page 03, A's Page 04, A's Page 05, A's Page 06, A's Page 07, A's Page 08, A's Page 09, A's Page 10, A's Page 11, A's Page 12, A's Page 13, A's Page 14, A's Page 15, A's Page 16, A's Page 17, A's Page 18, A's Page 19, A's Page 20, A's Page 21" + And I set the select2 value "A's Page 01, A's Page 02, A's Page 03, A's Page 04, A's Page 05, A's Page 06, A's Page 07, A's Page 08, A's Page 09, A's Page 10, A's Page 11, A's Page 12, A's Page 13, A's Page 14, A's Page 15, A's Page 16, A's Page 17, A's Page 18, A's Page 19, A's Page 20, A's Page 21" for "editaccess_views" And I select "Public" from "accesslist[0][searchtype]" And I press "editaccess_submit" And I follow "Logout" diff --git a/test/behat/features/group/group_view_block.feature b/test/behat/features/group/group_view_block.feature index 9492b4cf90209f94a6785632279028dfa97db232..17a1d49dc86e81006bae27fb18973d42e86adc06 100644 --- a/test/behat/features/group/group_view_block.feature +++ b/test/behat/features/group/group_view_block.feature @@ -69,7 +69,7 @@ These list must take into account the sort option choosen in the block config (B And I choose "Shared by me" in "Portfolio" And I follow "Pages" in the "div#main-column-container" "css_element" And I click on "Edit access" in "Page userA_01" row - And I set the select2 field "editaccess_views" to "Page userA_01, Page userA_02, Page userA_03, Page userA_04, Page userA_05" + And I set the select2 value "Page userA_01, Page userA_02, Page userA_03, Page userA_04, Page userA_05" for "editaccess_views" And I select "Group Z" from "accesslist[0][searchtype]" And I press "Save" # Edit access for Collection userA_01 @@ -77,7 +77,7 @@ These list must take into account the sort option choosen in the block config (B And I follow "Collections" in the "div#main-column-container" "css_element" And I click on "Edit access" in "Collection userA_01" row And I should not see "Collection userA_02" in the "ul.select2-selection__rendered" "css_element" - And I set the select2 field "editaccess_collections" to "Collection userA_01, Collection userA_02, Collection userA_03, Collection userA_04, Collection userA_05, Collection userA_06" + And I set the select2 value "Collection userA_01, Collection userA_02, Collection userA_03, Collection userA_04, Collection userA_05, Collection userA_06" for "editaccess_collections" And I select "Group Z" from "accesslist[0][searchtype]" And I press "Save" And I log out @@ -90,7 +90,7 @@ These list must take into account the sort option choosen in the block config (B # Edit access for pages And I choose "Shared by me" in "Portfolio" And I click on "Edit access" in "Page userB_01" row - And I set the select2 field "editaccess_views" to "Page userB_01, Page userB_02, Page userB_03, Page userB_04, Page userB_05, Page userB_06, Page userB_07" + And I set the select2 value "Page userB_01, Page userB_02, Page userB_03, Page userB_04, Page userB_05, Page userB_06, Page userB_07" for "editaccess_views" And I select "Group Z" from "accesslist[0][searchtype]" And I press "Save" And I log out @@ -160,7 +160,7 @@ These list must take into account the sort option choosen in the block config (B And I choose "Portfolio" And I click on "Edit \"Page userA_01\"" And I follow "Edit title and description" - And I set the field "Page description" to "

This is the page 01 (updated)

" + And I set the value "Page description" for "

This is the page 01 (updated)

" And I press "Save" And I follow "Display page" # Check if it is now in the first page of the list of shared pages @@ -174,7 +174,7 @@ These list must take into account the sort option choosen in the block config (B # Update the shared collection "Collection userA_06" And I choose "Collections" in "Portfolio" And I click on "Edit \"Collection userA_06\"" - And I set the field "Collection description" to "This is the collection 06 (updated)" + And I set the value "Collection description" for "This is the collection 06 (updated)" And I press "Save" # Check if it is now in the first page of the list of shared collections And I choose "Groups" diff --git a/test/behat/features/group/shared_views_to_group.feature b/test/behat/features/group/shared_views_to_group.feature index 43ebde5cf4f0df1dbbdd169bc764f69051931583..9f1ee1d06999d6b7a66ce5facc987c3742efe4ea 100644 --- a/test/behat/features/group/shared_views_to_group.feature +++ b/test/behat/features/group/shared_views_to_group.feature @@ -76,14 +76,14 @@ The list of shared pages must take into account of access date (Bug 1374163) # Edit access for Collection 01 And I choose "Shared by me" in "Portfolio" And I click on "Edit access" in "Collection 01" row - And I set the select2 field "editaccess_collections" to "Collection 01" + And I set the select2 value "Collection 01"" for "editaccess_collections" And I select "Group Z" from "accesslist[0][searchtype]" And I set the field "accesslist[0][startdate]" to "2015/06/15 03:00" And I press "Save" # Edit access for Collection 03 And I choose "Shared by me" in "Portfolio" And I click on "Edit access" in "Collection 03" row - And I set the select2 field "editaccess_collections" to "Collection 03" + And I set the select2 value "Collection 03" for "editaccess_collections" And I follow "Advanced options" And I fill in the following: | Access start date/time | 2015/06/15 00:00 | @@ -91,7 +91,7 @@ The list of shared pages must take into account of access date (Bug 1374163) # Edit access for Collection 05 And I choose "Shared by me" in "Portfolio" And I click on "Edit access" in "Collection 05" row - And I set the select2 field "editaccess_collections" to "Collection 05" + And I set the select2 value "Collection 05" for "editaccess_collections" And I select "Group Z" from "accesslist[0][searchtype]" And I press "Save" # Check the list of shared pages to group "Group Z" diff --git a/test/behat/features/messages/send_message.feature b/test/behat/features/messages/send_message.feature new file mode 100644 index 0000000000000000000000000000000000000000..3053bb2f01e5f46dd95122ad5032f43e796ac380 --- /dev/null +++ b/test/behat/features/messages/send_message.feature @@ -0,0 +1,25 @@ +@javascript @core @core_messages +Feature: Select2 ajax test using sendmessage + In order to retrieve data via ajax and select it + As an admin I need to fill in a select2 box + So I can confirm the value is selectable + +Background: + Given the following "users" exist: + | username | password | email | firstname | lastname | institution | authname | role | + | userA | Kupuhipa1 | test01@example.com | Andrea | Andrews | mahara | internal | member | + | userB | Kupuhipa1 | test02@example.com | Barry | Bishop | mahara | internal | member | + | userC | Kupuhipa1 | test03@example.com | Catriona | Carson | mahara | internal | member | + +Scenario: Selecting select2 option via ajax + # Log in as an Admin user + Given I log in as "admin" with password "Kupuhipa1" + # Checking messages + And I follow "mail" + And I follow "Compose" + And I fill in select2 input "sendmessage_recipients" with "userA" and select "Andrea Andrews (userA)" + And I set the following fields to these values: + | Subject | Test message | + | Message | This is a test | + And I press "Send message" + Then I should see "Message sent" \ No newline at end of file diff --git a/test/behat/features/messages/send_multiple_messages.feature b/test/behat/features/messages/send_multiple_messages.feature index c2f85b9dae979aa678749538a4720b3e1c78e8c0..abd9b9df1372828512a3db7e470c4f7371393db8 100644 --- a/test/behat/features/messages/send_multiple_messages.feature +++ b/test/behat/features/messages/send_multiple_messages.feature @@ -1,4 +1,4 @@ -@javascript @core core_messages +@javascript @core @core_messages Feature: Send messages to other users In order to send a message to another user As an admin I need to create an user diff --git a/test/behat/features/user/search_users_by_share_pages.feature b/test/behat/features/user/search_users_by_share_pages.feature index 8f43f4138590fddb48f21590b4a252d037c3cf14..585267d96890c5e09630709b323e44a540c6c333 100644 --- a/test/behat/features/user/search_users_by_share_pages.feature +++ b/test/behat/features/user/search_users_by_share_pages.feature @@ -35,7 +35,7 @@ Scenario: Create users and search for them (Bug 897586) And I should see "Page saved successfully" # Sharing both of the pages that have been created And I follow "Share page" - And I set the select2 field "editaccess_views" to "Testing page 1, Testing page 2" + And I set the select2 value "Testing page 1, Testing page 2" for "editaccess_views" And I select "Public" from "accesslist[0][searchtype]" And I press "Save" # Verifying that both of the pages have been shared @@ -63,7 +63,7 @@ Scenario: Create users and search for them (Bug 897586) And I should see "Page saved successfully" # Sharing both of the pages Jen created And I follow "Share page" - And I set the select2 field "editaccess_views" to "Testing page 3, Testing page 4" + And I set the select2 value "Testing page 3, Testing page 4" for "editaccess_views" And I select "Public" from "accesslist[0][searchtype]" And I press "Save" # Verifying that both of the pages have been shared diff --git a/test/behat/features/view/max_item_limit_sharedwithme.feature b/test/behat/features/view/max_item_limit_sharedwithme.feature index da78618444fa4ea4222182afe460a74df8169113..d713c7acd8aa5b5ce1d05153c12516f1fd164024 100644 --- a/test/behat/features/view/max_item_limit_sharedwithme.feature +++ b/test/behat/features/view/max_item_limit_sharedwithme.feature @@ -69,8 +69,8 @@ As an admin And I follow "A's Page 01" And I follow "Edit this page" And I follow "Share page" - And I set the select2 field "editaccess_views" to "A's Page 01, A's Page 02, A's Page 03, A's Page 04, A's Page 05, A's Page 06, A's Page 07, A's Page 08, A's Page 09, A's Page 10, A's Page 11, A's Page 12, A's Page 13, A's Page 14, A's Page 15, A's Page 16, A's Page 17, A's Page 18, A's Page 19, A's Page 20, A's Page 21, A's Page 22, A's Page 23, A's Page 24, A's Page 25, A's Page 26, A's Page 27, A's Page 28, A's Page 29, A's Page 30, A's Page 31, A's Page 32, A's Page 33, A's Page 34, A's Page 35, A's Page 36, A's Page 37, A's Page 38, A's Page 39, A's Page 40, A's Page 41, A's Page 42, A's Page 43, A's Page 44, A's Page 45, A's Page 46, A's Page 47, A's Page 48, A's Page 49, A's Page 50, A's Page 51" - And I select "Public" from "accesslist[0][searchtype]" + And I set the select2 value ""A's Page 01, A's Page 02, A's Page 03, A's Page 04, A's Page 05, A's Page 06, A's Page 07, A's Page 08, A's Page 09, A's Page 10, A's Page 11, A's Page 12, A's Page 13, A's Page 14, A's Page 15, A's Page 16, A's Page 17, A's Page 18, A's Page 19, A's Page 20, A's Page 21, A's Page 22, A's Page 23, A's Page 24, A's Page 25, A's Page 26, A's Page 27, A's Page 28, A's Page 29, A's Page 30, A's Page 31, A's Page 32, A's Page 33, A's Page 34, A's Page 35, A's Page 36, A's Page 37, A's Page 38, A's Page 39, A's Page 40, A's Page 41, A's Page 42, A's Page 43, A's Page 44, A's Page 45, A's Page 46, A's Page 47, A's Page 48, A's Page 49, A's Page 50, A's Page 51" for "editaccess_views" +And I select "Public" from "accesslist[0][searchtype]" And I press "Save" And I follow "Logout" And I log in as "userB" with password "Kupuhipa1"