Skip to content

Commit

Permalink
Merge branch 'MDL-39635_master' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jul 22, 2013
2 parents f251596 + 3897608 commit 63ff2c5
Show file tree
Hide file tree
Showing 37 changed files with 295 additions and 237 deletions.
10 changes: 7 additions & 3 deletions admin/tests/behat/behat_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function i_set_the_following_administration_settings_values(TableNode $ta
}

// Search by label.
$searchbox = $this->find_field('Search in settings');
$searchbox = $this->find_field(get_string('searchinsettings', 'admin'));
$searchbox->setValue($label);
$submitsearch = $this->find('css', 'form.adminsearchform input[type=submit]');
$submitsearch->press();
Expand All @@ -72,8 +72,12 @@ 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 ');

// The argument should be converted to an xpath literal.
$label = $this->getSession()->getSelectorsHandler()->xpathLiteral($label);

$fieldxpath = "//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]" .
"[@id=//label[contains(normalize-space(string(.)), '" . $label . "')]/@for]";
"[@id=//label[contains(normalize-space(.), $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");
Expand All @@ -90,7 +94,7 @@ public function i_set_the_following_administration_settings_values(TableNode $ta
$field = behat_field_manager::get_field_instance($type, $fieldnode, $this->getSession());
$field->set_value($value);

$this->find_button('Save changes')->press();
$this->find_button(get_string('savechanges'))->press();
}
}

Expand Down
2 changes: 1 addition & 1 deletion admin/tests/behat/display_short_names.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Display extended course names
And I should not see "C_shortname Course fullname"

Scenario: Courses list with extended course names
Given I click on "Courses" "link" in the "//div[@id='settingsnav']//descendant::li[contains(concat(' ', @class, ' '), ' type_setting ')][not(contains(., 'Site administration'))][contains(., 'Appearance')]" "xpath_element"
Given I click on "Courses" "link" in the "//div[@id='settingsnav']/descendant::li[contains(concat(' ', normalize-space(@class), ' '), ' type_setting ')][not(contains(., 'Site administration'))][contains(., 'Appearance')]" "xpath_element"
And I check "Display extended course names"
When I press "Save changes"
And I am on homepage
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/behat/tests/behat/basic_actions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ Feature: Page contents assertions
And I follow "Course 1"
When I click on "Move this to the dock" "button" in the ".block_settings" "css_element"
Then I should not see "Question bank"
And I click on "//div[@id='dock']/descendant::*[contains(., 'Administration')]/h2" "xpath_element"
And I click on "//div[@id='dock']/descendant::h2[normalize-space(.)='Administration']" "xpath_element"

@javascript
Scenario: Locators inside specific DOM nodes using XPath
Given the following "courses" exists:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And I log in as "admin"
When I click on "Move this to the dock" "button" in the "//*[contains(concat(' ', normalize-space(@class), ' '), ' block_settings ')]" "xpath_element"
When I click on "Move this to the dock" "button" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' block_settings ')]" "xpath_element"
Then I should not see "Turn editing on"
16 changes: 8 additions & 8 deletions admin/tool/behat/tests/behat/data_generators.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ Feature: Set up contextual data for tests
Then I should see "Course 1"
And I should see "Course 2"
And I should see "Course 3"
When I go to the courses management page
And I go to the courses management page
And I follow "Cat 1"
Then I should see "Cat 2"
And I should see "Cat 2"
And I should see "Cat 3"
When I follow "Cat 3"
Then I should see "Course 1"
And I follow "Cat 3"
And I should see "Course 1"
And I should see "Course 2"
When I select "Cat 2" from "Course categories:"
Then I should see "No courses in this category"
When I select "Miscellaneous" from "Course categories:"
Then I should see "Course 3"
And I select "Cat 1 / Cat 2" from "Course categories:"
And I should see "No courses in this category"
And I select "Miscellaneous" from "Course categories:"
And I should see "Course 3"

