Skip to content

Commit

Permalink
MDL-39635 behat: Replacing hardcoded language strings
Browse files Browse the repository at this point in the history
Using get_string() instead.
  • Loading branch information
David Monllao authored and dmonllao committed Jul 19, 2013
1 parent 3194dc8 commit dedb973
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 79 deletions.
4 changes: 2 additions & 2 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 Down Expand Up @@ -90,7 +90,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
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 "'.$username.'"'),
new Given('I fill in "' . get_string('password') . '" with "'.$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') . '"');
}

}
44 changes: 23 additions & 21 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 @@ -106,7 +106,7 @@ public function i_import_course_into_course($fromcourse, $tocourse, $options = f
$this->find_link($tocourse)->click();

// Click the backup link.
$this->find_link('Import')->click();
$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());
Expand All @@ -119,22 +119,22 @@ public function i_import_course_into_course($fromcourse, $tocourse, $options = f
$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 @@ -160,7 +160,8 @@ public function i_restore_backup_into_course_using_this_options($backupfilename,
$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(@class, 'bcs-existing-course')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();

Expand Down Expand Up @@ -188,7 +189,8 @@ public function i_restore_backup_into_a_new_course_using_this_options($backupfil
$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(@class, 'bcs-new-course')]" .
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();

Expand Down Expand Up @@ -216,7 +218,7 @@ public function i_merge_backup_into_the_current_course($backupfilename, $options

// 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']");
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();

Expand Down Expand Up @@ -244,7 +246,7 @@ public function i_merge_backup_into_current_course_deleting_its_contents($backup

// 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']");
"/descendant::input[@type='submit'][@value='" . get_string('continue') . "']");
$continuenode->click();
$this->wait();

Expand All @@ -263,12 +265,12 @@ 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')]";
$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 +286,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
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion blocks/tests/behat/behat_blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function i_add_the_block($blockname) {
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
18 changes: 9 additions & 9 deletions cohort/tests/behat/behat_cohort.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ public function i_add_user_to_cohort($username, $cohortidnumber) {
$userid = $DB->get_field('user', 'id', array('username' => $username));

$steps = array(
new Given('I click on "Assign" "link" in the "//table[@id=\'cohorts\']//tr[contains(., \'' . $cohortidnumber . '\')]" "xpath_element"'),
new Given('I select "' . $userid . '" from "Potential users"'),
new Given('I press "Add"'),
new Given('I press "Back to cohorts"')
new Given('I click on "' . get_string('assign', 'cohort') . '" "link" in the "//table[@id=\'cohorts\']//tr[contains(., \'' . $cohortidnumber . '\')]" "xpath_element"'),
new Given('I select "' . $userid . '" from "' . get_string('potusers', 'cohort') . '"'),
new Given('I press "' . get_string('add') . '"'),
new Given('I press "' . get_string('backtocohorts', 'cohort') . '"')
);

// If we are not in the cohorts management we should move there before anything else.
if (!$this->getSession()->getPage()->find('css', 'input#cohort_search_q')) {
$steps = array_merge(
array(
new Given('I am on homepage'),
new Given('I collapse "Front page settings" node'),
new Given('I expand "Site administration" node'),
new Given('I expand "Users" node'),
new Given('I expand "Accounts" node'),
new Given('I follow "Cohorts"')
new Given('I collapse "' . get_string('frontpagesettings', 'admin') . '" node'),
new Given('I expand "' . get_string('administrationsite') . '" node'),
new Given('I expand "' . get_string('users', 'admin') . '" node'),
new Given('I expand "' . get_string('accounts', 'admin') . '" node'),
new Given('I follow "' . get_string('cohorts', 'cohort') . '"')
),
$steps
);
Expand Down
6 changes: 3 additions & 3 deletions completion/tests/behat/behat_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ public function go_to_the_current_course_activity_completion_report() {
$this->find('xpath', "//*[@id='settingsnav']" .
"/descendant::li" .
"/descendant::li[not(contains(@class,'collapsed'))]" .
"/descendant::p[contains(., 'Activity completion')]");
"/descendant::p[contains(., '" . get_string('pluginname', 'report_progress') . "')]");
} catch (ElementNotFoundException $e) {
$steps[] = new Given('I expand "Reports" node');
$steps[] = new Given('I expand "' . get_string('reports') . '" node');
}

$steps[] = new Given('I follow "Activity completion"');
$steps[] = new Given('I follow "' . get_string('pluginname', 'report_progress') . '"');

return $steps;
}
Expand Down
20 changes: 10 additions & 10 deletions course/tests/behat/behat_course.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class behat_course extends behat_base {
* @Given /^I turn editing mode on$/
*/
public function i_turn_editing_mode_on() {
return new Given('I press "Turn editing on"');
return new Given('I press "' . get_string('turneditingon') . '"');
}

/**
* Turns editing mode off.
* @Given /^I turn editing mode off$/
*/
public function i_turn_editing_mode_off() {
return new Given('I press "Turn editing off"');
return new Given('I press "' . get_string('turneditingoff') . '"');
}

/**
Expand All @@ -68,9 +68,9 @@ public function i_turn_editing_mode_off() {
public function i_create_a_course_with(TableNode $table) {
return array(
new Given('I go to the courses management page'),
new Given('I press "Add a new course"'),
new Given('I press "' . get_string('addnewcourse') . '"'),
new Given('I fill the moodle form with:', $table),
new Given('I press "Save changes"')
new Given('I press "' . get_string('savechanges') . '"')
);
}

Expand All @@ -83,9 +83,9 @@ public function i_go_to_the_courses_management_page() {

return array(
new Given('I am on homepage'),
new Given('I expand "Site administration" node'),
new Given('I expand "Courses" node'),
new Given('I follow "Add/edit courses"'),
new Given('I expand "' . get_string('administrationsite') . '" node'),
new Given('I expand "' . get_string('courses', 'admin') . '" node'),
new Given('I follow "' . get_string('coursemgmt', 'admin') . '"'),
);
}

Expand All @@ -102,7 +102,7 @@ public function i_add_to_section_and_i_fill_the_form_with($activity, $section, T
return array(
new Given('I add a "'.$activity.'" to section "'.$section.'"'),
new Given('I fill the moodle form with:', $data),
new Given('I press "Save and return to course"')
new Given('I press "' . get_string('savechangesandreturntocourse') . '"')
);
}

Expand Down Expand Up @@ -765,8 +765,8 @@ protected function get_activity_node($activityname) {
protected function is_course_editor() {

// We don't need to behat_base::spin() here as all is already loaded.
if (!$this->getSession()->getPage()->findButton('Turn editing off') &&
!$this->getSession()->getPage()->findButton('Turn editing on')) {
if (!$this->getSession()->getPage()->findButton(get_string('turneditingoff')) &&
!$this->getSession()->getPage()->findButton(get_string('turneditingon'))) {
return false;
}

Expand Down
8 changes: 4 additions & 4 deletions enrol/tests/behat/behat_enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class behat_enrol extends behat_base {
public function i_add_enrolment_method_with($enrolmethod, TableNode $table) {

return array(
new Given('I expand "Users" node'),
new Given('I follow "Enrolment methods"'),
new Given('I select "' . $enrolmethod . '" from "Add method"'),
new Given('I expand "' . get_string('users', 'admin') . '" node'),
new Given('I follow "' . get_string('type_enrol_plural', 'plugin') . '"'),
new Given('I select "' . $enrolmethod . '" from "' . get_string('addinstance', 'enrol') . '"'),
new Given('I fill the moodle form with:', $table),
new Given('I press "Add method"')
new Given('I press "' . get_string('addinstance', 'enrol') . '"')
);
}

Expand Down
2 changes: 1 addition & 1 deletion group/tests/behat/behat_groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function i_add_user_to_group($username, $groupname) {
$this->getSession()->wait(self::TIMEOUT, '(document.readyState === "complete")');

// Returning to the main groups page.
$this->find_button('Back to groups')->click();
$this->find_button(get_string('backtogroups', 'group'))->click();
}

}
20 changes: 10 additions & 10 deletions lib/tests/behat/behat_permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public function i_set_the_following_system_permissions_of_role($rolename, $table

return array(
new Given('I am on homepage'),
new Given('I collapse "Front page settings" node'),
new Given('I expand "Site administration" node'),
new Given('I expand "Users" node'),
new Given('I expand "Permissions" node'),
new Given('I follow "Define roles"'),
new Given('I collapse "' . get_string('frontpagesettings', 'admin') . '" node'),
new Given('I expand "' . get_string('administrationsite') . '" node'),
new Given('I expand "' . get_string('users', 'admin') . '" node'),
new Given('I expand "' . get_string('permissions', 'role') . '" node'),
new Given('I follow "' . get_string('defineroles', 'role') . '"'),
new Given('I follow "Edit ' . $this->escape($rolename) . ' role"'),
new Given('I fill the capabilities form with the following permissions:', $table),
new Given('I press "Save changes"')
new Given('I press "' . get_string('savechanges') . '"')
);
}

Expand All @@ -76,9 +76,9 @@ public function i_override_the_system_permissions_of_role_with($rolename, $table
$roleoption = $this->find('xpath', '//select[@name="roleid"]/option[contains(text(),"' . $this->escape($rolename) . '")]');

return array(
new Given('I select "' . $this->escape($roleoption->getText()) . '" from "Advanced role override"'),
new Given('I select "' . $this->escape($roleoption->getText()) . '" from "' . get_string('advancedoverride', 'role') . '"'),
new Given('I fill the capabilities form with the following permissions:', $table),
new Given('I press "Save changes"')
new Given('I press "' . get_string('savechanges') . '"')
);
}

Expand All @@ -93,9 +93,9 @@ public function i_fill_the_capabilities_form_with_the_following_permissions($tab
// Ensure we are using the advanced view.
// Wrapped in a try/catch to capture the exception and continue execution, we don't know if advanced mode was already enabled.
try {
$advancedtoggle = $this->find_button('Show advanced');
$advancedtoggle = $this->find_button(get_string('showadvanced', 'form'));
if ($advancedtoggle) {
$this->getSession()->getPage()->pressButton('Show advanced');
$this->getSession()->getPage()->pressButton(get_string('showadvanced', 'form'));
}
} catch (Exception $e) {
// We already are in advanced mode.
Expand Down
4 changes: 2 additions & 2 deletions message/tests/behat/behat_message.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public function i_send_message_to_user($messagecontent, $tousername) {
$steps[] = new Given('I am on homepage');

if ($this->running_javascript()) {
$steps[] = new Given('I expand "My profile" node');
$steps[] = new Given('I expand "' . get_string('myprofile') . '" node');
}

$steps[] = new Given('I follow "Messages"');
$steps[] = new Given('I follow "' . get_string('messages', 'message') . '"');
$steps[] = new Given('I fill in "' . get_string('searchcombined', 'message') . '" with "' . $tofullname . '"');
$steps[] = new Given('I press "' . get_string('searchcombined', 'message') . '"');
$steps[] = new Given('I follow "' . get_string('sendmessageto', 'message', $tofullname) . '"');
Expand Down
Loading

0 comments on commit dedb973

Please sign in to comment.