From c18481fab80ddb60d24c5d697391d5fecc95dba3 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 20 Jan 2014 15:54:29 +0800 Subject: [PATCH 1/2] MDL-43757 messaging: Behat feature to test participants messaging The new test checks that messages can be sent from the participants block and they can be read when accesing user's recent conversations. --- .../tests/behat/message_participants.feature | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 message/tests/behat/message_participants.feature diff --git a/message/tests/behat/message_participants.feature b/message/tests/behat/message_participants.feature new file mode 100644 index 00000000000..feeb42b0a50 --- /dev/null +++ b/message/tests/behat/message_participants.feature @@ -0,0 +1,39 @@ +@core @core_message +Feature: An user can message course participants + In order to communicate efficiently with my students + As a teacher + I need to message them all + + @javascript + Scenario: An user can message multiple course participants including him/her self + Given the following "users" exists: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + | student1 | Student | 1 | student1@asd.com | + | student2 | Student | 2 | student2@asd.com | + | student3 | Student | 3 | student3@asd.com | + And the following "courses" exists: + | fullname | shortname | format | + | Course 1 | C1 | topics | + And the following "course enrolments" exists: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And I log in as "teacher1" + And I follow "Course 1" + And I follow "Participants" + When I click on "input[type='checkbox']" "css_element" in the "Teacher 1" "table_row" + And I click on "input[type='checkbox']" "css_element" in the "Student 1" "table_row" + And I select "Send a message" from "With selected users..." + And I fill the moodle form with: + | messagebody | Here it is, the message content | + And I press "Preview" + And I press "Send message" + And I follow "Home" + And I expand "My profile" node + And I follow "Messages" + And I select "Recent conversations" from "Message navigation:" + Then I should see "Here it is, the message content" + And I should see "Student 1" + And I click on "this conversation" "link" in the "//div[@class='singlemessage'][contains(., 'Teacher 1')]" "xpath_element" + And I should see "Here it is, the message content" From 9cb75a10bf0942c2b40efccdd6abab8d082d49d7 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 20 Jan 2014 15:58:23 +0800 Subject: [PATCH 2/2] MDL-43757 behat: Allowing the form field guesser to detect TinyMCE It includes 2 more minor fixes: - Escapes values sent to TinyMCE as it was breaking when values contained double quotes. - Adding seconds to the screenshots directory to avoid using the same folder for multiple runs. --- lib/behat/form_field/behat_form_editor.php | 1 + lib/behat/form_field/behat_form_field.php | 18 +++++++++++++++--- lib/tests/behat/behat_hooks.php | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/behat/form_field/behat_form_editor.php b/lib/behat/form_field/behat_form_editor.php index 5773d127368..4f100ac1f10 100644 --- a/lib/behat/form_field/behat_form_editor.php +++ b/lib/behat/form_field/behat_form_editor.php @@ -58,6 +58,7 @@ class behat_form_editor extends behat_form_field { if ($editorid = $this->get_editor_id()) { // Set the value to the iframe and save it to the textarea. + $value = str_replace('"', '\"', $value); $this->session->executeScript(' tinyMCE.get("'.$editorid.'").setContent("' . $value . '"); tinyMCE.get("'.$editorid.'").save(); diff --git a/lib/behat/form_field/behat_form_field.php b/lib/behat/form_field/behat_form_field.php index 8db45793c39..284befd3be5 100644 --- a/lib/behat/form_field/behat_form_field.php +++ b/lib/behat/form_field/behat_form_field.php @@ -114,10 +114,22 @@ class behat_form_field { // Textareas are considered text based elements. $tagname = strtolower($this->field->getTagName()); if ($tagname == 'textarea') { - return false; - } - if ($tagname == 'input') { + if (!$this->running_javascript()) { + return false; + } + + // If there is an iframe with $id + _ifr there a TinyMCE editor loaded. + $xpath = '//iframe[@id="' . $this->field->getAttribute('id') . '_ifr"]'; + if (!$this->session->getPage()->find('xpath', $xpath)) { + + // Generic one if it is a normal textarea. + return false; + } + + $classname = 'behat_form_editor'; + + } else if ($tagname == 'input') { $type = $this->field->getAttribute('type'); switch ($type) { case 'text': diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 23981bff84a..31f621ddc65 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -321,7 +321,7 @@ class behat_hooks extends behat_base { // All the run screenshots in the same parent dir. if (!$screenshotsdirname = self::get_run_screenshots_dir()) { - $screenshotsdirname = self::$screenshotsdirname = date('Ymd_Hi'); + $screenshotsdirname = self::$screenshotsdirname = date('Ymd_His'); $dir = $CFG->behat_screenshots_path . DIRECTORY_SEPARATOR . $screenshotsdirname;