@javascript
Scenario: Add a bunch of groups and groupings
Expand Down
10 changes: 5 additions & 5 deletions auth/tests/behat/behat_auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class behat_auth extends behat_base {
public function i_log_in_as($username) {

return array(new Given('I am on homepage'),
new Given('I follow "Log in"'),
new Given('I fill in "Username" with "'.$username.'"'),
new Given('I fill in "Password" with "'.$username.'"'),
new Given('I press "Log in"')
new Given('I follow "' . get_string('login') . '"'),
new Given('I fill in "' . get_string('username') . '" with "' . $this->escape($username) . '"'),
new Given('I fill in "' . get_string('password') . '" with "'. $this->escape($username) . '"'),
new Given('I press "' . get_string('login') . '"')
);
}

Expand All @@ -62,7 +62,7 @@ public function i_log_in_as($username) {
* @Given /^I log out$/
*/
public function i_log_out() {
return new When('I follow "Log out"');
return new When('I follow "' . get_string('logout') . '"');
}

}
4 changes: 2 additions & 2 deletions backup/util/ui/tests/behat/backup_courses.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Feature: Backup Moodle courses
And I should not see "Section 3"
And I press "Continue"
And I click on "Continue" "button" in the ".bcs-current-course" "css_element"
And I click on "//div[contains(concat(' ', @class, ' '), ' fitem ')][contains(., 'Include calendar events')]/descendant::img" "xpath_element"
And I click on "setting_root_logs" "checkbox" in the "//div[contains(@class, 'fitem')][contains(., 'Include course logs')]" "xpath_element"
And "//div[contains(concat(' ', normalize-space(@class), ' '), ' fitem ')][contains(., 'Include calendar events')]/descendant::img" "xpath_element" should exists
And I check "Include course logs"
And I press "Cancel"
And I click on "Cancel" "button" in the ".confirmation-dialogue" "css_element"
79 changes: 46 additions & 33 deletions backup/util/ui/tests/behat/behat_backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ public function i_backup_course_using_this_options($backupcourse, $options = fal
$this->find_link($backupcourse)->click();

// Click the backup link.
$this->find_link('Backup')->click();
$this->find_link(get_string('backup'))->click();

// Initial settings.
$this->fill_backup_restore_form($options);
$this->find_button('Next')->press();
$this->find_button(get_string('backupstage1action', 'backup'))->press();

// Schema settings.
$this->fill_backup_restore_form($options);
$this->find_button('Next')->press();
$this->find_button(get_string('backupstage2action', 'backup'))->press();

// Confirmation and review, backup filename can also be specified.
$this->fill_backup_restore_form($options);
$this->find_button('Perform backup')->press();
$this->find_button(get_string('backupstage4action', 'backup'))->press();

// Waiting for it to finish.
$this->wait(10);

// Last backup continue button.
$this->find_button('Continue')->press();
$this->find_button(get_string('backupstage16action', 'backup'))->press();
}

/**
Expand All @@ -105,36 +105,37 @@ public function i_import_course_into_course($fromcourse, $tocourse, $options = f
// Click the course link.
$this->find_link($tocourse)->click();

// Click the backup link.
$this->find_link('Import')->click();
// Click the import link.
$this->find_link(get_string('import'))->click();

// Select the course.
$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 . "')]" .
// The argument should be converted to an xpath literal.
$fromcourse = $this->getSession()->getSelectorsHandler()->xpathLiteral($fromcourse);
$xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' ics-results ')]" .
"/descendant::tr[contains(., $fromcourse)]" .
"/descendant::input[@type='radio']";
$radionode = $this->find('xpath', $xpath, $exception);
$radionode->check();
$radionode->click();

$this->find_button('Continue')->press();
$this->find_button(get_string('continue'))->press();

// Initial settings.
$this->fill_backup_restore_form($options);
$this->find_button('Next')->press();
$this->find_button(get_string('importbackupstage1action', 'backup'))->press();

// Schema settings.
$this->fill_backup_restore_form($options);
$this->find_button('Next')->press();
$this->find_button(get_string('importbackupstage2action', 'backup'))->press();

// Run it.
$this->find_button('Perform import')->press();
$this->find_button(get_string('importbackupstage4action', 'backup'))->press();
$this->wait();

// Continue and redirect to 'to' course.
$this->find_button('Continue')->press();
$this->find_button(get_string('continue'))->press();
}

/**
Expand All @@ -150,17 +151,20 @@ public function i_restore_backup_into_course_using_this_options($backupfilename,
// Confirm restore.
$this->select_backup($backupfilename);

// The argument should be converted to an xpath literal.
$existingcourse = $this->getSession()->getSelectorsHandler()->xpathLiteral($existingcourse);

// 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')]" .
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-existing-course ')]" .
"/descendant::div[@class='restore-course-search']" .
"/descendant::tr[contains(., '" . $existingcourse . "')]" .
"/descendant::tr[contains(., $existingcourse)]" .
"/descendant::input[@type='radio']");
$radionode->check();
$radionode->click();

// Pressing the continue button of the restore into an existing course section.
$continuenode = $this->find('xpath', "//div[contains(@class, 'bcs-existing-course')]/descendant::input[@type='submit'][@value='Continue']");
$continuenode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-existing-course ')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();

Expand All @@ -181,14 +185,15 @@ 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')]" .
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-new-course ')]" .
"/descendant::div[@class='restore-course-search']" .
"/descendant::input[@type='radio']");
$radionode->check();
$radionode->click();

// Pressing the continue button of the restore into an existing course section.
$continuenode = $this->find('xpath', "//div[contains(@class, 'bcs-new-course')]/descendant::input[@type='submit'][@value='Continue']");
$continuenode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-new-course ')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();

Expand All @@ -209,14 +214,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')]" .
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@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(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();

Expand All @@ -237,14 +242,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')]" .
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@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(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();

Expand All @@ -263,12 +268,16 @@ protected function select_backup($backupfilename) {

// Using xpath as there are other restore links before this one.
$exception = new ExpectationException('The "' . $backupfilename . '" backup file can not be found in this page', $this->getSession());
$xpath = "//tr[contains(., '" . $backupfilename . "')]/descendant::a[contains(., 'Restore')]";

// The argument should be converted to an xpath literal.
$backupfilename = $this->getSession()->getSelectorsHandler()->xpathLiteral($backupfilename);

$xpath = "//tr[contains(., $backupfilename)]/descendant::a[contains(., '" . get_string('restore') . "')]";
$restorelink = $this->find('xpath', $xpath, $exception);
$restorelink->click();

// Confirm the backup contents.
$restore = $this->find_button('Continue')->press();
$restore = $this->find_button(get_string('continue'))->press();
}

/**
Expand All @@ -284,18 +293,18 @@ protected function process_restore($options) {

// Settings.
$this->fill_backup_restore_form($options);
$this->find_button('Next')->press();
$this->find_button(get_string('restorestage4action', 'backup'))->press();

// Schema.
$this->fill_backup_restore_form($options);
$this->find_button('Next')->press();
$this->find_button(get_string('restorestage8action', 'backup'))->press();

// Review, no options here.
$this->find_button('Perform restore')->press();
$this->find_button(get_string('restorestage16action', 'backup'))->press();
$this->wait(10);

// Last restore continue button, redirected to restore course after this.
$this->find_button('Continue')->press();
$this->find_button(get_string('restorestage32action', 'backup'))->press();
}

/**
Expand Down Expand Up @@ -339,6 +348,10 @@ protected function fill_backup_restore_form($options) {
*/
protected function wait($timeout = false) {

if (!$this->running_javascript()) {
return;
}

if (!$timeout) {
$timeout = self::TIMEOUT;
}
Expand Down
11 changes: 7 additions & 4 deletions blocks/comments/tests/behat/behat_block_comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function i_add_comment_to_comments_block($comment) {
$commentstextarea = $this->find('css', '.comment-area textarea', $exception);
$commentstextarea->setValue($comment);

$this->find_link('Save comment')->click();
$this->find_link(get_string('savecomment'))->click();

// Wait for the AJAX request.
$this->getSession()->wait(4 * 1000, false);
Expand Down Expand Up @@ -91,8 +91,11 @@ 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 . "')]";
// Using xpath liternal to avoid possible problems with comments containing quotes.
$commentliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($comment);

$commentxpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' block_comments ')]" .
"/descendant::div[@class='comment-message'][contains(., $commentliteral)]";
$commentnode = $this->find('xpath', $commentxpath, $exception);

// Click on delete icon.
Expand All @@ -101,7 +104,7 @@ public function i_delete_comment_from_comments_block($comment) {
$deleteicon->click();

// Yes confirm.
$confirmnode = $this->find('xpath', "//div[@class='comment-delete-confirm']/descendant::a[contains(., 'Yes')]");
$confirmnode = $this->find('xpath', "//div[@class='comment-delete-confirm']/descendant::a[contains(., '" . get_string('yes') . "')]");
$confirmnode->click();

// Wait for the AJAX request.
Expand Down
4 changes: 2 additions & 2 deletions blocks/tests/behat/behat_blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class behat_blocks extends behat_base {
* @param string $blockname
*/
public function i_add_the_block($blockname) {
$steps = new Given('I select "' . $blockname . '" from "bui_addblock"');
$steps = new Given('I select "' . $this->escape($blockname) . '" from "bui_addblock"');

// If we are running without javascript we need to submit the form.
if (!$this->running_javascript()) {
$steps = array(
$steps,
new Given('I click on "Go" "button" in the "#add_block" "css_element"')
new Given('I click on "' . get_string('go') . '" "button" in the "#add_block" "css_element"')
);
}
return $steps;
Expand Down
2 changes: 1 addition & 1 deletion blocks/tests/behat/configure_block_throughout_site.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Feature: Add and configure blocks throughout the site
And I press "Save changes"
And I follow "Course 1"
# The first block matching the pattern should be top-left block
And I should see "Comments" in the "//*[@id='region-pre']/descendant::div[contains(concat(' ', @class, ' '), ' block ')]" "xpath_element"
And I should see "Comments" in the "//*[@id='region-pre']/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' block ')]" "xpath_element"
Loading

0 comments on commit 63ff2c5

Please sign in to comment.