Skip to content

Commit

Permalink
MDL-39348 behat: Chaining strings instead of splitting strings in lines
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed May 3, 2013
1 parent 4d40089 commit 00ea74c
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 52 deletions.
8 changes: 4 additions & 4 deletions admin/tests/behat/behat_admin.php
Expand Up @@ -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'));
Expand Down
34 changes: 18 additions & 16 deletions backup/util/ui/tests/behat/behat_backup.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions blocks/comments/tests/behat/behat_block_comments.php
Expand Up @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions completion/tests/behat/behat_completion.php
Expand Up @@ -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'),
Expand All @@ -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"')
Expand All @@ -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');
}
Expand Down
14 changes: 7 additions & 7 deletions course/tests/behat/behat_course.php
Expand Up @@ -126,18 +126,18 @@ 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();

} else {
// 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);

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/tests/behat/behat_forms.php
Expand Up @@ -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.

Expand Down
21 changes: 10 additions & 11 deletions lib/tests/behat/behat_navigation.php
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions question/tests/behat/behat_question.php
Expand Up @@ -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') . '"'),
Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions repository/tests/behat/behat_filepicker.php
Expand Up @@ -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
);
Expand All @@ -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
);
Expand Down

0 comments on commit 00ea74c

Please sign in to comment.