From 00ea74cb54dfeba8f57f5e8a5feba049d46a6a6d Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 25 Apr 2013 15:41:24 +0800 Subject: [PATCH] MDL-39348 behat: Chaining strings instead of splitting strings in lines --- admin/tests/behat/behat_admin.php | 8 ++--- backup/util/ui/tests/behat/behat_backup.php | 34 ++++++++++--------- .../tests/behat/behat_block_comments.php | 4 +-- completion/tests/behat/behat_completion.php | 11 ++++-- course/tests/behat/behat_course.php | 14 ++++---- lib/tests/behat/behat_forms.php | 3 +- lib/tests/behat/behat_navigation.php | 21 ++++++------ question/tests/behat/behat_question.php | 8 ++--- repository/tests/behat/behat_filepicker.php | 8 ++--- 9 files changed, 59 insertions(+), 52 deletions(-) diff --git a/admin/tests/behat/behat_admin.php b/admin/tests/behat/behat_admin.php index 97a78a4447743..0cd23064ad4d1 100644 --- a/admin/tests/behat/behat_admin.php +++ b/admin/tests/behat/behat_admin.php @@ -72,11 +72,11 @@ public function i_set_the_following_administration_settings_values(TableNode $ta // Admin settings does not use the same DOM structure than other moodle forms // but we also need to use lib/behat/form_field/* to deal with the different moodle form elements. $exception = new ElementNotFoundException($this->getSession(), '"' . $label . '" administration setting '); - $fieldxpath = "//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')] -[@id=//label[contains(normalize-space(string(.)), '" . $label . "')]/@for]"; + $fieldxpath = "//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]" . + "[@id=//label[contains(normalize-space(string(.)), '" . $label . "')]/@for]"; $fieldnode = $this->find('xpath', $fieldxpath, $exception); - $formfieldtypenode = $this->find('xpath', $fieldxpath . "/ancestor::div[@class='form-setting'] -/child::div[contains(concat(' ', @class, ' '), ' form-')]/child::*/parent::div"); + $formfieldtypenode = $this->find('xpath', $fieldxpath . "/ancestor::div[@class='form-setting']" . + "/child::div[contains(concat(' ', @class, ' '), ' form-')]/child::*/parent::div"); // Getting the class which contains the field type. $classes = explode(' ', $formfieldtypenode->getAttribute('class')); diff --git a/backup/util/ui/tests/behat/behat_backup.php b/backup/util/ui/tests/behat/behat_backup.php index 79c05e126dc99..4d8f4b1155bee 100644 --- a/backup/util/ui/tests/behat/behat_backup.php +++ b/backup/util/ui/tests/behat/behat_backup.php @@ -112,9 +112,9 @@ public function i_import_course_into_course($fromcourse, $tocourse, $options = f $exception = new ExpectationException('"' . $fromcourse . '" course not found in the list of courses to import from', $this->getSession()); $fromcourse = str_replace("'", "\'", $fromcourse); - $xpath = "//div[contains(concat(' ', @class, ' '), ' ics-results ')] -/descendant::tr[contains(., '" . $fromcourse . "')] -/descendant::input[@type='radio']"; + $xpath = "//div[contains(concat(' ', @class, ' '), ' ics-results ')]" . + "/descendant::tr[contains(., '" . $fromcourse . "')]" . + "/descendant::input[@type='radio']"; $radionode = $this->find('xpath', $xpath, $exception); $radionode->check(); $radionode->click(); @@ -152,10 +152,10 @@ public function i_restore_backup_into_course_using_this_options($backupfilename, // Selecting the specified course (we can not call behat_forms::select_radio here as is in another behat subcontext). $existingcourse = str_replace("'", "\'", $existingcourse); - $radionode = $this->find('xpath', "//div[contains(@class, 'bcs-existing-course')] -/descendant::div[@class='restore-course-search'] -/descendant::tr[contains(., '" . $existingcourse . "')] -/descendant::input[@type='radio']"); + $radionode = $this->find('xpath', "//div[contains(@class, 'bcs-existing-course')]" . + "/descendant::div[@class='restore-course-search']" . + "/descendant::tr[contains(., '" . $existingcourse . "')]" . + "/descendant::input[@type='radio']"); $radionode->check(); $radionode->click(); @@ -181,9 +181,9 @@ public function i_restore_backup_into_a_new_course_using_this_options($backupfil $this->select_backup($backupfilename); // The first category in the list. - $radionode = $this->find('xpath', "//div[contains(@class, 'bcs-new-course')] -/descendant::div[@class='restore-course-search'] -/descendant::input[@type='radio']"); + $radionode = $this->find('xpath', "//div[contains(@class, 'bcs-new-course')]" . + "/descendant::div[@class='restore-course-search']" . + "/descendant::input[@type='radio']"); $radionode->check(); $radionode->click(); @@ -209,13 +209,14 @@ public function i_merge_backup_into_the_current_course($backupfilename, $options $this->select_backup($backupfilename); // Merge without deleting radio option. - $radionode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')] -/descendant::input[@type='radio'][@name='target'][@value='1']"); + $radionode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]" . + "/descendant::input[@type='radio'][@name='target'][@value='1']"); $radionode->check(); $radionode->click(); // Pressing the continue button of the restore merging section. - $continuenode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]/descendant::input[@type='submit'][@value='Continue']"); + $continuenode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]" . + "/descendant::input[@type='submit'][@value='Continue']"); $continuenode->click(); $this->wait(); @@ -236,13 +237,14 @@ public function i_merge_backup_into_current_course_deleting_its_contents($backup $this->select_backup($backupfilename); // Delete contents radio option. - $radionode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')] -/descendant::input[@type='radio'][@name='target'][@value='0']"); + $radionode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]" . + "/descendant::input[@type='radio'][@name='target'][@value='0']"); $radionode->check(); $radionode->click(); // Pressing the continue button of the restore merging section. - $continuenode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]/descendant::input[@type='submit'][@value='Continue']"); + $continuenode = $this->find('xpath', "//div[contains(@class, 'bcs-current-course')]" . + "/descendant::input[@type='submit'][@value='Continue']"); $continuenode->click(); $this->wait(); diff --git a/blocks/comments/tests/behat/behat_block_comments.php b/blocks/comments/tests/behat/behat_block_comments.php index 447eb5aaf31a1..548246062a30c 100644 --- a/blocks/comments/tests/behat/behat_block_comments.php +++ b/blocks/comments/tests/behat/behat_block_comments.php @@ -91,8 +91,8 @@ public function i_delete_comment_from_comments_block($comment) { $exception = new ElementNotFoundException($this->getSession(), '"' . $comment . '" comment '); - $commentxpath = "//div[contains(concat(' ', @class, ' '), ' block_comments ')] -/descendant::div[@class='comment-message'][contains(., '" . $comment . "')]"; + $commentxpath = "//div[contains(concat(' ', @class, ' '), ' block_comments ')]" . + "/descendant::div[@class='comment-message'][contains(., '" . $comment . "')]"; $commentnode = $this->find('xpath', $commentxpath, $exception); // Click on delete icon. diff --git a/completion/tests/behat/behat_completion.php b/completion/tests/behat/behat_completion.php index 7bf57fbf48114..ef05aeb328d19 100644 --- a/completion/tests/behat/behat_completion.php +++ b/completion/tests/behat/behat_completion.php @@ -50,7 +50,8 @@ class behat_completion extends behat_base { public function user_has_completed_activity($userfullname, $activityname) { // Will throw an exception if the element can not be hovered. - $xpath = "//table[@id='completion-progress']/descendant::img[contains(@title, '" . $userfullname . ", " . $activityname . ": Completed')]"; + $xpath = "//table[@id='completion-progress']" . + "/descendant::img[contains(@title, '" . $userfullname . ", " . $activityname . ": Completed')]"; return array( new Given('I go to the current course activity completion report'), @@ -67,7 +68,8 @@ public function user_has_completed_activity($userfullname, $activityname) { */ public function user_has_not_completed_activity($userfullname, $activityname) { - $xpath = "//table[@id='completion-progress']/descendant::img[contains(@title, '" . $userfullname . ", " . $activityname . ": Not completed')]"; + $xpath = "//table[@id='completion-progress']" . + "/descendant::img[contains(@title, '" . $userfullname . ", " . $activityname . ": Not completed')]"; return array( new Given('I go to the current course activity completion report'), new Given('I hover "' . $xpath . '" "xpath_element"') @@ -87,7 +89,10 @@ public function go_to_the_current_course_activity_completion_report() { // Expand reports node if we can't see the link. try { - $this->find('xpath', "//*[@id='settingsnav']/descendant::li/descendant::li[not(contains(@class,'collapsed'))]/descendant::p[contains(., 'Activity completion')]"); + $this->find('xpath', "//*[@id='settingsnav']" . + "/descendant::li" . + "/descendant::li[not(contains(@class,'collapsed'))]" . + "/descendant::p[contains(., 'Activity completion')]"); } catch (ElementNotFoundException $e) { $steps[] = new Given('I expand "Reports" node'); } diff --git a/course/tests/behat/behat_course.php b/course/tests/behat/behat_course.php index 71a59b901f63a..532a4629ff0a0 100644 --- a/course/tests/behat/behat_course.php +++ b/course/tests/behat/behat_course.php @@ -126,9 +126,9 @@ public function i_add_to_section($activity, $section) { // Clicks the selected activity if it exists. $activity = ucfirst($activity); - $activityxpath = "//div[@id='chooseform']/descendant::label -/descendant::span[contains(concat(' ', @class, ' '), ' typename ')][contains(.,'" . $activity . "')] -/parent::label/child::input"; + $activityxpath = "//div[@id='chooseform']/descendant::label" . + "/descendant::span[contains(concat(' ', @class, ' '), ' typename ')][contains(.,'" . $activity . "')]" . + "/parent::label/child::input"; $activitynode = $this->find('xpath', $activityxpath); $activitynode->doubleClick(); @@ -136,8 +136,8 @@ public function i_add_to_section($activity, $section) { // Without Javascript. // Selecting the option from the select box which contains the option. - $selectxpath = $sectionxpath . "/descendant::div[contains(concat(' ', @class, ' '), ' section_add_menus ')] -/descendant::select[contains(., '" . $activity . "')]"; + $selectxpath = $sectionxpath . "/descendant::div[contains(concat(' ', @class, ' '), ' section_add_menus ')]" . + "/descendant::select[contains(., '" . $activity . "')]"; $selectnode = $this->find('xpath', $selectxpath); $selectnode->selectOption($activity); @@ -279,8 +279,8 @@ public function section_should_be_hidden($sectionnumber) { foreach ($activities as $activity) { // Dimmed. - $this->find('xpath', "//div[contains(concat(' ', @class, ' '), ' activityinstance ')] -/a[contains(concat(' ', @class, ' '), ' dimmed ')]", $dimmedexception, $activity); + $this->find('xpath', "//div[contains(concat(' ', @class, ' '), ' activityinstance ')]" . + "/a[contains(concat(' ', @class, ' '), ' dimmed ')]", $dimmedexception, $activity); // To check that the visibility is not clickable we check the funcionality rather than the applied style. $visibilityiconnode = $this->find('css', 'a.editing_show img', false, $activity); diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index 57c76ebee8ef3..f785d1690a80f 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -132,7 +132,8 @@ protected function expand_all_fields() { // Show all fields. $showmorestr = get_string('showmore', 'form'); - $showmores = $this->find_all('xpath', "//a[contains(concat(' ', normalize-space(.), ' '), '" . $showmorestr . "')][contains(concat(' ', normalize-space(@class), ' '), ' moreless-toggler')]"); + $showmores = $this->find_all('xpath', "//a[contains(concat(' ', normalize-space(.), ' '), '" . $showmorestr . "')]" . + "[contains(concat(' ', normalize-space(@class), ' '), ' moreless-toggler')]"); // We are supposed to have 'show more's here, otherwise exception. diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index f3bad4610ba82..9146eb9593f6a 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -53,17 +53,16 @@ public function i_expand_node($nodetext) { return false; } - $xpath = "//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')] -/child::li -/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')] -/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')] -| -//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')] -/descendant::li[not(contains(concat(' ', normalize-space(@class), ' '), ' collapsed'))] -/descendant::li -/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')] -/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')] -"; + $xpath = "//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" . + "/child::li" . + "/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')]" . + "/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]" . + "|" . + "//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" . + "/descendant::li[not(contains(concat(' ', normalize-space(@class), ' '), ' collapsed'))]" . + "/descendant::li" . + "/child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')]" . + "/child::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]"; $node = $this->find('xpath', $xpath); $node->click(); diff --git a/question/tests/behat/behat_question.php b/question/tests/behat/behat_question.php index fe6daafdc8a02..79fe0ea34ae91 100644 --- a/question/tests/behat/behat_question.php +++ b/question/tests/behat/behat_question.php @@ -51,8 +51,8 @@ class behat_question extends behat_base { */ public function i_add_a_question_filling_the_form_with($questiontypename, TableNode $questiondata) { - $questiontypexpath = "//span[@class='qtypename'][.='" . $questiontypename . "'] -/ancestor::div[@class='qtypeoption']/descendant::input"; + $questiontypexpath = "//span[@class='qtypename'][.='" . $questiontypename . "']" . + "/ancestor::div[@class='qtypeoption']/descendant::input"; return array( new Given('I follow "' . get_string('questionbank', 'question') . '"'), @@ -81,8 +81,8 @@ public function the_state_of_question_is_shown_as($questiondescription, $state) $this->find('xpath', $questionxpath, $exception); $exception = new ExpectationException('Question "' . $questiondescription . '" state is not "' . $state . '"', $this->getSession()); - $xpath = $questionxpath . "/ancestor::div[contains(concat(' ', @class, ' '), ' que ')] -/descendant::div[@class='state'][contains(., '" . $state . "')]"; + $xpath = $questionxpath . "/ancestor::div[contains(concat(' ', @class, ' '), ' que ')]" . + "/descendant::div[@class='state'][contains(., '" . $state . "')]"; $this->find('xpath', $xpath, $exception); } diff --git a/repository/tests/behat/behat_filepicker.php b/repository/tests/behat/behat_filepicker.php index 10c9b3f0241d6..8b83ae3ecaf97 100644 --- a/repository/tests/behat/behat_filepicker.php +++ b/repository/tests/behat/behat_filepicker.php @@ -92,8 +92,8 @@ public function i_open_folder_from_filepicker($foldername, $filepickerelement) { // In the current folder workspace. $folder = $this->find( 'xpath', - "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')] -//descendant::div[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]", + "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')]" . + "//descendant::div[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]", $exception, $fieldnode ); @@ -102,8 +102,8 @@ public function i_open_folder_from_filepicker($foldername, $filepickerelement) { // And in the pathbar. $folder = $this->find( 'xpath', - "//a[contains(concat(' ', normalize-space(@class), ' '), ' fp-path-folder-name ')] -[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]", + "//a[contains(concat(' ', normalize-space(@class), ' '), ' fp-path-folder-name ')]" . + "[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]", $exception, $fieldnode );