MDL-53381 behat: Replaced chained steps with api.

Behat 3.x doesn't support chained steps and hence
this is first step to get rid of chained steps in core.
This commit is contained in:
Rajesh Taneja
2016-03-18 12:12:42 +08:00
parent cffc012645
commit eb9ca848fa
30 changed files with 740 additions and 703 deletions

View File

@@ -28,9 +28,6 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given;
use Moodle\BehatExtension\Context\Step\When as When;
/** /**
* Log in log out steps definitions. * Log in log out steps definitions.
* *
@@ -51,12 +48,11 @@ class behat_auth extends behat_base {
$this->getSession()->visit($this->locate_path('login/index.php')); $this->getSession()->visit($this->locate_path('login/index.php'));
// Enter username and password. // Enter username and password.
$behatforms = behat_context_helper::get('behat_forms'); $this->execute('behat_forms::i_set_the_field_to', array('Username', $this->escape($username)));
$behatforms->i_set_the_field_to('Username', $this->escape($username)); $this->execute('behat_forms::i_set_the_field_to', array('Password', $this->escape($username)));
$behatforms->i_set_the_field_to('Password', $this->escape($username));
// Press log in button. // Press log in button, no need to check for exceptions as it will checked after this step execution.
$behatforms->press_button(get_string('login')); $this->execute('behat_forms::press_button', get_string('login'));
} }
/** /**
@@ -65,22 +61,18 @@ class behat_auth extends behat_base {
* @Given /^I log out$/ * @Given /^I log out$/
*/ */
public function i_log_out() { public function i_log_out() {
$steps = array(new When('I follow "' . get_string('logout') . '"'));
// No need to check anything else if we run without JS.
if (!$this->running_javascript()) {
return $steps;
}
// There is no longer any need to worry about whether the navigation // There is no longer any need to worry about whether the navigation
// bar needs to be expanded; user_menu now lives outside the // bar needs to be expanded; user_menu now lives outside the
// hamburger. // hamburger.
// However, the user menu *always* needs to be expanded. // However, the user menu *always* needs to be expanded. if running JS.
if ($this->running_javascript()) {
$xpath = "//div[@class='usermenu']//a[contains(concat(' ', @class, ' '), ' toggle-display ')]"; $xpath = "//div[@class='usermenu']//a[contains(concat(' ', @class, ' '), ' toggle-display ')]";
array_unshift($steps, new When('I click on "'.$xpath.'" "xpath_element"'));
return $steps; $this->execute('behat_general::i_click_on', array($xpath, "xpath_element"));
}
// No need to check for exceptions as it will checked after this step execution.
$this->execute('behat_general::click_link', get_string('logout'));
} }
} }

View File

@@ -27,8 +27,6 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given;
/** /**
* Blocks management steps definitions. * Blocks management steps definitions.
* *
@@ -46,16 +44,16 @@ class behat_blocks extends behat_base {
* @param string $blockname * @param string $blockname
*/ */
public function i_add_the_block($blockname) { public function i_add_the_block($blockname) {
$steps = new Given('I set the field "bui_addblock" to "' . $this->escape($blockname) . '"'); $this->execute('behat_forms::i_set_the_field_to',
array("bui_addblock", $this->escape($blockname))
);
// If we are running without javascript we need to submit the form. // If we are running without javascript we need to submit the form.
if (!$this->running_javascript()) { if (!$this->running_javascript()) {
$steps = array( $this->execute('behat_general::i_click_on_in_the',
$steps, array(get_string('go'), "button", "#add_block", "css_element")
new Given('I click on "' . get_string('go') . '" "button" in the "#add_block" "css_element"')
); );
} }
return $steps;
} }
/** /**
@@ -63,13 +61,14 @@ class behat_blocks extends behat_base {
* *
* @Given /^I dock "(?P<block_name_string>(?:[^"]|\\")*)" block$/ * @Given /^I dock "(?P<block_name_string>(?:[^"]|\\")*)" block$/
* @param string $blockname * @param string $blockname
* @return Given
*/ */
public function i_dock_block($blockname) { public function i_dock_block($blockname) {
// Looking for both title and alt. // Looking for both title and alt.
$xpath = "//input[@type='image'][@title='" . get_string('dockblock', 'block', $blockname) . "' or @alt='" . get_string('addtodock', 'block') . "']"; $xpath = "//input[@type='image'][@title='" . get_string('dockblock', 'block', $blockname) . "' or @alt='" . get_string('addtodock', 'block') . "']";
return new Given('I click on " ' . $xpath . '" "xpath_element" in the "' . $this->escape($blockname) . '" "block"'); $this->execute('behat_general::i_click_on_in_the',
array($xpath, "xpath_element", $this->escape($blockname), "block")
);
} }
/** /**
@@ -78,7 +77,6 @@ class behat_blocks extends behat_base {
* @Given /^I open the "(?P<block_name_string>(?:[^"]|\\")*)" blocks action menu$/ * @Given /^I open the "(?P<block_name_string>(?:[^"]|\\")*)" blocks action menu$/
* @throws DriverException The step is not available when Javascript is disabled * @throws DriverException The step is not available when Javascript is disabled
* @param string $blockname * @param string $blockname
* @return Given
*/ */
public function i_open_the_blocks_action_menu($blockname) { public function i_open_the_blocks_action_menu($blockname) {
@@ -93,7 +91,9 @@ class behat_blocks extends behat_base {
return; return;
} }
return new Given('I click on "a[role=\'menuitem\']" "css_element" in the "' . $this->escape($blockname) . '" "block"'); $this->execute('behat_general::i_click_on_in_the',
array("a[role='menuitem']", "css_element", $this->escape($blockname), "block")
);
} }
/** /**
@@ -106,9 +106,11 @@ class behat_blocks extends behat_base {
*/ */
public function i_configure_the_block($blockname) { public function i_configure_the_block($blockname) {
// Note that since $blockname may be either block name or CSS class, we can not use the exact label of "Configure" link. // Note that since $blockname may be either block name or CSS class, we can not use the exact label of "Configure" link.
return array(
new Given('I open the "'.$this->escape($blockname).'" blocks action menu'), $this->execute("behat_blocks::i_open_the_blocks_action_menu", $this->escape($blockname));
new Given('I click on "Configure" "link" in the "'.$this->escape($blockname).'" "block"')
$this->execute('behat_general::i_click_on_in_the',
array("Configure", "link", $this->escape($blockname), "block")
); );
} }
} }

View File

@@ -26,7 +26,6 @@
// NOTE: no MOODLE_INTERNAL used, this file may be required by behat before including /config.php. // NOTE: no MOODLE_INTERNAL used, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given;
use Behat\Gherkin\Node\TableNode as TableNode; use Behat\Gherkin\Node\TableNode as TableNode;
/** /**
@@ -44,17 +43,13 @@ class behat_calendar extends behat_base {
* *
* @Given /^I create a calendar event with form data:$/ * @Given /^I create a calendar event with form data:$/
* @param TableNode $data * @param TableNode $data
* @return array the list of actions to perform
*/ */
public function i_create_a_calendar_event_with_form_data($data) { public function i_create_a_calendar_event_with_form_data($data) {
// Get the event name. // Go to current month page.
$eventname = $data->getRow(1); $this->execute("behat_general::click_link", get_string('monththis', 'calendar'));
$eventname = $eventname[1];
return array( // Create event.
new Given('I follow "' . get_string('monththis', 'calendar') . '"'), $this->i_create_a_calendar_event($data);
new Given('I create a calendar event:', $data),
);
} }
/** /**
@@ -62,19 +57,24 @@ class behat_calendar extends behat_base {
* *
* @Given /^I create a calendar event:$/ * @Given /^I create a calendar event:$/
* @param TableNode $data * @param TableNode $data
* @return array the list of actions to perform
*/ */
public function i_create_a_calendar_event($data) { public function i_create_a_calendar_event($data) {
// Get the event name. // Get the event name.
$eventname = $data->getRow(1); $eventname = $data->getRow(1);
$eventname = $eventname[1]; $eventname = $eventname[1];
return array( // Click to create new event.
new Given('I click on "' . get_string('newevent', 'calendar') .'" "button"'), $this->execute("behat_general::i_click_on", array(get_string('newevent', 'calendar'), "button"));
new Given('I set the following fields to these values:', $data),
new Given('I press "' . get_string('savechanges') . '"'), // Set form fields.
new Given('I should see "' . $eventname . '"') $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
);
// Save event.
$this->execute("behat_forms::press_button", get_string('savechanges'));
// Check if event is created. Being last step, don't need to wait or check for exceptions.
$this->execute("behat_general::assert_page_contains_text", $eventname);
} }
/** /**
@@ -82,7 +82,6 @@ class behat_calendar extends behat_base {
* *
* @Given /^I hover over day "(?P<dayofmonth>\d+)" of this month in the calendar$/ * @Given /^I hover over day "(?P<dayofmonth>\d+)" of this month in the calendar$/
* @param int $day The day of the current month * @param int $day The day of the current month
* @return Given[]
*/ */
public function i_hover_over_day_of_this_month_in_calendar($day) { public function i_hover_over_day_of_this_month_in_calendar($day) {
$summarytitle = get_string('calendarheading', 'calendar', userdate(time(), get_string('strftimemonthyear'))); $summarytitle = get_string('calendarheading', 'calendar', userdate(time(), get_string('strftimemonthyear')));
@@ -94,16 +93,16 @@ class behat_calendar extends behat_base {
$daycontains = "text()[contains(concat(' ', normalize-space(.), ' '), ' {$day} ')]"; $daycontains = "text()[contains(concat(' ', normalize-space(.), ' '), ' {$day} ')]";
$daycell = "td[{$cellclasses}]"; $daycell = "td[{$cellclasses}]";
$dayofmonth = "a[{$daycontains}]"; $dayofmonth = "a[{$daycontains}]";
return array(
new Given('I hover "//' . $currentmonth . '/descendant::' . $daycell . '/' . $dayofmonth . '" "xpath_element"'), $xpath = '//' . $currentmonth . '/descendant::' . $daycell . '/' . $dayofmonth;
); $this->execute("behat_general::i_hover", array($xpath, "xpath_element"));
} }
/** /**
* Hover over today in the calendar. * Hover over today in the calendar.
* *
* @Given /^I hover over today in the calendar$/ * @Given /^I hover over today in the calendar$/
* @return Given[]
*/ */
public function i_hover_over_today_in_the_calendar() { public function i_hover_over_today_in_the_calendar() {
// For window's compatibility, using %d and not %e. // For window's compatibility, using %d and not %e.

View File

@@ -27,8 +27,6 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given;
/** /**
* Steps definitions for cohort actions. * Steps definitions for cohort actions.
* *
@@ -48,13 +46,6 @@ class behat_cohort extends behat_base {
*/ */
public function i_add_user_to_cohort_members($user, $cohortidnumber) { public function i_add_user_to_cohort_members($user, $cohortidnumber) {
$steps = array(
new Given('I click on "' . get_string('assign', 'cohort') . '" "link" in the "' . $this->escape($cohortidnumber) . '" "table_row"'),
new Given('I set the field "' . get_string('potusers', 'cohort') . '" to "' . $this->escape($user) . '"'),
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 we are not in the cohorts management we should move there before anything else.
if (!$this->getSession()->getPage()->find('css', 'input#cohort_search_q')) { if (!$this->getSession()->getPage()->find('css', 'input#cohort_search_q')) {
@@ -62,15 +53,23 @@ class behat_cohort extends behat_base {
$parentnodes = get_string('administrationsite') . ' > ' . $parentnodes = get_string('administrationsite') . ' > ' .
get_string('users', 'admin') . ' > ' . get_string('users', 'admin') . ' > ' .
get_string('accounts', 'admin'); get_string('accounts', 'admin');
$steps = array_merge(
array( $this->execute("behat_general::i_am_on_homepage");
new Given('I am on homepage'), $this->execute("behat_navigation::i_navigate_to_node_in",
new Given('I navigate to "' . get_string('cohorts', 'cohort') . '" node in "' . $parentnodes . '"') array(get_string('cohorts', 'cohort'), $parentnodes)
),
$steps
); );
} }
return $steps; $this->execute('behat_general::i_click_on_in_the',
array(get_string('assign', 'cohort'), "link", $this->escape($cohortidnumber), "table_row")
);
$this->execute("behat_forms::i_set_the_field_to",
array(get_string('potusers', 'cohort'), $this->escape($user))
);
$this->execute("behat_forms::press_button", get_string('add'));
$this->execute("behat_forms::press_button", get_string('backtocohorts', 'cohort'));
} }
} }

View File

@@ -27,9 +27,7 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given, use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
Moodle\BehatExtension\Context\Step\Then,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
/** /**
* Steps definitions to deal with course and activities completion. * Steps definitions to deal with course and activities completion.
@@ -55,9 +53,9 @@ class behat_completion extends behat_base {
$xpath = "//table[@id='completion-progress']" . $xpath = "//table[@id='completion-progress']" .
"/descendant::img[contains(@title, $titleliteral)]"; "/descendant::img[contains(@title, $titleliteral)]";
return array( $this->execute("behat_completion::go_to_the_current_course_activity_completion_report");
new Given('I go to the current course activity completion report'), $this->execute("behat_general::should_exist",
new Then('"' . $this->escape($xpath) . '" "xpath_element" should exist') array($this->escape($xpath), "xpath_element")
); );
} }
@@ -74,12 +72,9 @@ class behat_completion extends behat_base {
$titleliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname . ", " . $activityname . ": Not completed"); $titleliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname . ", " . $activityname . ": Not completed");
$xpath = "//table[@id='completion-progress']" . $xpath = "//table[@id='completion-progress']" .
"/descendant::img[contains(@title, $titleliteral)]"; "/descendant::img[contains(@title, $titleliteral)]";
return array(
new Given('I go to the current course activity completion report'),
new Then('"' . $this->escape($xpath) . '" "xpath_element" should exist')
);
return $steps; $this->execute("behat_completion::go_to_the_current_course_activity_completion_report");
$this->execute("behat_general::should_exist", array($this->escape($xpath), "xpath_element"));
} }
/** /**
@@ -91,7 +86,7 @@ class behat_completion extends behat_base {
$completionnode = get_string('pluginname', 'report_progress'); $completionnode = get_string('pluginname', 'report_progress');
$reportsnode = get_string('courseadministration') . ' > ' . get_string('reports'); $reportsnode = get_string('courseadministration') . ' > ' . get_string('reports');
return new Given('I navigate to "' . $completionnode . '" node in "' . $reportsnode . '"'); $this->execute("behat_navigation::i_navigate_to_node_in", array($completionnode, $reportsnode));
} }
/** /**
@@ -104,18 +99,21 @@ class behat_completion extends behat_base {
$toggle = strtolower($completionstatus) == 'enabled' ? get_string('yes') : get_string('no'); $toggle = strtolower($completionstatus) == 'enabled' ? get_string('yes') : get_string('no');
return array( // Go to course editing.
new Given('I follow "'.get_string('editsettings').'"'), $this->execute("behat_general::click_link", get_string('editsettings'));
new Given('I set the field "'.get_string('enablecompletion', 'completion').'" to "'.$toggle.'"'),
new Given('I press "'.get_string('savechangesanddisplay').'"') // Enable completion.
); $this->execute("behat_forms::i_set_the_field_to",
array(get_string('enablecompletion', 'completion'), $toggle));
// Save course settings.
$this->execute("behat_forms::press_button", get_string('savechangesanddisplay'));
} }
/** /**
* Checks if the activity with specified name is maked as complete. * Checks if the activity with specified name is maked as complete.
* *
* @Given /^the "(?P<activityname_string>(?:[^"]|\\")*)" "(?P<activitytype_string>(?:[^"]|\\")*)" activity with "(manual|auto)" completion should be marked as complete$/ * @Given /^the "(?P<activityname_string>(?:[^"]|\\")*)" "(?P<activitytype_string>(?:[^"]|\\")*)" activity with "(manual|auto)" completion should be marked as complete$/
* @return array
*/ */
public function activity_marked_as_complete($activityname, $activitytype, $completiontype) { public function activity_marked_as_complete($activityname, $activitytype, $completiontype) {
if ($completiontype == "manual") { if ($completiontype == "manual") {
@@ -125,15 +123,17 @@ class behat_completion extends behat_base {
} }
$csselementforactivitytype = "li.modtype_".strtolower($activitytype); $csselementforactivitytype = "li.modtype_".strtolower($activitytype);
return new Given('"//img[contains(@alt, \''.$imgalttext.'\')]" "xpath_element" ' . $xpathtocheck = "//img[contains(@alt, '$imgalttext')]";
'should exist in the "'.$csselementforactivitytype.'" "css_element"'); $this->execute("behat_general::should_exist_in_the",
array($xpathtocheck, "xpath_element", $csselementforactivitytype, "css_element")
);
} }
/** /**
* Checks if the activity with specified name is maked as complete. * Checks if the activity with specified name is maked as complete.
* *
* @Given /^the "(?P<activityname_string>(?:[^"]|\\")*)" "(?P<activitytype_string>(?:[^"]|\\")*)" activity with "(manual|auto)" completion should be marked as not complete$/ * @Given /^the "(?P<activityname_string>(?:[^"]|\\")*)" "(?P<activitytype_string>(?:[^"]|\\")*)" activity with "(manual|auto)" completion should be marked as not complete$/
* @return array
*/ */
public function activity_marked_as_not_complete($activityname, $activitytype, $completiontype) { public function activity_marked_as_not_complete($activityname, $activitytype, $completiontype) {
if ($completiontype == "manual") { if ($completiontype == "manual") {
@@ -143,7 +143,10 @@ class behat_completion extends behat_base {
} }
$csselementforactivitytype = "li.modtype_".strtolower($activitytype); $csselementforactivitytype = "li.modtype_".strtolower($activitytype);
return new Given('"//img[contains(@alt, \''.$imgalttext.'\')]" "xpath_element" ' . $xpathtocheck = "//img[contains(@alt, '$imgalttext')]";
'should exist in the "'.$csselementforactivitytype.'" "css_element"'); $this->execute("behat_general::should_exist_in_the",
array($xpathtocheck, "xpath_element", $csselementforactivitytype, "css_element")
);
} }
} }

View File

@@ -27,8 +27,7 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given, use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ExpectationException as ExpectationException, Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\DriverException as DriverException, Behat\Mink\Exception\DriverException as DriverException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
@@ -48,7 +47,8 @@ class behat_course extends behat_base {
* @Given /^I turn editing mode on$/ * @Given /^I turn editing mode on$/
*/ */
public function i_turn_editing_mode_on() { public function i_turn_editing_mode_on() {
return new Given('I press "' . get_string('turneditingon') . '"');
$this->execute("behat_forms::press_button", get_string('turneditingon'));
} }
/** /**
@@ -56,7 +56,8 @@ class behat_course extends behat_base {
* @Given /^I turn editing mode off$/ * @Given /^I turn editing mode off$/
*/ */
public function i_turn_editing_mode_off() { public function i_turn_editing_mode_off() {
return new Given('I press "' . get_string('turneditingoff') . '"');
$this->execute("behat_forms::press_button", get_string('turneditingoff'));
} }
/** /**
@@ -64,16 +65,21 @@ class behat_course extends behat_base {
* *
* @Given /^I create a course with:$/ * @Given /^I create a course with:$/
* @param TableNode $table The course data * @param TableNode $table The course data
* @return Given[]
*/ */
public function i_create_a_course_with(TableNode $table) { public function i_create_a_course_with(TableNode $table) {
$steps = array( // Go to course management page.
new Given('I go to the courses management page'), $this->i_go_to_the_courses_management_page();
new Given('I should see the "'.get_string('categories').'" management page'), // Ensure you are on course management page.
new Given('I click on category "'.get_string('miscellaneous').'" in the management interface'), $this->execute("behat_course::i_should_see_the_courses_management_page", get_string('categories'));
new Given('I should see the "'.get_string('categoriesandcoures').'" management page'),
new Given('I click on "'.get_string('createnewcourse').'" "link" in the "#course-listing" "css_element"') // Select Miscellaneous category.
$this->i_click_on_category_in_the_management_interface(get_string('miscellaneous'));
$this->execute("behat_course::i_should_see_the_courses_management_page", get_string('categoriesandcoures'));
// Click create new course.
$this->execute('behat_general::i_click_on_in_the',
array(get_string('createnewcourse'), "link", "#course-listing", "css_element")
); );
// If the course format is one of the fields we change how we // If the course format is one of the fields we change how we
@@ -101,29 +107,36 @@ class behat_course extends behat_base {
// Adding a forced wait until editors are loaded as otherwise selenium sometimes tries clicks on the // Adding a forced wait until editors are loaded as otherwise selenium sometimes tries clicks on the
// format field when the editor is being rendered and the click misses the field coordinates. // format field when the editor is being rendered and the click misses the field coordinates.
$steps[] = new Given('I expand all fieldsets'); $this->execute("behat_forms::i_expand_all_fieldsets");
$steps[] = new Given('I set the field "' . $formatfield . '" to "' . $formatvalue . '"');
$steps[] = new Given('I set the following fields to these values:', $table); $this->execute("behat_forms::i_set_the_field_to", array($formatfield, $formatvalue));
} else {
$steps[] = new Given('I set the following fields to these values:', $table);
} }
$steps[] = new Given('I press "' . get_string('savechangesanddisplay') . '"'); // Set form fields.
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
// Save course settings.
$this->execute("behat_forms::press_button", get_string('savechangesanddisplay'));
return $steps;
} }
/** /**
* Goes to the system courses/categories management page. * Goes to the system courses/categories management page.
* *
* @Given /^I go to the courses management page$/ * @Given /^I go to the courses management page$/
* @return Given[]
*/ */
public function i_go_to_the_courses_management_page() { public function i_go_to_the_courses_management_page() {
return array(
new Given('I am on homepage'), $parentnodes = get_string('administrationsite') . ' > ' . get_string('courses', 'admin');
new Given('I navigate to "' . get_string('coursemgmt', 'admin') . '" node in "' . get_string('administrationsite') . ' > ' . get_string('courses', 'admin') . '"')
// Go to home page.
$this->execute("behat_general::i_am_on_homepage");
// Navigate to course management page via navigation block.
$this->execute("behat_navigation::i_navigate_to_node_in",
array(get_string('coursemgmt', 'admin'), $parentnodes)
); );
} }
/** /**
@@ -133,16 +146,22 @@ class behat_course extends behat_base {
* @param string $activity The activity name * @param string $activity The activity name
* @param int $section The section number * @param int $section The section number
* @param TableNode $data The activity field/value data * @param TableNode $data The activity field/value data
* @return Given[]
*/ */
public function i_add_to_section_and_i_fill_the_form_with($activity, $section, TableNode $data) { public function i_add_to_section_and_i_fill_the_form_with($activity, $section, TableNode $data) {
return array( // Add activity to section.
new Given('I add a "' . $this->escape($activity) . '" to section "' . $this->escape($section) . '"'), $this->execute("behat_course::i_add_to_section",
new Given('I wait to be redirected'), array($this->escape($activity), $this->escape($section))
new Given('I set the following fields to these values:', $data),
new Given('I press "' . get_string('savechangesandreturntocourse') . '"')
); );
// Wait to be redirected.
$this->execute('behat_general::wait_until_the_page_is_ready');
// Set form fields.
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
// Save course settings.
$this->execute("behat_forms::press_button", get_string('savechangesandreturntocourse'));
} }
/** /**
@@ -234,7 +253,6 @@ class behat_course extends behat_base {
* *
* @Given /^I delete section "(?P<section_number>\d+)"$/ * @Given /^I delete section "(?P<section_number>\d+)"$/
* @param int $sectionnumber The section number * @param int $sectionnumber The section number
* @return Given[]
*/ */
public function i_delete_section($sectionnumber) { public function i_delete_section($sectionnumber) {
// Ensures the section exists. // Ensures the section exists.
@@ -253,7 +271,11 @@ class behat_course extends behat_base {
$this->i_open_section_edit_menu($sectionnumber); $this->i_open_section_edit_menu($sectionnumber);
} }
return new Given('I click on "' . $strdelete . '" "link" in the "' . $this->escape($xpath) . '" "xpath_element"'); // Click on delete link.
$this->execute('behat_general::i_click_on_in_the',
array($strdelete, "link", $this->escape($xpath), "xpath_element")
);
} }
/** /**
@@ -261,7 +283,6 @@ class behat_course extends behat_base {
* *
* @Given /^I turn section "(?P<section_number>\d+)" highlighting on$/ * @Given /^I turn section "(?P<section_number>\d+)" highlighting on$/
* @param int $sectionnumber The section number * @param int $sectionnumber The section number
* @return Given[]
*/ */
public function i_turn_section_highlighting_on($sectionnumber) { public function i_turn_section_highlighting_on($sectionnumber) {
@@ -273,7 +294,10 @@ class behat_course extends behat_base {
$this->i_open_section_edit_menu($sectionnumber); $this->i_open_section_edit_menu($sectionnumber);
} }
return new Given('I click on "' . get_string('markthistopic') . '" "link" in the "' . $this->escape($xpath) . '" "xpath_element"'); // Click on highlight topic link.
$this->execute('behat_general::i_click_on_in_the',
array(get_string('markthistopic'), "link", $this->escape($xpath), "xpath_element")
);
} }
/** /**
@@ -281,7 +305,6 @@ class behat_course extends behat_base {
* *
* @Given /^I turn section "(?P<section_number>\d+)" highlighting off$/ * @Given /^I turn section "(?P<section_number>\d+)" highlighting off$/
* @param int $sectionnumber The section number * @param int $sectionnumber The section number
* @return Given[]
*/ */
public function i_turn_section_highlighting_off($sectionnumber) { public function i_turn_section_highlighting_off($sectionnumber) {
@@ -293,7 +316,10 @@ class behat_course extends behat_base {
$this->i_open_section_edit_menu($sectionnumber); $this->i_open_section_edit_menu($sectionnumber);
} }
return new Given('I click on "' . get_string('markedthistopic') . '" "link" in the "' . $this->escape($xpath) . '" "xpath_element"'); // Click on un-highlight topic link.
$this->execute('behat_general::i_click_on_in_the',
array(get_string('markedthistopic'), "link", $this->escape($xpath), "xpath_element")
);
} }
/** /**
@@ -358,7 +384,11 @@ class behat_course extends behat_base {
$stredit = get_string('editsection'); $stredit = get_string('editsection');
} }
return new Given('I click on "' . $stredit . '" "link" in the "#section-' . $sectionnumber . '" "css_element"'); // Click on un-highlight topic link.
$this->execute('behat_general::i_click_on_in_the',
array($stredit, "link", "#section-" . $sectionnumber, "css_element")
);
} }
/** /**
@@ -367,15 +397,17 @@ class behat_course extends behat_base {
* @When /^I edit the section "(?P<section_number>\d+)" and I fill the form with:$/ * @When /^I edit the section "(?P<section_number>\d+)" and I fill the form with:$/
* @param int $sectionnumber The section number * @param int $sectionnumber The section number
* @param TableNode $data The activity field/value data * @param TableNode $data The activity field/value data
* @return Given[]
*/ */
public function i_edit_the_section_and_i_fill_the_form_with($sectionnumber, TableNode $data) { public function i_edit_the_section_and_i_fill_the_form_with($sectionnumber, TableNode $data) {
return array( // Edit given section.
new Given('I edit the section "' . $sectionnumber . '"'), $this->execute("behat_course::i_edit_the_section");
new Given('I set the following fields to these values:', $data),
new Given('I press "' . get_string('savechanges') . '"') // Set form fields.
); $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
// Save section settings.
$this->execute("behat_forms::press_button", get_string('savechanges'));
} }
/** /**
@@ -632,7 +664,6 @@ class behat_course extends behat_base {
* @Given /^I move "(?P<activity_name_string>(?:[^"]|\\")*)" activity to section "(?P<section_number>\d+)"$/ * @Given /^I move "(?P<activity_name_string>(?:[^"]|\\")*)" activity to section "(?P<section_number>\d+)"$/
* @param string $activityname The activity name * @param string $activityname The activity name
* @param int $sectionnumber The number of section * @param int $sectionnumber The number of section
* @return Given[]
*/ */
public function i_move_activity_to_section($activityname, $sectionnumber) { public function i_move_activity_to_section($activityname, $sectionnumber) {
@@ -646,18 +677,21 @@ class behat_course extends behat_base {
$destinationxpath = $sectionxpath . "/descendant::ul[contains(concat(' ', normalize-space(@class), ' '), ' yui3-dd-drop ')]"; $destinationxpath = $sectionxpath . "/descendant::ul[contains(concat(' ', normalize-space(@class), ' '), ' yui3-dd-drop ')]";
return array( $this->execute("behat_general::i_drag_and_i_drop_it_in",
new Given('I drag "' . $this->escape($activitynode->getXpath()) . '" "xpath_element" ' . array($this->escape($activitynode->getXpath()), "xpath_element",
'and I drop it in "' . $this->escape($destinationxpath) . '" "xpath_element"'), $this->escape($destinationxpath), "xpath_element")
); );
} else { } else {
// Following links with no-JS. // Following links with no-JS.
// Moving to the fist spot of the section (before all other section's activities). // Moving to the fist spot of the section (before all other section's activities).
return array( $this->execute('behat_course::i_click_on_in_the_activity',
new Given('I click on "a.editing_move" "css_element" in the "' . $this->escape($activityname) . '" activity'), array("a.editing_move", "css_element", $this->escape($activityname))
new Given('I click on "li.movehere a" "css_element" in the "' . $this->escape($sectionxpath) . '" "xpath_element"'), );
$this->execute('behat_general::i_click_on_in_the',
array("li.movehere a", "css_element", $this->escape($sectionxpath), "xpath_element")
); );
} }
} }
@@ -669,7 +703,6 @@ class behat_course extends behat_base {
* @throws DriverException Step not available when Javascript is disabled * @throws DriverException Step not available when Javascript is disabled
* @param string $activityname * @param string $activityname
* @param string $newactivityname * @param string $newactivityname
* @return Given[]
*/ */
public function i_change_activity_name_to($activityname, $newactivityname) { public function i_change_activity_name_to($activityname, $newactivityname) {
@@ -677,12 +710,17 @@ class behat_course extends behat_base {
throw new DriverException('Change activity name step is not available with Javascript disabled'); throw new DriverException('Change activity name step is not available with Javascript disabled');
} }
// Adding chr(10) to save changes.
$activity = $this->escape($activityname); $activity = $this->escape($activityname);
return array(
new Given('I click on "' . get_string('edittitle') . '" "link" in the "' . $activity .'" activity'), $this->execute('behat_course::i_click_on_in_the_activity',
new Given('I set the field "title" to "' . $this->escape($newactivityname) . chr(10) . '"') array(get_string('edittitle'), "link", $activity)
); );
// Adding chr(10) to save changes.
$this->execute('behat_forms::i_set_the_field_to',
array('title', $this->escape($newactivityname) . chr(10))
);
} }
/** /**
@@ -691,7 +729,6 @@ class behat_course extends behat_base {
* @Given /^I open "(?P<activity_name_string>(?:[^"]|\\")*)" actions menu$/ * @Given /^I open "(?P<activity_name_string>(?:[^"]|\\")*)" actions menu$/
* @throws DriverException The step is not available when Javascript is disabled * @throws DriverException The step is not available when Javascript is disabled
* @param string $activityname * @param string $activityname
* @return Given
*/ */
public function i_open_actions_menu($activityname) { public function i_open_actions_menu($activityname) {
@@ -706,7 +743,10 @@ class behat_course extends behat_base {
return; return;
} }
return new Given('I click on "a[role=\'menuitem\']" "css_element" in the "' . $this->escape($activityname) . '" activity'); $this->execute('behat_course::i_click_on_in_the_activity',
array("a[role='menuitem']", "css_element", $this->escape($activityname))
);
} }
/** /**
@@ -715,7 +755,6 @@ class behat_course extends behat_base {
* @Given /^I close "(?P<activity_name_string>(?:[^"]|\\")*)" actions menu$/ * @Given /^I close "(?P<activity_name_string>(?:[^"]|\\")*)" actions menu$/
* @throws DriverException The step is not available when Javascript is disabled * @throws DriverException The step is not available when Javascript is disabled
* @param string $activityname * @param string $activityname
* @return Given
*/ */
public function i_close_actions_menu($activityname) { public function i_close_actions_menu($activityname) {
@@ -730,7 +769,9 @@ class behat_course extends behat_base {
return; return;
} }
return new Given('I click on "a[role=\'menuitem\']" "css_element" in the "' . $this->escape($activityname) . '" activity'); $this->execute('behat_course::i_click_on_in_the_activity',
array("a[role='menuitem']", "css_element", $this->escape($activityname))
);
} }
/** /**
@@ -752,8 +793,6 @@ class behat_course extends behat_base {
if (empty($classes['action-menu-shown'])) { if (empty($classes['action-menu-shown'])) {
throw new ExpectationException(sprintf("The action menu for '%s' is not open", $activityname), $this->getSession()); throw new ExpectationException(sprintf("The action menu for '%s' is not open", $activityname), $this->getSession());
} }
return;
} }
/** /**
@@ -761,18 +800,18 @@ class behat_course extends behat_base {
* *
* @Given /^I indent right "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/ * @Given /^I indent right "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
* @param string $activityname * @param string $activityname
* @return Given[]
*/ */
public function i_indent_right_activity($activityname) { public function i_indent_right_activity($activityname) {
$steps = array();
$activity = $this->escape($activityname); $activity = $this->escape($activityname);
if ($this->running_javascript()) { if ($this->running_javascript()) {
$steps[] = new Given('I open "' . $activity . '" actions menu'); $this->i_open_actions_menu($activity);
} }
$steps[] = new Given('I click on "' . get_string('moveright') . '" "link" in the "' . $activity . '" activity');
return $steps; $this->execute('behat_course::i_click_on_in_the_activity',
array(get_string('moveright'), "link", $this->escape($activity))
);
} }
/** /**
@@ -780,18 +819,17 @@ class behat_course extends behat_base {
* *
* @Given /^I indent left "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/ * @Given /^I indent left "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
* @param string $activityname * @param string $activityname
* @return Given[]
*/ */
public function i_indent_left_activity($activityname) { public function i_indent_left_activity($activityname) {
$steps = array();
$activity = $this->escape($activityname); $activity = $this->escape($activityname);
if ($this->running_javascript()) { if ($this->running_javascript()) {
$steps[] = new Given('I open "' . $activity . '" actions menu'); $this->i_open_actions_menu($activity);
} }
$steps[] = new Given('I click on "' . get_string('moveleft') . '" "link" in the "' . $activity . '" activity');
return $steps; $this->execute('behat_course::i_click_on_in_the_activity',
array(get_string('moveleft'), "link", $this->escape($activity))
);
} }
@@ -800,23 +838,27 @@ class behat_course extends behat_base {
* *
* @Given /^I delete "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/ * @Given /^I delete "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
* @param string $activityname * @param string $activityname
* @return Given[]
*/ */
public function i_delete_activity($activityname) { public function i_delete_activity($activityname) {
$steps = array(); $steps = array();
$activity = $this->escape($activityname); $activity = $this->escape($activityname);
if ($this->running_javascript()) { if ($this->running_javascript()) {
$steps[] = new Given('I open "' . $activity . '" actions menu'); $this->i_open_actions_menu($activity);
} }
$steps[] = new Given('I click on "' . get_string('delete') . '" "link" in the "' . $activity . '" activity');
$this->execute('behat_course::i_click_on_in_the_activity',
array(get_string('delete'), "link", $this->escape($activity))
);
// JS enabled. // JS enabled.
// Not using chain steps here because the exceptions catcher have problems detecting // Not using chain steps here because the exceptions catcher have problems detecting
// JS modal windows and avoiding interacting them at the same time. // JS modal windows and avoiding interacting them at the same time.
if ($this->running_javascript()) { if ($this->running_javascript()) {
$steps[] = new Given('I click on "' . get_string('yes') . '" "button" in the "Confirm" "dialogue"'); $this->execute('behat_general::i_click_on_in_the',
array(get_string('yes'), "button", "Confirm", "dialogue")
);
} else { } else {
$steps[] = new Given('I press "' . get_string('yes') . '"'); $this->execute("behat_forms::press_button", get_string('yes'));
} }
return $steps; return $steps;
@@ -827,16 +869,17 @@ class behat_course extends behat_base {
* *
* @Given /^I duplicate "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/ * @Given /^I duplicate "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
* @param string $activityname * @param string $activityname
* @return Given[]
*/ */
public function i_duplicate_activity($activityname) { public function i_duplicate_activity($activityname) {
$steps = array(); $steps = array();
$activity = $this->escape($activityname); $activity = $this->escape($activityname);
if ($this->running_javascript()) { if ($this->running_javascript()) {
$steps[] = new Given('I open "' . $activity . '" actions menu'); $this->i_open_actions_menu($activity);
} }
$steps[] = new Given('I click on "' . get_string('duplicate') . '" "link" in the "' . $activity . '" activity'); $this->execute('behat_course::i_click_on_in_the_activity',
return $steps; array(get_string('duplicate'), "link", $activity)
);
} }
/** /**
@@ -845,16 +888,13 @@ class behat_course extends behat_base {
* @Given /^I duplicate "(?P<activity_name_string>(?:[^"]|\\")*)" activity editing the new copy with:$/ * @Given /^I duplicate "(?P<activity_name_string>(?:[^"]|\\")*)" activity editing the new copy with:$/
* @param string $activityname * @param string $activityname
* @param TableNode $data * @param TableNode $data
* @return Given[]
*/ */
public function i_duplicate_activity_editing_the_new_copy_with($activityname, TableNode $data) { public function i_duplicate_activity_editing_the_new_copy_with($activityname, TableNode $data) {
$steps = array();
$activity = $this->escape($activityname); $activity = $this->escape($activityname);
$activityliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($activityname); $activityliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($activityname);
$steps[] = new Given('I duplicate "' . $activity . '" activity'); $this->execute("behat_course::i_duplicate_activity", $activity);
// Determine the future new activity xpath from the former one. // Determine the future new activity xpath from the former one.
$duplicatedxpath = "//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')]" . $duplicatedxpath = "//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')]" .
@@ -868,24 +908,28 @@ class behat_course extends behat_base {
"/ancestor::li[contains(concat(' ', normalize-space(@class), ' '), ' section ')]" . "/ancestor::li[contains(concat(' ', normalize-space(@class), ' '), ' section ')]" .
"/descendant::div[contains(concat(' ', @class, ' '), ' lightbox ')][contains(@style, 'display: none')]"; "/descendant::div[contains(concat(' ', @class, ' '), ' lightbox ')][contains(@style, 'display: none')]";
$steps[] = new Given('I wait until the page is ready'); $this->execute("behat_general::wait_until_exists",
$steps[] = new Given('I wait until "' . $this->escape($hiddenlightboxxpath) .'" "xpath_element" exists'); array($this->escape($hiddenlightboxxpath), "xpath_element")
);
// Close the original activity actions menu. // Close the original activity actions menu.
$steps[] = new Given('I close "' . $activity . '" actions menu'); $this->i_close_actions_menu($activity);
// The next sibling of the former activity will be the duplicated one, so we click on it from it's xpath as, at // The next sibling of the former activity will be the duplicated one, so we click on it from it's xpath as, at
// this point, it don't even exists in the DOM (the steps are executed when we return them). // this point, it don't even exists in the DOM (the steps are executed when we return them).
$steps[] = new Given('I click on "' . $this->escape($duplicatedactionsmenuxpath) . '" "xpath_element"'); $this->execute('behat_general::i_click_on',
array($this->escape($duplicatedactionsmenuxpath), "xpath_element")
);
} }
// We force the xpath as otherwise mink tries to interact with the former one. // We force the xpath as otherwise mink tries to interact with the former one.
$steps[] = new Given('I click on "' . get_string('editsettings') . '" "link" in the "' . $this->execute('behat_general::i_click_on_in_the',
$this->escape($duplicatedxpath) . '" "xpath_element"'); array(get_string('editsettings'), "link", $this->escape($duplicatedxpath), "xpath_element")
);
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
$this->execute("behat_forms::press_button", get_string('savechangesandreturntocourse'));
$steps[] = new Given('I set the following fields to these values:', $data);
$steps[] = new Given('I press "' . get_string('savechangesandreturntocourse') . '"');
return $steps;
} }
/** /**
@@ -1280,14 +1324,16 @@ class behat_course extends behat_base {
* *
* @Given /^I move category "(?P<name_string>(?:[^"]|\\")*)" to top level in the management interface$/ * @Given /^I move category "(?P<name_string>(?:[^"]|\\")*)" to top level in the management interface$/
* @param string $name * @param string $name
* @return Given[]
*/ */
public function i_move_category_to_top_level_in_the_management_interface($name) { public function i_move_category_to_top_level_in_the_management_interface($name) {
$this->i_select_category_in_the_management_interface($name); $this->i_select_category_in_the_management_interface($name);
return array(
new Given('I set the field "menumovecategoriesto" to "' . coursecat::get(0)->get_formatted_name() . '"'), $this->execute('behat_forms::i_set_the_field_to',
new Given('I press "bulkmovecategories"'), array('menumovecategoriesto', coursecat::get(0)->get_formatted_name())
); );
// Save event.
$this->execute("behat_forms::press_button", "bulkmovecategories");
} }
/** /**
@@ -1532,29 +1578,31 @@ class behat_course extends behat_base {
* *
* @Given /^I should see the "(?P<mode_string>(?:[^"]|\\")*)" management page$/ * @Given /^I should see the "(?P<mode_string>(?:[^"]|\\")*)" management page$/
* @param string $mode The mode to expected. One of 'Courses', 'Course categories' or 'Course categories and courses' * @param string $mode The mode to expected. One of 'Courses', 'Course categories' or 'Course categories and courses'
* @return Given[]
*/ */
public function i_should_see_the_courses_management_page($mode) { public function i_should_see_the_courses_management_page($mode) {
$return = array( $this->execute("behat_general::assert_element_contains_text",
new Given('I should see "Course and category management" in the "h2" "css_element"') array("Course and category management", "h2", "css_element")
); );
switch ($mode) { switch ($mode) {
case "Courses": case "Courses":
$return[] = new Given('"#category-listing" "css_element" should not exist'); $this->execute("behat_general::should_not_exist", array("#category-listing", "css_element"));
$return[] = new Given('"#course-listing" "css_element" should exist'); $this->execute("behat_general::should_exist", array("#course-listing", "css_element"));
break; break;
case "Course categories": case "Course categories":
$return[] = new Given('"#category-listing" "css_element" should exist'); $this->execute("behat_general::should_exist", array("#category-listing", "css_element"));
$return[] = new Given('"#course-listing" "css_element" should exist'); $this->execute("behat_general::should_exist", array("#course-listing", "css_element"));
break; break;
case "Courses categories and courses": case "Courses categories and courses":
default: default:
$return[] = new Given('"#category-listing" "css_element" should exist'); $this->execute("behat_general::should_exist", array("#category-listing", "css_element"));
$return[] = new Given('"#course-listing" "css_element" should exist'); $this->execute("behat_general::should_exist", array("#course-listing", "css_element"));
break; break;
} }
$return[] = new Given('"#course-detail" "css_element" should not exist');
return $return; $this->execute("behat_general::should_not_exist", array("#course-detail", "css_element"));
} }
/** /**
@@ -1562,13 +1610,30 @@ class behat_course extends behat_base {
* *
* @Given /^I should see the "(?P<mode_string>(?:[^"]|\\")*)" management page with a course selected$/ * @Given /^I should see the "(?P<mode_string>(?:[^"]|\\")*)" management page with a course selected$/
* @param string $mode The mode to expected. One of 'Courses', 'Course categories' or 'Course categories and courses' * @param string $mode The mode to expected. One of 'Courses', 'Course categories' or 'Course categories and courses'
* @return Given[]
*/ */
public function i_should_see_the_courses_management_page_with_a_course_selected($mode) { public function i_should_see_the_courses_management_page_with_a_course_selected($mode) {
$return = $this->i_should_see_the_courses_management_page($mode); $this->execute("behat_general::assert_element_contains_text",
array_pop($return); array("Course and category management", "h2", "css_element"));
$return[] = new Given('"#course-detail" "css_element" should exist');
return $return; switch ($mode) {
case "Courses":
$this->execute("behat_general::should_not_exist", array("#category-listing", "css_element"));
$this->execute("behat_general::should_exist", array("#course-listing", "css_element"));
break;
case "Course categories":
$this->execute("behat_general::should_exist", array("#category-listing", "css_element"));
$this->execute("behat_general::should_exist", array("#course-listing", "css_element"));
break;
case "Courses categories and courses":
default:
$this->execute("behat_general::should_exist", array("#category-listing", "css_element"));
$this->execute("behat_general::should_exist", array("#course-listing", "css_element"));
break;
}
$this->execute("behat_general::should_exist", array("#course-detail", "css_element"));
} }
/** /**

View File

@@ -27,8 +27,7 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given, use Behat\Gherkin\Node\TableNode as TableNode;
Behat\Gherkin\Node\TableNode as TableNode;
/** /**
* Steps definitions for general enrolment actions. * Steps definitions for general enrolment actions.
@@ -48,14 +47,23 @@ class behat_enrol extends behat_base {
* @param TableNode $table * @param TableNode $table
*/ */
public function i_add_enrolment_method_with($enrolmethod, TableNode $table) { public function i_add_enrolment_method_with($enrolmethod, TableNode $table) {
return array( // Navigate to enrolment method page.
new Given('I expand "' . get_string('users', 'admin') . '" node'), $parentnodes = get_string('courseadministration') . ' > ' . get_string('users', 'admin');
new Given('I follow "' . get_string('type_enrol_plural', 'plugin') . '"'), $this->execute("behat_navigation::i_navigate_to_node_in",
new Given('I select "' . $this->escape($enrolmethod) . '" from the "' . array(get_string('type_enrol_plural', 'plugin'), $parentnodes)
get_string('addinstance', 'enrol') . '" singleselect'),
new Given('I set the following fields to these values:', $table),
new Given('I press "' . get_string('addinstance', 'enrol') . '"'),
); );
// Select enrolment method.
$this->execute('behat_forms::i_select_from_the_singleselect',
array($this->escape($enrolmethod), get_string('addinstance', 'enrol'))
);
// Set form fields.
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
// Save changes.
$this->execute("behat_forms::press_button", get_string('addinstance', 'enrol'));
} }
/** /**
@@ -67,33 +75,34 @@ class behat_enrol extends behat_base {
* @Given /^I enrol "(?P<user_fullname_string>(?:[^"]|\\")*)" user as "(?P<rolename_string>(?:[^"]|\\")*)"$/ * @Given /^I enrol "(?P<user_fullname_string>(?:[^"]|\\")*)" user as "(?P<rolename_string>(?:[^"]|\\")*)"$/
* @param string $userfullname * @param string $userfullname
* @param string $rolename * @param string $rolename
* @return Given[]
*/ */
public function i_enrol_user_as($userfullname, $rolename) { public function i_enrol_user_as($userfullname, $rolename) {
$steps = array( // Navigate to enrolment page.
new Given('I follow "' . get_string('enrolledusers', 'enrol') . '"'), $parentnodes = get_string('courseadministration') . ' > ' . get_string('users', 'admin');
new Given('I press "' . get_string('enrolusers', 'enrol') . '"') $this->execute("behat_navigation::i_navigate_to_node_in",
array(get_string('enrolledusers', 'enrol'), $parentnodes)
); );
$this->execute("behat_forms::press_button", get_string('enrolusers', 'enrol'));
$this->execute('behat_forms::i_set_the_field_to', array(get_string('assignroles', 'role'), $rolename));
if ($this->running_javascript()) { if ($this->running_javascript()) {
// We have a div here, not a tr. // We have a div here, not a tr.
$userliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname); $userliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname);
$userrowxpath = "//div[contains(concat(' ',normalize-space(@class),' '),' user ')][contains(., $userliteral)]"; $userrowxpath = "//div[contains(concat(' ',normalize-space(@class),' '),' user ')][contains(., $userliteral)]";
$steps[] = new Given('I set the field "' . get_string('assignroles', 'role') . '" to "' . $rolename . '"'); $this->execute('behat_general::i_click_on_in_the',
$steps[] = new Given('I click on "' . get_string('enrol', 'enrol') . '" "button" in the "' . $userrowxpath . '" "xpath_element"'); array(get_string('enrol', 'enrol'), "button", $userrowxpath, "xpath_element")
$steps[] = new Given('I press "' . get_string('finishenrollingusers', 'enrol') . '"'); );
$this->execute("behat_forms::press_button", get_string('finishenrollingusers', 'enrol'));
} else { } else {
$this->execute('behat_forms::i_set_the_field_to', array("addselect", $userfullname));
$steps[] = new Given('I set the field "' . get_string('assignrole', 'role') . '" to "' . $rolename . '"'); $this->execute("behat_forms::press_button", "add");
$steps[] = new Given('I set the field "addselect" to "' . $userfullname . '"');
$steps[] = new Given('I press "add"');
} }
return $steps;
} }
} }

View File

@@ -26,9 +26,6 @@
require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');
use Behat\Gherkin\Node\TableNode as TableNode, use Behat\Gherkin\Node\TableNode as TableNode,
Moodle\BehatExtension\Context\Step\Given as Given,
Moodle\BehatExtension\Context\Step\When as When,
Moodle\BehatExtension\Context\Step\Then as Then,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException, Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
Behat\Mink\Exception\ExpectationException as ExpectationException; Behat\Mink\Exception\ExpectationException as ExpectationException;
@@ -162,9 +159,6 @@ class behat_gradingform_guide extends behat_base {
$stepusage = '"I grade by filling the rubric with:" step needs you to provide a table where each row is a criterion' . $stepusage = '"I grade by filling the rubric with:" step needs you to provide a table where each row is a criterion' .
' and each criterion has 3 different values: | Criterion name | Number of points | Remark text |'; ' and each criterion has 3 different values: | Criterion name | Number of points | Remark text |';
// To fill with the steps to execute.
$steps = array();
// First element -> name, second -> points, third -> Remark. // First element -> name, second -> points, third -> Remark.
foreach ($criteria as $name => $criterion) { foreach ($criteria as $name => $criterion) {
@@ -192,12 +186,11 @@ class behat_gradingform_guide extends behat_base {
if ($criterionid) { if ($criterionid) {
$criterionroot = 'advancedgrading[criteria]' . '[' . $criterionid . ']'; $criterionroot = 'advancedgrading[criteria]' . '[' . $criterionid . ']';
$steps[] = new Given('I set the field "' . $criterionroot . '[score]' . '" to "' . $points . '"'); $this->execute('behat_forms::i_set_the_field_to', array($criterionroot . '[score]', $points));
$steps[] = new Given('I set the field "' . $criterionroot . '[remark]' . '" to "' . $criterion[1] . '"');
}
}
return $steps; $this->execute('behat_forms::i_set_the_field_to', array($criterionroot . '[remark]', $criterion[1]));
}
}
} }
/** /**

View File

@@ -28,7 +28,6 @@
require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');
use Behat\Gherkin\Node\TableNode as TableNode, use Behat\Gherkin\Node\TableNode as TableNode,
Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException, Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
Behat\Mink\Exception\ExpectationException as ExpectationException; Behat\Mink\Exception\ExpectationException as ExpectationException;
@@ -225,7 +224,6 @@ class behat_gradingform_rubric extends behat_base {
* @param string $currentvalue * @param string $currentvalue
* @param string $value * @param string $value
* @param string $criterionname * @param string $criterionname
* @return Given[]
*/ */
public function i_replace_rubric_level_with($currentvalue, $value, $criterionname) { public function i_replace_rubric_level_with($currentvalue, $value, $criterionname) {
@@ -275,7 +273,6 @@ class behat_gradingform_rubric extends behat_base {
* *
* @throws ExpectationException * @throws ExpectationException
* @param TableNode $rubric * @param TableNode $rubric
* @return void
*/ */
public function i_grade_by_filling_the_rubric_with(TableNode $rubric) { public function i_grade_by_filling_the_rubric_with(TableNode $rubric) {
@@ -284,9 +281,6 @@ class behat_gradingform_rubric extends behat_base {
$stepusage = '"I grade by filling the rubric with:" step needs you to provide a table where each row is a criterion' . $stepusage = '"I grade by filling the rubric with:" step needs you to provide a table where each row is a criterion' .
' and each criterion has 3 different values: | Criterion name | Number of points | Remark text |'; ' and each criterion has 3 different values: | Criterion name | Number of points | Remark text |';
// To fill with the steps to execute.
$steps = array();
// First element -> name, second -> points, third -> Remark. // First element -> name, second -> points, third -> Remark.
foreach ($criteria as $name => $criterion) { foreach ($criteria as $name => $criterion) {
@@ -311,8 +305,9 @@ class behat_gradingform_rubric extends behat_base {
// Using in_array() as there are only a few elements. // Using in_array() as there are only a few elements.
if (!in_array('checked', explode(' ', $levelnode->getAttribute('class')))) { if (!in_array('checked', explode(' ', $levelnode->getAttribute('class')))) {
$steps[] = new Given('I click on "' . $selectedlevelxpath . '" "xpath_element" in the "' . $this->execute('behat_general::i_click_on_in_the',
$this->escape($name) . '" "table_row"'); array($selectedlevelxpath, "xpath_element", $this->escape($name), "table_row")
);
} }
} else { } else {
@@ -321,7 +316,6 @@ class behat_gradingform_rubric extends behat_base {
$radioxpath = $this->get_criterion_xpath($name) . $radioxpath = $this->get_criterion_xpath($name) .
$selectedlevelxpath . "/descendant::input[@type='radio']"; $selectedlevelxpath . "/descendant::input[@type='radio']";
$radionode = $this->find('xpath', $radioxpath); $radionode = $this->find('xpath', $radioxpath);
// TODO MDL-43738: Change setValue() to use the generic set_value()
// which will delegate the process to the field type. // which will delegate the process to the field type.
$radionode->setValue($radionode->getAttribute('value')); $radionode->setValue($radionode->getAttribute('value'));
} }
@@ -330,10 +324,8 @@ class behat_gradingform_rubric extends behat_base {
// First we need to get the textarea name, then we can set the value. // First we need to get the textarea name, then we can set the value.
$textarea = $this->get_node_in_container('css_element', 'textarea', 'table_row', $name); $textarea = $this->get_node_in_container('css_element', 'textarea', 'table_row', $name);
$steps[] = new Given('I set the field "' . $textarea->getAttribute('name') . '" to "' . $criterion[1] . '"'); $this->execute('behat_forms::i_set_the_field_to', array($textarea->getAttribute('name'), $criterion[1]));
} }
return $steps;
} }
/** /**

View File

@@ -27,9 +27,7 @@
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
use Behat\Gherkin\Node\TableNode as TableNode, use Behat\Gherkin\Node\TableNode as TableNode;
Moodle\BehatExtension\Context\Step\Given as Given,
Moodle\BehatExtension\Context\Step\When as When;
/** /**
* Generic grading methods step definitions. * Generic grading methods step definitions.
@@ -46,13 +44,12 @@ class behat_grading extends behat_base {
* *
* @Given /^I go to "(?P<activity_name_string>(?:[^"]|\\")*)" advanced grading page$/ * @Given /^I go to "(?P<activity_name_string>(?:[^"]|\\")*)" advanced grading page$/
* @param string $activityname * @param string $activityname
* @return Given[]
*/ */
public function i_go_to_advanced_grading_page($activityname) { public function i_go_to_advanced_grading_page($activityname) {
return array(
new Given('I follow "' . $this->escape($activityname) . '"'), $this->execute('behat_general::click_link', $this->escape($activityname));
new Given('I follow "' . get_string('gradingmanagement', 'grading') . '"'),
); $this->execute('behat_general::click_link', get_string('gradingmanagement', 'grading'));
} }
/** /**
@@ -60,7 +57,6 @@ class behat_grading extends behat_base {
* *
* @Given /^I go to "(?P<activity_name_string>(?:[^"]|\\")*)" advanced grading definition page$/ * @Given /^I go to "(?P<activity_name_string>(?:[^"]|\\")*)" advanced grading definition page$/
* @param string $activityname * @param string $activityname
* @return Given[]
*/ */
public function i_go_to_advanced_grading_definition_page($activityname) { public function i_go_to_advanced_grading_definition_page($activityname) {
@@ -72,10 +68,9 @@ class behat_grading extends behat_base {
$definitionxpath = "//a[@class='action']" . $definitionxpath = "//a[@class='action']" .
"[./descendant::*[contains(., $newactionliteral) or contains(., $editactionliteral)]]"; "[./descendant::*[contains(., $newactionliteral) or contains(., $editactionliteral)]]";
return array( $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
new Given('I go to "' . $this->escape($activityname) . '" advanced grading page'),
new Given('I click on "' . $this->escape($definitionxpath) . '" "xpath_element"'), $this->execute("behat_general::i_click_on", array($this->escape($definitionxpath), "xpath_element"));
);
} }
/** /**
* Goes to the student's advanced grading page. * Goes to the student's advanced grading page.
@@ -83,25 +78,25 @@ class behat_grading extends behat_base {
* @Given /^I go to "(?P<user_fullname_string>(?:[^"]|\\")*)" "(?P<activity_name_string>(?:[^"]|\\")*)" activity advanced grading page$/ * @Given /^I go to "(?P<user_fullname_string>(?:[^"]|\\")*)" "(?P<activity_name_string>(?:[^"]|\\")*)" activity advanced grading page$/
* @param string $userfullname The user full name including firstname and lastname. * @param string $userfullname The user full name including firstname and lastname.
* @param string $activityname The activity name * @param string $activityname The activity name
* @return Given[]
*/ */
public function i_go_to_activity_advanced_grading_page($userfullname, $activityname) { public function i_go_to_activity_advanced_grading_page($userfullname, $activityname) {
// Step to access the user grade page from the grading page. // Step to access the user grade page from the grading page.
$usergradetext = get_string('gradeuser', 'assign', $userfullname); $usergradetext = get_string('gradeuser', 'assign', $userfullname);
$gradeuserstep = new Given('I follow "' . $this->escape($usergradetext) . '"');
// Shortcut in case we already are in the grading page. // Shortcut in case we already are in the grading page.
$usergradetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($usergradetext); $usergradetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($usergradetext);
if ($this->getSession()->getPage()->find('named_partial', array('link', $usergradetextliteral))) { if ($this->getSession()->getPage()->find('named_partial', array('link', $usergradetextliteral))) {
return $gradeuserstep; $this->execute('behat_general::click_link', $this->escape($usergradetext));
return true;
} }
return array( $this->execute('behat_general::click_link', $this->escape($activityname));
new Given('I follow "' . $this->escape($activityname) . '"'),
new Given('I follow "' . $this->escape(get_string('viewgrading', 'assign')) . '"'), $this->execute('behat_general::click_link', $this->escape(get_string('viewgrading', 'assign')));
$gradeuserstep
); $this->execute('behat_general::click_link', $this->escape($usergradetext));
} }
/** /**
@@ -109,15 +104,14 @@ class behat_grading extends behat_base {
* *
* @Given /^I publish "(?P<activity_name_string>(?:[^"]|\\")*)" grading form definition as a public template$/ * @Given /^I publish "(?P<activity_name_string>(?:[^"]|\\")*)" grading form definition as a public template$/
* @param string $activityname * @param string $activityname
* @return Given[]
*/ */
public function i_publish_grading_form_definition_as_a_public_template($activityname) { public function i_publish_grading_form_definition_as_a_public_template($activityname) {
return array( $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
new Given('I go to "' . $this->escape($activityname) . '" advanced grading page'),
new Given('I click on "' . $this->escape(get_string("manageactionshare", "grading")) . '" "link"'), $this->execute("behat_general::i_click_on", array($this->escape(get_string("manageactionshare", "grading")), "link"));
new Given('I press "' . get_string('continue') . '"')
); $this->execute('behat_forms::press_button', get_string('continue'));
} }
/** /**
@@ -126,7 +120,6 @@ class behat_grading extends behat_base {
* @Given /^I set "(?P<activity_name_string>(?:[^"]|\\")*)" activity to use "(?P<grading_form_template_string>(?:[^"]|\\")*)" grading form$/ * @Given /^I set "(?P<activity_name_string>(?:[^"]|\\")*)" activity to use "(?P<grading_form_template_string>(?:[^"]|\\")*)" grading form$/
* @param string $activityname * @param string $activityname
* @param string $templatename * @param string $templatename
* @return Given[]
*/ */
public function i_set_activity_to_use_grading_form($activityname, $templatename) { public function i_set_activity_to_use_grading_form($activityname, $templatename) {
@@ -141,28 +134,29 @@ class behat_grading extends behat_base {
$usetemplatexpath = "/a[./descendant::div[text()=$literaltemplate]]|" . $usetemplatexpath = "/a[./descendant::div[text()=$literaltemplate]]|" .
"/a[./descendant::div[text()=$literalownform]]"; "/a[./descendant::div[text()=$literalownform]]";
return array( $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
new Given('I go to "' . $this->escape($activityname) . '" advanced grading page'),
new Given('I follow "' . $this->escape(get_string('manageactionclone', 'grading')) . '"'), $this->execute('behat_general::click_link', $this->escape(get_string('manageactionclone', 'grading')));
new Given('I set the field "' . get_string('searchownforms', 'grading') . '" to "1"'), $this->execute('behat_forms::i_set_the_field_to', array(get_string('searchownforms', 'grading'), 1));
new Given('I click on "' . get_string('search') . '" "button" in the "region-main" "region"'), $this->execute('behat_general::i_click_on_in_the',
new Given('I click on "' . $this->escape($usetemplatexpath) . '" "xpath_element" ' . array(get_string('search'), "button", "region-main", "region")
'in the "' . $this->escape($templatexpath) . '" "xpath_element"'),
new Given('I press "' . get_string('continue') . '"')
); );
$this->execute('behat_general::i_click_on_in_the',
array($this->escape($usetemplatexpath), "xpath_element", $this->escape($templatexpath), "xpath_element")
);
$this->execute('behat_forms::press_button', get_string('continue'));
} }
/** /**
* Saves the current page advanced grading form. * Saves the current page advanced grading form.
* *
* @When /^I save the advanced grading form$/ * @When /^I save the advanced grading form$/
* @return When[]
*/ */
public function i_save_the_advanced_grading_form() { public function i_save_the_advanced_grading_form() {
return array(
new When('I press "' . get_string('savechanges') . '"'), $this->execute('behat_forms::press_button', get_string('savechanges'));
new When('I press "' . get_string('continue') . '"') $this->execute('behat_forms::press_button', get_string('continue'));
);
} }
/** /**
@@ -170,12 +164,9 @@ class behat_grading extends behat_base {
* *
* @Given /^I complete the advanced grading form with these values:$/ * @Given /^I complete the advanced grading form with these values:$/
* @param TableNode $data * @param TableNode $data
* @return Given[]
*/ */
public function i_complete_the_advanced_grading_form_with_these_values(TableNode $data) { public function i_complete_the_advanced_grading_form_with_these_values(TableNode $data) {
return array( $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
new Given('I set the following fields to these values:', $data), $this->execute('behat_grading::i_save_the_advanced_grading_form');
new Given('I save the advanced grading form')
);
} }
} }

View File

@@ -27,9 +27,7 @@
require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given, use Behat\Mink\Exception\ExpectationException as ExpectationException,
Moodle\BehatExtension\Context\Step\Then,
Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
/** /**
@@ -45,12 +43,11 @@ class behat_gradereport_grader extends behat_base {
* @Given /^I click on student "([^"]*)" for grade item "([^"]*)"$/ * @Given /^I click on student "([^"]*)" for grade item "([^"]*)"$/
* @param string $student * @param string $student
* @param string $itemname * @param string $itemname
* @return Given
*/ */
public function i_click_on_student_and_grade_item($student, $itemname) { public function i_click_on_student_and_grade_item($student, $itemname) {
$xpath = $this->get_student_and_grade_cell_selector($student, $itemname); $xpath = $this->get_student_and_grade_cell_selector($student, $itemname);
return new Given('I click on "' . $this->escape($xpath) . '" "xpath_element"'); $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
} }
/** /**
@@ -59,12 +56,11 @@ class behat_gradereport_grader extends behat_base {
* @Given /^I click away from student "([^"]*)" and grade item "([^"]*)" value$/ * @Given /^I click away from student "([^"]*)" and grade item "([^"]*)" value$/
* @param string $student * @param string $student
* @param string $itemname * @param string $itemname
* @return Given
*/ */
public function i_click_away_from_student_and_grade_value($student, $itemname) { public function i_click_away_from_student_and_grade_value($student, $itemname) {
$xpath = $this->get_student_and_grade_value_selector($student, $itemname); $xpath = $this->get_student_and_grade_value_selector($student, $itemname);
return new Given('I take focus off "' . $this->escape($xpath) . '" "xpath_element"'); $this->execute('behat_general::i_take_focus_off_field', array($this->escape($xpath), 'xpath_element'));
} }
/** /**
@@ -73,12 +69,11 @@ class behat_gradereport_grader extends behat_base {
* @Given /^I click away from student "([^"]*)" and grade item "([^"]*)" feedback$/ * @Given /^I click away from student "([^"]*)" and grade item "([^"]*)" feedback$/
* @param string $student * @param string $student
* @param string $itemname * @param string $itemname
* @return Given
*/ */
public function i_click_away_from_student_and_grade_feedback($student, $itemname) { public function i_click_away_from_student_and_grade_feedback($student, $itemname) {
$xpath = $this->get_student_and_grade_feedback_selector($student, $itemname); $xpath = $this->get_student_and_grade_feedback_selector($student, $itemname);
return new Given('I take focus off "' . $this->escape($xpath) . '" "xpath_element"'); $this->execute('behat_general::i_take_focus_off_field', array($this->escape($xpath), 'xpath_element'));
} }
/** /**
@@ -90,7 +85,6 @@ class behat_gradereport_grader extends behat_base {
* @param string $student * @param string $student
* @param string $itemname * @param string $itemname
* @param string $value * @param string $value
* @return Then
*/ */
public function the_grade_should_match($student, $itemname, $value) { public function the_grade_should_match($student, $itemname, $value) {
$xpath = $this->get_student_and_grade_value_selector($student, $itemname); $xpath = $this->get_student_and_grade_value_selector($student, $itemname);
@@ -131,12 +125,11 @@ class behat_gradereport_grader extends behat_base {
* @Then /^I should see a grade field for "([^"]*)" and grade item "([^"]*)"$/ * @Then /^I should see a grade field for "([^"]*)" and grade item "([^"]*)"$/
* @param string $student * @param string $student
* @param string $itemname * @param string $itemname
* @return Then
*/ */
public function i_should_see_grade_field($student, $itemname) { public function i_should_see_grade_field($student, $itemname) {
$xpath = $this->get_student_and_grade_value_selector($student, $itemname); $xpath = $this->get_student_and_grade_value_selector($student, $itemname);
return new Then('"' . $this->escape($xpath) . '" "xpath_element" should be visible'); $this->execute('behat_general::should_be_visible', array($this->escape($xpath), 'xpath_element'));
} }
/** /**
@@ -145,12 +138,11 @@ class behat_gradereport_grader extends behat_base {
* @Then /^I should see a feedback field for "([^"]*)" and grade item "([^"]*)"$/ * @Then /^I should see a feedback field for "([^"]*)" and grade item "([^"]*)"$/
* @param string $student * @param string $student
* @param string $itemname * @param string $itemname
* @return Then
*/ */
public function i_should_see_feedback_field($student, $itemname) { public function i_should_see_feedback_field($student, $itemname) {
$xpath = $this->get_student_and_grade_feedback_selector($student, $itemname); $xpath = $this->get_student_and_grade_feedback_selector($student, $itemname);
return new Then('"' . $this->escape($xpath) . '" "xpath_element" should be visible'); $this->execute('behat_general::should_be_visible', array($this->escape($xpath), 'xpath_element'));
} }
/** /**
@@ -159,12 +151,11 @@ class behat_gradereport_grader extends behat_base {
* @Then /^I should not see a grade field for "([^"]*)" and grade item "([^"]*)"$/ * @Then /^I should not see a grade field for "([^"]*)" and grade item "([^"]*)"$/
* @param string $student * @param string $student
* @param string $itemname * @param string $itemname
* @return Then
*/ */
public function i_should_not_see_grade_field($student, $itemname) { public function i_should_not_see_grade_field($student, $itemname) {
$xpath = $this->get_student_and_grade_value_selector($student, $itemname); $xpath = $this->get_student_and_grade_value_selector($student, $itemname);
return new Then('"' . $this->escape($xpath) . '" "xpath_element" should not exist'); $this->execute('behat_general::should_not_exist', array($this->escape($xpath), 'xpath_element'));
} }
/** /**
@@ -173,12 +164,11 @@ class behat_gradereport_grader extends behat_base {
* @Then /^I should not see a feedback field for "([^"]*)" and grade item "([^"]*)"$/ * @Then /^I should not see a feedback field for "([^"]*)" and grade item "([^"]*)"$/
* @param string $student * @param string $student
* @param string $itemname * @param string $itemname
* @return Then
*/ */
public function i_should_not_see_feedback_field($student, $itemname) { public function i_should_not_see_feedback_field($student, $itemname) {
$xpath = $this->get_student_and_grade_feedback_selector($student, $itemname); $xpath = $this->get_student_and_grade_feedback_selector($student, $itemname);
return new Then('"' . $this->escape($xpath) . '" "xpath_element" should not exist'); $this->execute('behat_general::should_not_exist', array($this->escape($xpath), 'xpath_element'));
} }
/** /**
@@ -269,5 +259,4 @@ class behat_gradereport_grader extends behat_base {
return $cell . "//input[contains(@id, 'feedback_') or @name='ajaxfeedback']"; return $cell . "//input[contains(@id, 'feedback_') or @name='ajaxfeedback']";
} }
} }

View File

@@ -27,8 +27,7 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given, use Behat\Gherkin\Node\TableNode as TableNode;
Behat\Gherkin\Node\TableNode as TableNode;
class behat_grade extends behat_base { class behat_grade extends behat_base {
@@ -39,13 +38,12 @@ class behat_grade extends behat_base {
* @param int $grade * @param int $grade
* @param string $userfullname the user's fullname as returned by fullname() * @param string $userfullname the user's fullname as returned by fullname()
* @param string $itemname * @param string $itemname
* @return Given
*/ */
public function i_give_the_grade($grade, $userfullname, $itemname) { public function i_give_the_grade($grade, $userfullname, $itemname) {
$gradelabel = $userfullname . ' ' . $itemname; $gradelabel = $userfullname . ' ' . $itemname;
$fieldstr = get_string('useractivitygrade', 'gradereport_grader', $gradelabel); $fieldstr = get_string('useractivitygrade', 'gradereport_grader', $gradelabel);
return new Given('I set the field "' . $this->escape($fieldstr) . '" to "' . $grade . '"'); $this->execute('behat_forms::i_set_the_field_to', array($this->escape($fieldstr), $grade));
} }
/** /**
@@ -56,13 +54,12 @@ class behat_grade extends behat_base {
* @param string $feedback * @param string $feedback
* @param string $userfullname the user's fullname as returned by fullname() * @param string $userfullname the user's fullname as returned by fullname()
* @param string $itemname * @param string $itemname
* @return Given
*/ */
public function i_give_the_feedback($feedback, $userfullname, $itemname) { public function i_give_the_feedback($feedback, $userfullname, $itemname) {
$gradelabel = $userfullname . ' ' . $itemname; $gradelabel = $userfullname . ' ' . $itemname;
$fieldstr = get_string('useractivityfeedback', 'gradereport_grader', $gradelabel); $fieldstr = get_string('useractivityfeedback', 'gradereport_grader', $gradelabel);
return new Given('I set the field "' . $this->escape($fieldstr) . '" to "' . $this->escape($feedback) . '"'); $this->execute('behat_forms::i_set_the_field_to', array($this->escape($fieldstr), $this->escape($feedback)));
} }
/** /**
@@ -73,27 +70,25 @@ class behat_grade extends behat_base {
* @Given /^I set the following settings for grade item "(?P<grade_item_string>(?:[^"]|\\")*)":$/ * @Given /^I set the following settings for grade item "(?P<grade_item_string>(?:[^"]|\\")*)":$/
* @param string $gradeitem * @param string $gradeitem
* @param TableNode $data * @param TableNode $data
* @return Given[]
*/ */
public function i_set_the_following_settings_for_grade_item($gradeitem, TableNode $data) { public function i_set_the_following_settings_for_grade_item($gradeitem, TableNode $data) {
$steps = array();
$gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem); $gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
if ($this->running_javascript()) { if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]"; $xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) { if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$steps[] = new Given('I click on "' . $this->escape($xpath) . '" "xpath_element"'); $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
} }
} }
$savechanges = get_string('savechanges', 'grades'); $savechanges = get_string('savechanges', 'grades');
$edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('edit') . ' '); $edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('edit') . ' ');
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]"; $linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$steps[] = new Given('I click on "' . $this->escape($linkxpath) . '" "xpath_element"');
$steps[] = new Given('I set the following fields to these values:', $data); $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
$steps[] = new Given('I press "' . $this->escape($savechanges) . '"'); $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
return $steps; $this->execute('behat_forms::press_button', $this->escape($savechanges));
} }
/** /**
@@ -104,17 +99,15 @@ class behat_grade extends behat_base {
* @param string $calculation The calculation. * @param string $calculation The calculation.
* @param string $gradeitem The grade item name. * @param string $gradeitem The grade item name.
* @param TableNode $TableNode The grade item name - idnumbers relation. * @param TableNode $TableNode The grade item name - idnumbers relation.
* @return Given[]
*/ */
public function i_set_calculation_for_grade_item_with_idnumbers($calculation, $gradeitem, TableNode $data) { public function i_set_calculation_for_grade_item_with_idnumbers($calculation, $gradeitem, TableNode $data) {
$steps = array();
$gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem); $gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
if ($this->running_javascript()) { if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]"; $xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) { if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$steps[] = new Given('I click on "' . $this->escape($xpath) . '" "xpath_element"'); $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
} }
} }
@@ -122,12 +115,7 @@ class behat_grade extends behat_base {
$savechanges = get_string('savechanges', 'grades'); $savechanges = get_string('savechanges', 'grades');
$edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('editcalculation', 'grades')); $edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('editcalculation', 'grades'));
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]"; $linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$steps[] = new Given('I click on "' . $this->escape($linkxpath) . '" "xpath_element"'); $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
// After adding id numbers we should wait until the page is reloaded.
if ($this->running_javascript()) {
$steps[] = new Given('I wait until the page is ready');
}
// Mapping names to idnumbers. // Mapping names to idnumbers.
$datahash = $data->getRowsHash(); $datahash = $data->getRowsHash();
@@ -139,20 +127,13 @@ class behat_grade extends behat_base {
" or " . " or " .
"parent::li[@class='categoryitem' or @class='courseitem']/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" . "parent::li[@class='categoryitem' or @class='courseitem']/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
"]"; "]";
$steps[] = new Given('I set the field with xpath "' . $inputxpath . '" to "' . $idnumber . '"'); $this->execute('behat_forms::i_set_the_field_with_xpath_to', array($inputxpath, $idnumber));
} }
$steps[] = new Given('I press "' . get_string('addidnumbers', 'grades') . '"'); $this->execute('behat_forms::press_button', get_string('addidnumbers', 'grades'));
$this->execute('behat_forms::i_set_the_field_to', array(get_string('calculation', 'grades'), $calculation));
$this->execute('behat_forms::press_button', $savechanges);
// After adding id numbers we should wait until the page is reloaded.
if ($this->running_javascript()) {
$steps[] = new Given('I wait until the page is ready');
}
$steps[] = new Given('I set the field "' . get_string('calculation', 'grades') . '" to "' . $calculation . '"');
$steps[] = new Given('I press "' . $savechanges . '"');
return $steps;
} }
/** /**
@@ -163,11 +144,9 @@ class behat_grade extends behat_base {
* @param string $calculation The calculation. * @param string $calculation The calculation.
* @param string $gradeitem The grade item name. * @param string $gradeitem The grade item name.
* @param TableNode $data The grade item name - idnumbers relation. * @param TableNode $data The grade item name - idnumbers relation.
* @return Given[]
*/ */
public function i_set_calculation_for_grade_category_with_idnumbers($calculation, $gradeitem, TableNode $data) { public function i_set_calculation_for_grade_category_with_idnumbers($calculation, $gradeitem, TableNode $data) {
$steps = array();
$gradecategorytotal = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem . ' total'); $gradecategorytotal = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem . ' total');
$gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem); $gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
@@ -175,7 +154,7 @@ class behat_grade extends behat_base {
$xpath = "//tr[contains(.,$gradecategorytotal)]//*[contains(@class,'moodle-actionmenu')]" . $xpath = "//tr[contains(.,$gradecategorytotal)]//*[contains(@class,'moodle-actionmenu')]" .
"//a[contains(@class,'toggle-display')]"; "//a[contains(@class,'toggle-display')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) { if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$steps[] = new Given('I click on "' . $this->escape($xpath) . '" "xpath_element"'); $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
} }
} }
@@ -183,10 +162,7 @@ class behat_grade extends behat_base {
$savechanges = get_string('savechanges', 'grades'); $savechanges = get_string('savechanges', 'grades');
$edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('editcalculation', 'grades')); $edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('editcalculation', 'grades'));
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]"; $linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$steps[] = new Given('I click on "' . $this->escape($linkxpath) . '" "xpath_element"'); $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
// After adding id numbers we should wait until the page is reloaded.
$steps[] = new Given('I wait until the page is ready');
// Mapping names to idnumbers. // Mapping names to idnumbers.
$datahash = $data->getRowsHash(); $datahash = $data->getRowsHash();
@@ -199,18 +175,13 @@ class behat_grade extends behat_base {
"parent::li[@class='categoryitem' | @class='courseitem']" . "parent::li[@class='categoryitem' | @class='courseitem']" .
"/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" . "/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
"]"; "]";
$steps[] = new Given('I set the field with xpath "' . $inputxpath . '" to "' . $idnumber . '"'); $this->execute('behat_forms::i_set_the_field_with_xpath_to', array($inputxpath, $idnumber));
} }
$steps[] = new Given('I press "' . get_string('addidnumbers', 'grades') . '"'); $this->execute('behat_forms::press_button', get_string('addidnumbers', 'grades'));
// After adding id numbers we should wait until the page is reloaded. $this->execute('behat_forms::i_set_the_field_to', array(get_string('calculation', 'grades'), $calculation));
$steps[] = new Given('I wait until the page is ready'); $this->execute('behat_forms::press_button', $savechanges);
$steps[] = new Given('I set the field "' . get_string('calculation', 'grades') . '" to "' . $calculation . '"');
$steps[] = new Given('I press "' . $savechanges . '"');
return $steps;
} }
/** /**
@@ -220,7 +191,6 @@ class behat_grade extends behat_base {
* *
* @Given /^I reset weights for grade category "(?P<grade_item_string>(?:[^"]|\\")*)"$/ * @Given /^I reset weights for grade category "(?P<grade_item_string>(?:[^"]|\\")*)"$/
* @param $gradeitem * @param $gradeitem
* @return array
*/ */
public function i_reset_weights_for_grade_category($gradeitem) { public function i_reset_weights_for_grade_category($gradeitem) {
@@ -230,13 +200,12 @@ class behat_grade extends behat_base {
$gradeitemliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem); $gradeitemliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
$xpath = "//tr[contains(.,$gradeitemliteral)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]"; $xpath = "//tr[contains(.,$gradeitemliteral)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) { if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$steps[] = new Given('I click on "' . $this->escape($xpath) . '" "xpath_element"'); $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
} }
} }
$linktext = get_string('resetweights', 'grades', (object)array('itemname' => $gradeitem)); $linktext = get_string('resetweights', 'grades', (object)array('itemname' => $gradeitem));
$steps[] = new Given('I click on "' . $this->escape($linktext) . '" "link"'); $this->execute("behat_general::i_click_on", array($this->escape($linktext), "link"));
return $steps;
} }
/** /**
@@ -245,7 +214,6 @@ class behat_grade extends behat_base {
* @Given /^gradebook calculations for the course "(?P<coursename_string>(?:[^"]|\\")*)" are frozen at version "(?P<version_string>(?:[^"]|\\")*)"$/ * @Given /^gradebook calculations for the course "(?P<coursename_string>(?:[^"]|\\")*)" are frozen at version "(?P<version_string>(?:[^"]|\\")*)"$/
* @param string $coursename * @param string $coursename
* @param string $version * @param string $version
* @return Given
*/ */
public function gradebook_calculations_for_the_course_are_frozen_at_version($coursename, $version) { public function gradebook_calculations_for_the_course_are_frozen_at_version($coursename, $version) {
global $DB; global $DB;

View File

@@ -27,7 +27,6 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Then;
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
/** /**
@@ -96,11 +95,9 @@ class behat_groups extends behat_base {
* @Given /^the group overview should include groups "(?P<groups_string>(?:[^"]|\\")*)" in grouping "(?P<grouping_string>(?:[^"]|\\")*)"$/ * @Given /^the group overview should include groups "(?P<groups_string>(?:[^"]|\\")*)" in grouping "(?P<grouping_string>(?:[^"]|\\")*)"$/
* @param string $groups one or comma seperated list of groups. * @param string $groups one or comma seperated list of groups.
* @param string $grouping grouping in which all group should be present. * @param string $grouping grouping in which all group should be present.
* @return Then[]
*/ */
public function the_groups_overview_should_include_groups_in_grouping($groups, $grouping) { public function the_groups_overview_should_include_groups_in_grouping($groups, $grouping) {
$steps = array();
$groups = array_map('trim', explode(',', $groups)); $groups = array_map('trim', explode(',', $groups));
foreach ($groups as $groupname) { foreach ($groups as $groupname) {
@@ -108,9 +105,7 @@ class behat_groups extends behat_base {
$xpath = "//h3[normalize-space(.) = '{$grouping}']/following-sibling::table//tr//". $xpath = "//h3[normalize-space(.) = '{$grouping}']/following-sibling::table//tr//".
"td[contains(concat(' ', normalize-space(@class), ' '), ' c0 ')][normalize-space(.) = '{$groupname}' ]"; "td[contains(concat(' ', normalize-space(@class), ' '), ' c0 ')][normalize-space(.) = '{$groupname}' ]";
$steps[] = new Then('"'.$xpath.'" "xpath_element" should exist'); $this->execute('behat_general::should_exist', array($xpath, 'xpath_element'));
} }
return $steps;
} }
} }

View File

@@ -681,8 +681,10 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext {
} }
} else if (' . self::PAGE_READY_JS . ') { } else if (' . self::PAGE_READY_JS . ') {
return ""; return "";
} else { } else if (typeof M.util !== "undefined") {
return M.util.pending_js.join(":"); return M.util.pending_js.join(":");
} else {
return "incomplete"
} }
}();'; }();';
$pending = $this->getSession()->evaluateScript($jscode); $pending = $this->getSession()->evaluateScript($jscode);
@@ -713,4 +715,119 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext {
throw new \Exception('Javascript code and/or AJAX requests are not ready after ' . self::EXTENDED_TIMEOUT . throw new \Exception('Javascript code and/or AJAX requests are not ready after ' . self::EXTENDED_TIMEOUT .
' seconds. There is a Javascript error or the code is extremely slow.'); ' seconds. There is a Javascript error or the code is extremely slow.');
} }
/**
* Internal step definition to find exceptions, debugging() messages and PHP debug messages.
*
* Part of behat_hooks class as is part of the testing framework, is auto-executed
* after each step so no features will splicitly use it.
*
* @throws Exception Unknown type, depending on what we caught in the hook or basic \Exception.
* @see Moodle\BehatExtension\Tester\MoodleStepTester
*/
public function look_for_exceptions() {
// Wrap in try in case we were interacting with a closed window.
try {
// Exceptions.
$exceptionsxpath = "//div[@data-rel='fatalerror']";
// Debugging messages.
$debuggingxpath = "//div[@data-rel='debugging']";
// PHP debug messages.
$phperrorxpath = "//div[@data-rel='phpdebugmessage']";
// Any other backtrace.
$othersxpath = "(//*[contains(., ': call to ')])[1]";
$xpaths = array($exceptionsxpath, $debuggingxpath, $phperrorxpath, $othersxpath);
$joinedxpath = implode(' | ', $xpaths);
// Joined xpath expression. Most of the time there will be no exceptions, so this pre-check
// is faster than to send the 4 xpath queries for each step.
if (!$this->getSession()->getDriver()->find($joinedxpath)) {
return;
}
// Exceptions.
if ($errormsg = $this->getSession()->getPage()->find('xpath', $exceptionsxpath)) {
// Getting the debugging info and the backtrace.
$errorinfoboxes = $this->getSession()->getPage()->findAll('css', 'div.alert-error');
// If errorinfoboxes is empty, try find notifytiny (original) class.
if (empty($errorinfoboxes)) {
$errorinfoboxes = $this->getSession()->getPage()->findAll('css', 'div.notifytiny');
}
$errorinfo = $this->get_debug_text($errorinfoboxes[0]->getHtml()) . "\n" .
$this->get_debug_text($errorinfoboxes[1]->getHtml());
$msg = "Moodle exception: " . $errormsg->getText() . "\n" . $errorinfo;
throw new \Exception(html_entity_decode($msg));
}
// Debugging messages.
if ($debuggingmessages = $this->getSession()->getPage()->findAll('xpath', $debuggingxpath)) {
$msgs = array();
foreach ($debuggingmessages as $debuggingmessage) {
$msgs[] = $this->get_debug_text($debuggingmessage->getHtml());
}
$msg = "debugging() message/s found:\n" . implode("\n", $msgs);
throw new \Exception(html_entity_decode($msg));
}
// PHP debug messages.
if ($phpmessages = $this->getSession()->getPage()->findAll('xpath', $phperrorxpath)) {
$msgs = array();
foreach ($phpmessages as $phpmessage) {
$msgs[] = $this->get_debug_text($phpmessage->getHtml());
}
$msg = "PHP debug message/s found:\n" . implode("\n", $msgs);
throw new \Exception(html_entity_decode($msg));
}
// Any other backtrace.
// First looking through xpath as it is faster than get and parse the whole page contents,
// we get the contents and look for matches once we found something to suspect that there is a backtrace.
if ($this->getSession()->getDriver()->find($othersxpath)) {
$backtracespattern = '/(line [0-9]* of [^:]*: call to [\->&;:a-zA-Z_\x7f-\xff][\->&;:a-zA-Z0-9_\x7f-\xff]*)/';
if (preg_match_all($backtracespattern, $this->getSession()->getPage()->getContent(), $backtraces)) {
$msgs = array();
foreach ($backtraces[0] as $backtrace) {
$msgs[] = $backtrace . '()';
}
$msg = "Other backtraces found:\n" . implode("\n", $msgs);
throw new \Exception(htmlentities($msg));
}
}
} catch (NoSuchWindow $e) {
// If we were interacting with a popup window it will not exists after closing it.
}
}
/**
* Helper function to execute api in a given context.
*
* @param string $contextapi context in which api is defined.
* @param array $params list of params to pass.
* @throws Exception
*/
protected function execute($contextapi, $params = array()) {
if (!is_array($params)) {
$params = array($params);
}
// Get required context and execute the api.
$contextapi = explode("::", $contextapi);
$context = behat_context_helper::get($contextapi[0]);
call_user_func_array(array($context, $contextapi[1]), $params);
// NOTE: Wait for pending js and look for exception are not optional, as this might lead to unexpected results.
// Don't make them optional for performance reasons.
// Wait for pending js.
$this->wait_for_pending_js();
// Look for exceptions.
$this->look_for_exceptions();
}
} }

View File

@@ -28,8 +28,6 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException, use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
Moodle\BehatExtension\Context\Step\Given as Given,
Moodle\BehatExtension\Context\Step\Then as Then,
Behat\Gherkin\Node\TableNode as TableNode; Behat\Gherkin\Node\TableNode as TableNode;
/** /**

View File

@@ -29,9 +29,6 @@ require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
require_once(__DIR__ . '/../../../lib/behat/behat_field_manager.php'); require_once(__DIR__ . '/../../../lib/behat/behat_field_manager.php');
use Behat\Gherkin\Node\TableNode as TableNode, use Behat\Gherkin\Node\TableNode as TableNode,
Moodle\BehatExtension\Context\Step\Given as Given,
Moodle\BehatExtension\Context\Step\When as When,
Moodle\BehatExtension\Context\Step\Then as Then,
Behat\Gherkin\Node\PyStringNode as PyStringNode, Behat\Gherkin\Node\PyStringNode as PyStringNode,
Behat\Mink\Exception\ExpectationException as ExpectationException, Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
@@ -466,9 +463,8 @@ class behat_forms extends behat_base {
* @Given /^I select "(?P<singleselect_option_string>(?:[^"]|\\")*)" from the "(?P<singleselect_name_string>(?:[^"]|\\")*)" singleselect$/ * @Given /^I select "(?P<singleselect_option_string>(?:[^"]|\\")*)" from the "(?P<singleselect_name_string>(?:[^"]|\\")*)" singleselect$/
*/ */
public function i_select_from_the_singleselect($option, $singleselect) { public function i_select_from_the_singleselect($option, $singleselect) {
$actions = array(
new Given('I set the field "' . $this->escape($singleselect) . '" to "' . $this->escape($option) . '"'), $this->execute('behat_forms::i_set_the_field_to', array($this->escape($singleselect), $this->escape($option)));
);
if (!$this->running_javascript()) { if (!$this->running_javascript()) {
// Press button in the specified select container. // Press button in the specified select container.
@@ -480,11 +476,10 @@ class behat_forms extends behat_base {
"or .//select[(./@name='" . $singleselect . "' or ./@id='". $singleselect . "')]" . "or .//select[(./@name='" . $singleselect . "' or ./@id='". $singleselect . "')]" .
")]"; ")]";
$actions[] = new Given('I click on "' . get_string('go') . '" "button" in the "' . $containerxpath . $this->execute('behat_general::i_click_on_in_the',
'" "xpath_element"'); array(get_string('go'), "button", $containerxpath, "xpath_element")
);
} }
return $actions;
} }
} }

View File

@@ -32,8 +32,7 @@ use Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\DriverException as DriverException, Behat\Mink\Exception\DriverException as DriverException,
WebDriver\Exception\NoSuchElement as NoSuchElement, WebDriver\Exception\NoSuchElement as NoSuchElement,
WebDriver\Exception\StaleElementReference as StaleElementReference, WebDriver\Exception\StaleElementReference as StaleElementReference,
Behat\Gherkin\Node\TableNode as TableNode, Behat\Gherkin\Node\TableNode as TableNode;
Moodle\BehatExtension\Context\Step\Given as Given;
/** /**
* Cross component steps definitions. * Cross component steps definitions.
@@ -258,8 +257,9 @@ class behat_general extends behat_base {
*/ */
public function wait_until_the_page_is_ready() { public function wait_until_the_page_is_ready() {
// No need to wait if not running JS.
if (!$this->running_javascript()) { if (!$this->running_javascript()) {
throw new DriverException('Waits are disabled in scenarios without Javascript support'); return;
} }
$this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS); $this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);

View File

@@ -496,88 +496,12 @@ class behat_hooks extends behat_base {
* @see Moodle\BehatExtension\Tester\MoodleStepTester * @see Moodle\BehatExtension\Tester\MoodleStepTester
*/ */
public function i_look_for_exceptions() { public function i_look_for_exceptions() {
// If the step already failed in a hook throw the exception. // If the step already failed in a hook throw the exception.
if (!is_null(self::$currentstepexception)) { if (!is_null(self::$currentstepexception)) {
throw self::$currentstepexception; throw self::$currentstepexception;
} }
// Wrap in try in case we were interacting with a closed window. $this->look_for_exceptions();
try {
// Exceptions.
$exceptionsxpath = "//div[@data-rel='fatalerror']";
// Debugging messages.
$debuggingxpath = "//div[@data-rel='debugging']";
// PHP debug messages.
$phperrorxpath = "//div[@data-rel='phpdebugmessage']";
// Any other backtrace.
$othersxpath = "(//*[contains(., ': call to ')])[1]";
$xpaths = array($exceptionsxpath, $debuggingxpath, $phperrorxpath, $othersxpath);
$joinedxpath = implode(' | ', $xpaths);
// Joined xpath expression. Most of the time there will be no exceptions, so this pre-check
// is faster than to send the 4 xpath queries for each step.
if (!$this->getSession()->getDriver()->find($joinedxpath)) {
return;
}
// Exceptions.
if ($errormsg = $this->getSession()->getPage()->find('xpath', $exceptionsxpath)) {
// Getting the debugging info and the backtrace.
$errorinfoboxes = $this->getSession()->getPage()->findAll('css', 'div.alert-error');
// If errorinfoboxes is empty, try find notifytiny (original) class.
if (empty($errorinfoboxes)) {
$errorinfoboxes = $this->getSession()->getPage()->findAll('css', 'div.notifytiny');
}
$errorinfo = $this->get_debug_text($errorinfoboxes[0]->getHtml()) . "\n" .
$this->get_debug_text($errorinfoboxes[1]->getHtml());
$msg = "Moodle exception: " . $errormsg->getText() . "\n" . $errorinfo;
throw new \Exception(html_entity_decode($msg));
}
// Debugging messages.
if ($debuggingmessages = $this->getSession()->getPage()->findAll('xpath', $debuggingxpath)) {
$msgs = array();
foreach ($debuggingmessages as $debuggingmessage) {
$msgs[] = $this->get_debug_text($debuggingmessage->getHtml());
}
$msg = "debugging() message/s found:\n" . implode("\n", $msgs);
throw new \Exception(html_entity_decode($msg));
}
// PHP debug messages.
if ($phpmessages = $this->getSession()->getPage()->findAll('xpath', $phperrorxpath)) {
$msgs = array();
foreach ($phpmessages as $phpmessage) {
$msgs[] = $this->get_debug_text($phpmessage->getHtml());
}
$msg = "PHP debug message/s found:\n" . implode("\n", $msgs);
throw new \Exception(html_entity_decode($msg));
}
// Any other backtrace.
// First looking through xpath as it is faster than get and parse the whole page contents,
// we get the contents and look for matches once we found something to suspect that there is a backtrace.
if ($this->getSession()->getDriver()->find($othersxpath)) {
$backtracespattern = '/(line [0-9]* of [^:]*: call to [\->&;:a-zA-Z_\x7f-\xff][\->&;:a-zA-Z0-9_\x7f-\xff]*)/';
if (preg_match_all($backtracespattern, $this->getSession()->getPage()->getContent(), $backtraces)) {
$msgs = array();
foreach ($backtraces[0] as $backtrace) {
$msgs[] = $backtrace . '()';
}
$msg = "Other backtraces found:\n" . implode("\n", $msgs);
throw new \Exception(htmlentities($msg));
}
}
} catch (NoSuchWindow $e) {
// If we were interacting with a popup window it will not exists after closing it.
}
} }
/** /**

View File

@@ -27,8 +27,6 @@
require_once(__DIR__ . '/../../behat/behat_base.php'); require_once(__DIR__ . '/../../behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given;
use Moodle\BehatExtension\Context\Step\When;
use Behat\Mink\Exception\ExpectationException as ExpectationException; use Behat\Mink\Exception\ExpectationException as ExpectationException;
use Behat\Mink\Exception\DriverException as DriverException; use Behat\Mink\Exception\DriverException as DriverException;
@@ -147,23 +145,22 @@ class behat_navigation extends behat_base {
* @Given /^I follow "(?P<nodetext_string>(?:[^"]|\\")*)" in the user menu$/ * @Given /^I follow "(?P<nodetext_string>(?:[^"]|\\")*)" in the user menu$/
* *
* @param string $nodetext * @param string $nodetext
* @return bool|void
*/ */
public function i_follow_in_the_user_menu($nodetext) { public function i_follow_in_the_user_menu($nodetext) {
$steps = array();
if ($this->running_javascript()) { if ($this->running_javascript()) {
// The user menu must be expanded when JS is enabled. // The user menu must be expanded when JS is enabled.
$xpath = "//div[@class='usermenu']//a[contains(concat(' ', @class, ' '), ' toggle-display ')]"; $xpath = "//div[@class='usermenu']//a[contains(concat(' ', @class, ' '), ' toggle-display ')]";
$steps[] = new When('I click on "'.$xpath.'" "xpath_element"'); $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
} }
// Now select the link. // Now select the link.
// The CSS path is always present, with or without JS. // The CSS path is always present, with or without JS.
$csspath = ".usermenu [data-rel='menu-content']"; $csspath = ".usermenu [data-rel='menu-content']";
$steps[] = new When('I click on "'.$nodetext.'" "link" in the "'.$csspath.'" "css_element"');
return $steps; $this->execute('behat_general::i_click_on_in_the',
array($nodetext, "link", $csspath, "css_element")
);
} }
/** /**
@@ -182,7 +179,10 @@ class behat_navigation extends behat_base {
if (!$this->running_javascript()) { if (!$this->running_javascript()) {
if ($nodetext === get_string('administrationsite')) { if ($nodetext === get_string('administrationsite')) {
// Administration menu is not loaded by default any more. Click the link to expand. // Administration menu is not loaded by default any more. Click the link to expand.
return new Given('I click on "'.$nodetext.'" "link" in the "'.get_string('administration').'" "block"'); $this->execute('behat_general::i_click_on_in_the',
array($nodetext, "link", get_string('administration'), "block")
);
return true;
} }
return true; return true;
} }
@@ -413,6 +413,6 @@ class behat_navigation extends behat_base {
return false; return false;
} }
return new Given('I click on ".btn-navbar" "css_element"'); $this->execute('behat_general::i_click_on', array(".btn-navbar", "css_element"));
} }
} }

View File

@@ -28,7 +28,6 @@
require_once(__DIR__ . '/../../behat/behat_base.php'); require_once(__DIR__ . '/../../behat/behat_base.php');
use Behat\Mink\Exception\ExpectationException as ExpectationException, use Behat\Mink\Exception\ExpectationException as ExpectationException,
Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode; Behat\Gherkin\Node\TableNode as TableNode;
/** /**
@@ -46,20 +45,25 @@ class behat_permissions extends behat_base {
* @Given /^I set the following system permissions of "(?P<rolefullname_string>(?:[^"]|\\")*)" role:$/ * @Given /^I set the following system permissions of "(?P<rolefullname_string>(?:[^"]|\\")*)" role:$/
* @param string $rolename * @param string $rolename
* @param TableNode $table * @param TableNode $table
* @return void Executes other steps
*/ */
public function i_set_the_following_system_permissions_of_role($rolename, $table) { public function i_set_the_following_system_permissions_of_role($rolename, $table) {
$parentnodes = get_string('administrationsite') . ' > ' . $parentnodes = get_string('administrationsite') . ' > ' .
get_string('users', 'admin') . ' > ' . get_string('users', 'admin') . ' > ' .
get_string('permissions', 'role'); get_string('permissions', 'role');
return array(
new Given('I am on homepage'), // Go to home page.
new Given('I navigate to "' . get_string('defineroles', 'role') . '" node in "' . $parentnodes . '"'), $this->execute("behat_general::i_am_on_homepage");
new Given('I follow "Edit ' . $this->escape($rolename) . ' role"'),
new Given('I fill the capabilities form with the following permissions:', $table), // Navigate to course management page via navigation block.
new Given('I press "' . get_string('savechanges') . '"') $this->execute("behat_navigation::i_navigate_to_node_in",
array(get_string('defineroles', 'role'), $parentnodes)
); );
$this->execute("behat_general::click_link", "Edit " . $this->escape($rolename) . " role");
$this->execute("behat_permissions::i_fill_the_capabilities_form_with_the_following_permissions", $table);
$this->execute('behat_forms::press_button', get_string('savechanges'));
} }
/** /**
@@ -67,22 +71,23 @@ class behat_permissions extends behat_base {
* @Given /^I override the system permissions of "(?P<rolefullname_string>(?:[^"]|\\")*)" role with:$/ * @Given /^I override the system permissions of "(?P<rolefullname_string>(?:[^"]|\\")*)" role with:$/
* @param string $rolename * @param string $rolename
* @param TableNode $table * @param TableNode $table
* @return void Executes other steps
*/ */
public function i_override_the_system_permissions_of_role_with($rolename, $table) { public function i_override_the_system_permissions_of_role_with($rolename, $table) {
// We don't know the number of overrides so we have to get it to match the option contents. // We don't know the number of overrides so we have to get it to match the option contents.
$roleoption = $this->find('xpath', '//select[@name="roleid"]/option[contains(.,"' . $this->escape($rolename) . '")]'); $roleoption = $this->find('xpath', '//select[@name="roleid"]/option[contains(.,"' . $this->escape($rolename) . '")]');
$result = array( $this->execute('behat_forms::i_set_the_field_to',
new Given('I set the field "' . get_string('advancedoverride', 'role') . array(get_string('advancedoverride', 'role'), $this->escape($roleoption->getText()))
'" to "' . $this->escape($roleoption->getText()) . '"')); );
if (!$this->running_javascript()) { if (!$this->running_javascript()) {
$result[] = new Given('I press "' . get_string('go') . '"'); $this->execute("behat_forms::press_button", get_string('go'));
} }
$result[] = new Given('I fill the capabilities form with the following permissions:', $table);
$result[] = new Given('I press "' . get_string('savechanges') . '"'); $this->execute("behat_permissions::i_fill_the_capabilities_form_with_the_following_permissions", $table);
return $result;
$this->execute('behat_forms::press_button', get_string('savechanges'));
} }
/** /**
@@ -192,13 +197,21 @@ class behat_permissions extends behat_base {
$parentnodes = get_string('administrationsite') . ' > ' . $parentnodes = get_string('administrationsite') . ' > ' .
get_string('users', 'admin') . ' > ' . get_string('users', 'admin') . ' > ' .
get_string('permissions', 'role'); get_string('permissions', 'role');
return array(
new Given('I am on homepage'), // Go to home page.
new Given('I navigate to "' . get_string('defineroles', 'role') . '" node in "' . $parentnodes . '"'), $this->execute("behat_general::i_am_on_homepage");
new Given('I follow "Allow role assignments"'),
new Given('I fill in the allowed role assignments form for the "' . $rolename . '" role with:', $table), // Navigate to course management page via navigation block.
new Given('I press "' . get_string('savechanges') . '"') $this->execute("behat_navigation::i_navigate_to_node_in",
array(get_string('defineroles', 'role'), $parentnodes)
); );
$this->execute("behat_general::click_link", "Allow role assignments");
$this->execute("behat_permissions::i_fill_in_the_allowed_role_assignments_form_for_a_role_with",
array($rolename, $table)
);
$this->execute('behat_forms::press_button', get_string('savechanges'));
} }
/** /**

View File

@@ -27,8 +27,7 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given, use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
/** /**
* Messaging system steps definitions. * Messaging system steps definitions.
@@ -49,21 +48,27 @@ class behat_message extends behat_base {
*/ */
public function i_send_message_to_user($messagecontent, $userfullname) { public function i_send_message_to_user($messagecontent, $userfullname) {
$steps = array(); // Visit home page and follow messages.
$steps[] = new Given('I am on homepage'); $this->execute("behat_general::i_am_on_homepage");
if ($this->running_javascript()) { if ($this->running_javascript()) {
$steps[] = new Given('I follow "' . get_string('messages', 'message') . '" in the user menu'); $this->execute("behat_navigation::i_follow_in_the_user_menu", get_string('messages', 'message'));
} else { } else {
$steps[] = new Given('I follow "' . get_string('messages', 'message') . '"'); $this->execute("behat_general::click_link", get_string('messages', 'message'));
} }
$steps[] = new Given('I set the field "' . get_string('searchcombined', 'message') .
'" to "' . $this->escape($userfullname) . '"');
$steps[] = new Given('I press "' . get_string('searchcombined', 'message') . '"');
$steps[] = new Given('I follow "' . $this->escape(get_string('sendmessageto', 'message', $userfullname)) . '"');
$steps[] = new Given('I set the field "id_message" to "' . $this->escape($messagecontent) . '"');
$steps[] = new Given('I press "' . get_string('sendmessage', 'message') . '"');
return $steps; $this->execute('behat_forms::i_set_the_field_to',
array(get_string('searchcombined', 'message'), $this->escape($userfullname))
);
$this->execute("behat_forms::press_button", get_string('searchcombined', 'message'));
$this->execute("behat_general::click_link", $this->escape(get_string('sendmessageto', 'message', $userfullname)));
$this->execute('behat_forms::i_set_the_field_to',
array("id_message", $this->escape($messagecontent))
);
$this->execute("behat_forms::press_button", get_string('sendmessage', 'message'));
} }
} }

View File

@@ -27,8 +27,6 @@
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given;
/** /**
* Choice activity definitions. * Choice activity definitions.
* *
@@ -49,12 +47,11 @@ class behat_mod_choice extends behat_base {
*/ */
public function I_choose_option_from_activity($option, $choiceactivity) { public function I_choose_option_from_activity($option, $choiceactivity) {
// Escaping again the strings as backslashes have been removed by the automatic transformation. $this->execute("behat_general::click_link", $this->escape($choiceactivity));
return array(
new Given('I follow "' . $this->escape($choiceactivity) . '"'), $this->execute('behat_forms::i_set_the_field_to', array( $this->escape($option), 1));
new Given('I set the field "' . $this->escape($option) . '" to "1"'),
new Given('I press "' . get_string('savemychoice', 'choice') . '"') $this->execute("behat_forms::press_button", get_string('savemychoice', 'choice'));
);
} }
/** /**

View File

@@ -27,9 +27,7 @@
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given, use Behat\Gherkin\Node\TableNode as TableNode;
Moodle\BehatExtension\Context\Step\When as When,
Behat\Gherkin\Node\TableNode as TableNode;
/** /**
* Database-related steps definitions. * Database-related steps definitions.
* *
@@ -48,27 +46,22 @@ class behat_mod_data extends behat_base {
* @param string $fieldtype * @param string $fieldtype
* @param string $activityname * @param string $activityname
* @param TableNode $fielddata * @param TableNode $fielddata
* @return Given[]
*/ */
public function i_add_a_field_to_database_and_i_fill_the_form_with($fieldtype, $activityname, TableNode $fielddata) { public function i_add_a_field_to_database_and_i_fill_the_form_with($fieldtype, $activityname, TableNode $fielddata) {
$steps = array( $this->execute("behat_general::click_link", $this->escape($activityname));
new Given('I follow "' . $this->escape($activityname) . '"'), $this->execute("behat_general::click_link", get_string('fields', 'mod_data'));
new Given('I follow "' . get_string('fields', 'mod_data') . '"'),
new Given('I set the field "newtype" to "' . $this->escape($fieldtype) . '"') $this->execute('behat_forms::i_set_the_field_to', array('newtype', $this->escape($fieldtype)));
);
if (!$this->running_javascript()) { if (!$this->running_javascript()) {
$steps[] = new Given('I click on "' . get_string('go') . '" "button" in the ".fieldadd" "css_element"'); $this->execute('behat_general::i_click_on_in_the',
array(get_string('go'), "button", ".fieldadd", "css_element")
);
} }
array_push( $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $fielddata);
$steps, $this->execute('behat_forms::press_button', get_string('add'));
new Given('I set the following fields to these values:', $fielddata),
new Given('I press "' . get_string('add') . '"')
);
return $steps;
} }
/** /**
@@ -78,14 +71,12 @@ class behat_mod_data extends behat_base {
* *
* @param string $activityname * @param string $activityname
* @param TableNode $entrydata * @param TableNode $entrydata
* @return When[]
*/ */
public function i_add_an_entry_to_database_with($activityname, TableNode $entrydata) { public function i_add_an_entry_to_database_with($activityname, TableNode $entrydata) {
return array( $this->execute("behat_general::click_link", $this->escape($activityname));
new When('I follow "' . $this->escape($activityname) . '"'), $this->execute("behat_general::click_link", get_string('add', 'mod_data'));
new When('I follow "' . get_string('add', 'mod_data') . '"'),
new When('I set the following fields to these values:', $entrydata), $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $entrydata);
);
} }
} }

View File

@@ -27,8 +27,7 @@
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
use Behat\Behat\Context\Step\Given as Given, use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ExpectationException as ExpectationException; Behat\Mink\Exception\ExpectationException as ExpectationException;
/** /**
@@ -49,10 +48,11 @@ class behat_mod_feedback extends behat_base {
* @param TableNode $questiondata with data for filling the add question form * @param TableNode $questiondata with data for filling the add question form
*/ */
public function i_add_question_to_the_feedback_with($questiontype, TableNode $questiondata) { public function i_add_question_to_the_feedback_with($questiontype, TableNode $questiondata) {
$rv = array();
$questiontype = $this->escape($questiontype); $questiontype = $this->escape($questiontype);
$additem = $this->escape(get_string('add_item', 'feedback')); $additem = $this->escape(get_string('add_item', 'feedback'));
$rv[] = new Given("I select \"{$questiontype}\" from the \"{$additem}\" singleselect");
$this->execute('behat_forms::i_select_from_the_singleselect', array($questiontype, $additem));
$rows = $questiondata->getRows(); $rows = $questiondata->getRows();
$modifiedrows = array(); $modifiedrows = array();
@@ -64,12 +64,10 @@ class behat_mod_feedback extends behat_base {
} }
$newdata = new TableNode($modifiedrows); $newdata = new TableNode($modifiedrows);
$rv[] = new Given('I set the following fields to these values:', $newdata); $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $newdata);
$saveitem = $this->escape(get_string('save_item', 'feedback')); $saveitem = $this->escape(get_string('save_item', 'feedback'));
$rv[] = new Given("I press \"{$saveitem}\""); $this->execute("behat_forms::press_button", $saveitem);
return $rv;
} }
/** /**
@@ -84,14 +82,20 @@ class behat_mod_feedback extends behat_base {
$coursename = $this->escape($coursename); $coursename = $this->escape($coursename);
$feedbackname = $this->escape($feedbackname); $feedbackname = $this->escape($feedbackname);
$completeform = $this->escape(get_string('complete_the_form', 'feedback')); $completeform = $this->escape(get_string('complete_the_form', 'feedback'));
return [
new Given("I log in as \"$username\""), // Log in as user.
new Given("I follow \"$coursename\""), $this->execute('behat_auth::i_log_in_as', $username);
new Given("I follow \"$feedbackname\""),
new Given("I follow \"$completeform\""), // Navigate to feedback complete form.
new Given("I set the following fields to these values:", $answers), $this->execute('behat_general::click_link', $coursename);
new Given("I press \"Submit your answers\""), $this->execute('behat_general::click_link', $feedbackname);
new Given("I log out") $this->execute('behat_general::click_link', $completeform);
];
// Fill form and submit.
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $answers);
$this->execute("behat_forms::press_button", 'Submit your answers');
// Log out.
$this->execute('behat_auth::i_log_out');
} }
} }

View File

@@ -27,8 +27,7 @@
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given, use Behat\Gherkin\Node\TableNode as TableNode;
Behat\Gherkin\Node\TableNode as TableNode;
/** /**
* Forum-related steps definitions. * Forum-related steps definitions.
* *
@@ -47,7 +46,7 @@ class behat_mod_forum extends behat_base {
* @param TableNode $table * @param TableNode $table
*/ */
public function i_add_a_new_topic_to_forum_with($forumname, TableNode $table) { public function i_add_a_new_topic_to_forum_with($forumname, TableNode $table) {
return $this->add_new_discussion($forumname, $table, get_string('addanewtopic', 'forum')); $this->add_new_discussion($forumname, $table, get_string('addanewtopic', 'forum'));
} }
/** /**
@@ -58,7 +57,7 @@ class behat_mod_forum extends behat_base {
* @param TableNode $table * @param TableNode $table
*/ */
public function i_add_a_forum_discussion_to_forum_with($forumname, TableNode $table) { public function i_add_a_forum_discussion_to_forum_with($forumname, TableNode $table) {
return $this->add_new_discussion($forumname, $table, get_string('addanewdiscussion', 'forum')); $this->add_new_discussion($forumname, $table, get_string('addanewdiscussion', 'forum'));
} }
/** /**
@@ -71,15 +70,16 @@ class behat_mod_forum extends behat_base {
*/ */
public function i_reply_post_from_forum_with($postsubject, $forumname, TableNode $table) { public function i_reply_post_from_forum_with($postsubject, $forumname, TableNode $table) {
return array( // Navigate to forum.
new Given('I follow "' . $this->escape($forumname) . '"'), $this->execute('behat_general::click_link', $this->escape($forumname));
new Given('I follow "' . $this->escape($postsubject) . '"'), $this->execute('behat_general::click_link', $this->escape($postsubject));
new Given('I follow "' . get_string('reply', 'forum') . '"'), $this->execute('behat_general::click_link', get_string('reply', 'forum'));
new Given('I set the following fields to these values:', $table),
new Given('I press "' . get_string('posttoforum', 'forum') . '"'),
new Given('I wait to be redirected')
);
// Fill form and post.
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', $table);
$this->execute('behat_forms::press_button', get_string('posttoforum', 'forum'));
$this->execute('behat_general::i_wait_to_be_redirected');
} }
/** /**
@@ -91,19 +91,17 @@ class behat_mod_forum extends behat_base {
* @param string $forumname * @param string $forumname
* @param TableNode $table * @param TableNode $table
* @param string $buttonstr * @param string $buttonstr
* @return Given[]
*/ */
protected function add_new_discussion($forumname, TableNode $table, $buttonstr) { protected function add_new_discussion($forumname, TableNode $table, $buttonstr) {
// Escaping $forumname as it has been stripped automatically by the transformer. // Navigate to forum.
return array( $this->execute('behat_general::click_link', $this->escape($forumname));
new Given('I follow "' . $this->escape($forumname) . '"'), $this->execute('behat_forms::press_button', $buttonstr);
new Given('I press "' . $buttonstr . '"'),
new Given('I set the following fields to these values:', $table),
new Given('I press "' . get_string('posttoforum', 'forum') . '"'),
new Given('I wait to be redirected')
);
// Fill form and post.
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', $table);
$this->execute('behat_forms::press_button', get_string('posttoforum', 'forum'));
$this->execute('behat_general::i_wait_to_be_redirected');
} }
} }

View File

@@ -27,8 +27,7 @@
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given, use Behat\Gherkin\Node\TableNode as TableNode;
Behat\Gherkin\Node\TableNode as TableNode;
/** /**
* Glossary-related steps definitions. * Glossary-related steps definitions.
@@ -47,11 +46,11 @@ class behat_mod_glossary extends behat_base {
* @param TableNode $data * @param TableNode $data
*/ */
public function i_add_a_glossary_entry_with_the_following_data(TableNode $data) { public function i_add_a_glossary_entry_with_the_following_data(TableNode $data) {
return array( $this->execute("behat_forms::press_button", get_string('addentry', 'mod_glossary'));
new Given('I press "' . get_string('addentry', 'mod_glossary') . '"'),
new Given('I set the following fields to these values:', $data), $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
new Given('I press "' . get_string('savechanges') . '"')
); $this->execute("behat_forms::press_button", get_string('savechanges'));
} }
/** /**
@@ -62,13 +61,15 @@ class behat_mod_glossary extends behat_base {
*/ */
public function i_add_a_glossary_entries_category_named($categoryname) { public function i_add_a_glossary_entries_category_named($categoryname) {
return array( $this->execute("behat_general::click_link", get_string('categoryview', 'mod_glossary'));
new Given('I follow "' . get_string('categoryview', 'mod_glossary') . '"'),
new Given('I press "' . get_string('editcategories', 'mod_glossary') . '"'), $this->execute("behat_forms::press_button", get_string('editcategories', 'mod_glossary'));
new Given('I press "' . get_string('add').' '.get_string('category', 'glossary') . '"'),
new Given('I set the field "name" to "' . $this->escape($categoryname) . '"'), $this->execute("behat_forms::press_button", get_string('add').' '.get_string('category', 'glossary'));
new Given('I press "' . get_string('savechanges') . '"'),
new Given('I press "' . get_string('back', 'mod_glossary') . '"') $this->execute('behat_forms::i_set_the_field_to', array('name', $this->escape($categoryname)));
);
$this->execute("behat_forms::press_button", get_string('savechanges'));
$this->execute("behat_forms::press_button", get_string('back', 'mod_glossary'));
} }
} }

View File

@@ -28,8 +28,7 @@
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
require_once(__DIR__ . '/../../../../question/tests/behat/behat_question_base.php'); require_once(__DIR__ . '/../../../../question/tests/behat/behat_question_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given, use Behat\Gherkin\Node\TableNode as TableNode;
Behat\Gherkin\Node\TableNode as TableNode;
use Behat\Mink\Exception\ExpectationException as ExpectationException; use Behat\Mink\Exception\ExpectationException as ExpectationException;
@@ -249,12 +248,15 @@ class behat_mod_quiz extends behat_question_base {
$addaquestion = $this->escape(get_string('addaquestion', 'quiz')); $addaquestion = $this->escape(get_string('addaquestion', 'quiz'));
$menuxpath = "//div[contains(@class, ' page-add-actions ')][last()]//a[contains(@class, ' textmenu')]"; $menuxpath = "//div[contains(@class, ' page-add-actions ')][last()]//a[contains(@class, ' textmenu')]";
$itemxpath = "//div[contains(@class, ' page-add-actions ')][last()]//a[contains(@class, ' addquestion ')]"; $itemxpath = "//div[contains(@class, ' page-add-actions ')][last()]//a[contains(@class, ' addquestion ')]";
return array_merge(array(
new Given("I follow \"$quizname\""), $this->execute('behat_general::click_link', $quizname);
new Given("I navigate to \"$editquiz\" node in \"$quizadmin\""),
new Given("I click on \"$menuxpath\" \"xpath_element\""), $this->execute("behat_navigation::i_navigate_to_node_in", array($editquiz, $quizadmin));
new Given("I click on \"$itemxpath\" \"xpath_element\""),
), $this->finish_adding_question($questiontype, $questiondata)); $this->execute("behat_general::i_click_on", array($menuxpath, "xpath_element"));
$this->execute("behat_general::i_click_on", array($itemxpath, "xpath_element"));
$this->finish_adding_question($questiontype, $questiondata);
} }
/** /**
@@ -265,12 +267,13 @@ class behat_mod_quiz extends behat_question_base {
* @param string $newmark the mark to set * @param string $newmark the mark to set
*/ */
public function i_set_the_max_mark_for_quiz_question($questionname, $newmark) { public function i_set_the_max_mark_for_quiz_question($questionname, $newmark) {
return array( $this->execute('behat_general::click_link', $this->escape(get_string('editmaxmark', 'quiz')));
new Given('I follow "' . $this->escape(get_string('editmaxmark', 'quiz')) . '"'),
new Given('I wait until "li input[name=maxmark]" "css_element" exists'), $this->execute('behat_general::wait_until_exists', array("li input[name=maxmark]", "css_element"));
new Given('I should see "' . $this->escape(get_string('edittitleinstructions')) . '"'),
new Given('I set the field "maxmark" to "' . $this->escape($newmark) . chr(10) . '"'), $this->execute('behat_general::assert_page_contains_text', $this->escape(get_string('edittitleinstructions')));
);
$this->execute('behat_forms::i_set_the_field_to', array('maxmark', $this->escape($newmark) . chr(10)));
} }
/** /**
@@ -291,20 +294,21 @@ class behat_mod_quiz extends behat_question_base {
} else { } else {
throw new ExpectationException("The I open the add to quiz menu step must specify either 'Page N' or 'last'."); throw new ExpectationException("The I open the add to quiz menu step must specify either 'Page N' or 'last'.");
} }
$menu = $this->find('xpath', $xpath)->click(); $this->find('xpath', $xpath)->click();
} }
/** /**
* Click on a given link in the moodle-actionmenu that is currently open. * Click on a given link in the moodle-actionmenu that is currently open.
* @Given /^I follow "(?P<link_string>(?:[^"]|\\")*)" in the open menu$/ * @Given /^I follow "(?P<link_string>(?:[^"]|\\")*)" in the open menu$/
* @param string $linkstring the text (or id, etc.) of the link to click. * @param string $linkstring the text (or id, etc.) of the link to click.
* @return array of steps.
*/ */
public function i_follow_in_the_open_menu($linkstring) { public function i_follow_in_the_open_menu($linkstring) {
$openmenuxpath = "//div[contains(@class, 'moodle-actionmenu') and contains(@class, 'show')]"; $openmenuxpath = "//div[contains(@class, 'moodle-actionmenu') and contains(@class, 'show')]";
return array(
new Given('I click on "' . $linkstring . '" "link" in the "' . $openmenuxpath . '" "xpath_element"'), $this->execute('behat_general::i_click_on_in_the',
array($linkstring, "link", $openmenuxpath, "xpath_element")
); );
} }
/** /**
@@ -312,15 +316,13 @@ class behat_mod_quiz extends behat_question_base {
* @Given /^I should see "(?P<question_name>(?:[^"]|\\")*)" on quiz page "(?P<page_number>\d+)"$/ * @Given /^I should see "(?P<question_name>(?:[^"]|\\")*)" on quiz page "(?P<page_number>\d+)"$/
* @param string $questionname the name of the question we are looking for. * @param string $questionname the name of the question we are looking for.
* @param number $pagenumber the page it should be found on. * @param number $pagenumber the page it should be found on.
* @return array of steps.
*/ */
public function i_should_see_on_quiz_page($questionname, $pagenumber) { public function i_should_see_on_quiz_page($questionname, $pagenumber) {
$xpath = "//li[contains(., '" . $this->escape($questionname) . $xpath = "//li[contains(., '" . $this->escape($questionname) .
"')][./preceding-sibling::li[contains(@class, 'pagenumber')][1][contains(., 'Page " . "')][./preceding-sibling::li[contains(@class, 'pagenumber')][1][contains(., 'Page " .
$pagenumber . "')]]"; $pagenumber . "')]]";
return array(
new Given('"' . $xpath . '" "xpath_element" should exist'), $this->execute('behat_general::should_exist', array($xpath, 'xpath_element'));
);
} }
/** /**
@@ -328,15 +330,13 @@ class behat_mod_quiz extends behat_question_base {
* @Given /^I should not see "(?P<question_name>(?:[^"]|\\")*)" on quiz page "(?P<page_number>\d+)"$/ * @Given /^I should not see "(?P<question_name>(?:[^"]|\\")*)" on quiz page "(?P<page_number>\d+)"$/
* @param string $questionname the name of the question we are looking for. * @param string $questionname the name of the question we are looking for.
* @param number $pagenumber the page it should be found on. * @param number $pagenumber the page it should be found on.
* @return array of steps.
*/ */
public function i_should_not_see_on_quiz_page($questionname, $pagenumber) { public function i_should_not_see_on_quiz_page($questionname, $pagenumber) {
$xpath = "//li[contains(., '" . $this->escape($questionname) . $xpath = "//li[contains(., '" . $this->escape($questionname) .
"')][./preceding-sibling::li[contains(@class, 'pagenumber')][1][contains(., 'Page " . "')][./preceding-sibling::li[contains(@class, 'pagenumber')][1][contains(., 'Page " .
$pagenumber . "')]]"; $pagenumber . "')]]";
return array(
new Given('"' . $xpath . '" "xpath_element" should not exist'), $this->execute('behat_general::should_not_exist', array($xpath, 'xpath_element'));
);
} }
/** /**
@@ -345,15 +345,13 @@ class behat_mod_quiz extends behat_question_base {
* @Given /^I should see "(?P<first_q_name>(?:[^"]|\\")*)" before "(?P<second_q_name>(?:[^"]|\\")*)" on the edit quiz page$/ * @Given /^I should see "(?P<first_q_name>(?:[^"]|\\")*)" before "(?P<second_q_name>(?:[^"]|\\")*)" on the edit quiz page$/
* @param string $firstquestionname the name of the question that should come first in order. * @param string $firstquestionname the name of the question that should come first in order.
* @param string $secondquestionname the name of the question that should come immediately after it in order. * @param string $secondquestionname the name of the question that should come immediately after it in order.
* @return array of steps.
*/ */
public function i_should_see_before_on_the_edit_quiz_page($firstquestionname, $secondquestionname) { public function i_should_see_before_on_the_edit_quiz_page($firstquestionname, $secondquestionname) {
$xpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($firstquestionname) . $xpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($firstquestionname) .
"')]/following-sibling::li[contains(@class, ' slot ')][1]" . "')]/following-sibling::li[contains(@class, ' slot ')][1]" .
"[contains(., '" . $this->escape($secondquestionname) . "')]"; "[contains(., '" . $this->escape($secondquestionname) . "')]";
return array(
new Given('"' . $xpath . '" "xpath_element" should exist'), $this->execute('behat_general::should_exist', array($xpath, 'xpath_element'));
);
} }
/** /**
@@ -361,14 +359,12 @@ class behat_mod_quiz extends behat_question_base {
* @Given /^"(?P<question_name>(?:[^"]|\\")*)" should have number "(?P<number>(?:[^"]|\\")*)" on the edit quiz page$/ * @Given /^"(?P<question_name>(?:[^"]|\\")*)" should have number "(?P<number>(?:[^"]|\\")*)" on the edit quiz page$/
* @param string $questionname the name of the question we are looking for. * @param string $questionname the name of the question we are looking for.
* @param number $number the number (or 'i') that should be displayed beside that question. * @param number $number the number (or 'i') that should be displayed beside that question.
* @return array of steps.
*/ */
public function should_have_number_on_the_edit_quiz_page($questionname, $number) { public function should_have_number_on_the_edit_quiz_page($questionname, $number) {
$xpath = "//li[contains(@class, 'slot') and contains(., '" . $this->escape($questionname) . $xpath = "//li[contains(@class, 'slot') and contains(., '" . $this->escape($questionname) .
"')]//span[contains(@class, 'slotnumber') and normalize-space(text()) = '" . $this->escape($number) . "']"; "')]//span[contains(@class, 'slotnumber') and normalize-space(text()) = '" . $this->escape($number) . "']";
return array(
new Given('"' . $xpath . '" "xpath_element" should exist'), $this->execute('behat_general::should_exist', array($xpath, 'xpath_element'));
);
} }
/** /**
@@ -387,13 +383,11 @@ class behat_mod_quiz extends behat_question_base {
* @When /^I click on the "(Add|Remove)" page break icon after question "(?P<question_name>(?:[^"]|\\")*)"$/ * @When /^I click on the "(Add|Remove)" page break icon after question "(?P<question_name>(?:[^"]|\\")*)"$/
* @param string $addorremoves 'Add' or 'Remove'. * @param string $addorremoves 'Add' or 'Remove'.
* @param string $questionname the name of the question before the icon to click. * @param string $questionname the name of the question before the icon to click.
* @return array of steps.
*/ */
public function i_click_on_the_page_break_icon_after_question($addorremoves, $questionname) { public function i_click_on_the_page_break_icon_after_question($addorremoves, $questionname) {
$xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname);
return array(
new Given('I click on "' . $xpath . '" "xpath_element"'), $this->execute("behat_general::i_click_on", array($xpath, "xpath_element"));
);
} }
/** /**
@@ -405,9 +399,8 @@ class behat_mod_quiz extends behat_question_base {
*/ */
public function the_page_break_icon_after_question_should_exist($addorremoves, $questionname) { public function the_page_break_icon_after_question_should_exist($addorremoves, $questionname) {
$xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname);
return array(
new Given('"' . $xpath . '" "xpath_element" should exist'), $this->execute('behat_general::should_exist', array($xpath, 'xpath_element'));
);
} }
/** /**
@@ -419,9 +412,8 @@ class behat_mod_quiz extends behat_question_base {
*/ */
public function the_page_break_icon_after_question_should_not_exist($addorremoves, $questionname) { public function the_page_break_icon_after_question_should_not_exist($addorremoves, $questionname) {
$xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname);
return array(
new Given('"' . $xpath . '" "xpath_element" should not exist'), $this->execute('behat_general::should_not_exist', array($xpath, 'xpath_element'));
);
} }
/** /**
@@ -434,9 +426,8 @@ class behat_mod_quiz extends behat_question_base {
*/ */
public function the_page_break_link_after_question_should_contain($addorremoves, $questionname, $paramdata) { public function the_page_break_link_after_question_should_contain($addorremoves, $questionname, $paramdata) {
$xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname); $xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname);
return array(
new Given('I click on "' . $xpath . '" "xpath_element"'), $this->execute("behat_general::i_click_on", array($xpath, "xpath_element"));
);
} }
/** /**
@@ -480,7 +471,7 @@ class behat_mod_quiz extends behat_question_base {
/** /**
* Return the xpath for shuffle checkbox in section heading * Return the xpath for shuffle checkbox in section heading
* @param strung $heading * @param string $heading
* @return string * @return string
*/ */
protected function get_xpath_for_shuffle_checkbox($heading) { protected function get_xpath_for_shuffle_checkbox($heading) {
@@ -495,15 +486,13 @@ class behat_mod_quiz extends behat_question_base {
* @param string $questionname the name of the question we are looking for. * @param string $questionname the name of the question we are looking for.
* @param string $target the target place to move to. One of the links in the pop-up like * @param string $target the target place to move to. One of the links in the pop-up like
* "After Page 1" or "After Question N". * "After Page 1" or "After Question N".
* @return array of steps.
*/ */
public function i_move_question_after_item_by_clicking_the_move_icon($questionname, $target) { public function i_move_question_after_item_by_clicking_the_move_icon($questionname, $target) {
$iconxpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) . $iconxpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) .
"')]//span[contains(@class, 'editing_move')]"; "')]//span[contains(@class, 'editing_move')]";
return array(
new Given('I click on "' . $iconxpath . '" "xpath_element"'), $this->execute("behat_general::i_click_on", array($iconxpath, "xpath_element"));
new Given('I click on "' . $this->escape($target) . '" "text"'), $this->execute("behat_general::i_click_on", array($this->escape($target), "text"));
);
} }
/** /**
@@ -511,16 +500,15 @@ class behat_mod_quiz extends behat_question_base {
* @When /^I move "(?P<question_name>(?:[^"]|\\")*)" to "(?P<target>(?:[^"]|\\")*)" in the quiz by dragging$/ * @When /^I move "(?P<question_name>(?:[^"]|\\")*)" to "(?P<target>(?:[^"]|\\")*)" in the quiz by dragging$/
* @param string $questionname the name of the question we are looking for. * @param string $questionname the name of the question we are looking for.
* @param string $target the target place to move to. Ether a question name, or "Page N" * @param string $target the target place to move to. Ether a question name, or "Page N"
* @return array of steps.
*/ */
public function i_move_question_after_item_by_dragging($questionname, $target) { public function i_move_question_after_item_by_dragging($questionname, $target) {
$iconxpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) . $iconxpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) .
"')]//span[contains(@class, 'editing_move')]//img"; "')]//span[contains(@class, 'editing_move')]//img";
$destinationxpath = "//li[contains(@class, ' slot ') or contains(@class, 'pagenumber ')]" . $destinationxpath = "//li[contains(@class, ' slot ') or contains(@class, 'pagenumber ')]" .
"[contains(., '" . $this->escape($target) . "')]"; "[contains(., '" . $this->escape($target) . "')]";
return array(
new Given('I drag "' . $iconxpath . '" "xpath_element" ' . $this->execute('behat_general::i_drag_and_i_drop_it_in',
'and I drop it in "' . $destinationxpath . '" "xpath_element"'), array($iconxpath, 'xpath_element', $destinationxpath, 'xpath_element')
); );
} }
@@ -535,9 +523,11 @@ class behat_mod_quiz extends behat_question_base {
$slotxpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) . $slotxpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) .
"')]"; "')]";
$deletexpath = "//a[contains(@class, 'editing_delete')]"; $deletexpath = "//a[contains(@class, 'editing_delete')]";
return array(
new Given('I click on "' . $slotxpath . $deletexpath . '" "xpath_element"'), $this->execute("behat_general::i_click_on", array($slotxpath . $deletexpath, "xpath_element"));
new Given('I click on "Yes" "button" in the "Confirm" "dialogue"'),
$this->execute('behat_general::i_click_on_in_the',
array('Yes', "button", "Confirm", "dialogue")
); );
} }
@@ -549,11 +539,11 @@ class behat_mod_quiz extends behat_question_base {
* @param string $sectionheading the new heading to set. * @param string $sectionheading the new heading to set.
*/ */
public function i_set_the_section_heading_for($sectionname, $sectionheading) { public function i_set_the_section_heading_for($sectionname, $sectionheading) {
return array( $this->execute('behat_general::click_link', $this->escape("Edit heading '{$sectionname}'"));
new Given('I follow "' . $this->escape("Edit heading '{$sectionname}'") . '"'),
new Given('I should see "' . $this->escape(get_string('edittitleinstructions')) . '"'), $this->execute('behat_general::assert_page_contains_text', $this->escape(get_string('edittitleinstructions')));
new Given('I set the field "section" to "' . $this->escape($sectionheading) . chr(10) . '"'),
); $this->execute('behat_forms::i_set_the_field_to', array('section', $this->escape($sectionheading) . chr(10)));
} }
/** /**

View File

@@ -27,8 +27,7 @@
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given, use Behat\Gherkin\Node\TableNode as TableNode;
Behat\Gherkin\Node\TableNode as TableNode;
/** /**
* Steps definitions related to mod_workshop. * Steps definitions related to mod_workshop.
@@ -54,11 +53,12 @@ class behat_mod_workshop extends behat_base {
$xpath = "//*[@class='userplan']/descendant::div[./span[contains(.,$phaseliteral)]]/". $xpath = "//*[@class='userplan']/descendant::div[./span[contains(.,$phaseliteral)]]/".
"descendant-or-self::a[./img[@alt=$switchphase]]"; "descendant-or-self::a[./img[@alt=$switchphase]]";
$continue = $this->escape(get_string('continue')); $continue = $this->escape(get_string('continue'));
return array(
new Given("I follow \"$workshopname\""), $this->execute('behat_general::click_link', $workshopname);
new Given("I click on \"$xpath\" \"xpath_element\""),
new Given("I press \"$continue\""), $this->execute("behat_general::i_click_on", array($xpath, "xpath_element"));
);
$this->execute("behat_forms::press_button", $continue);
} }
/** /**
@@ -72,12 +72,14 @@ class behat_mod_workshop extends behat_base {
$workshopname = $this->escape($workshopname); $workshopname = $this->escape($workshopname);
$savechanges = $this->escape(get_string('savechanges')); $savechanges = $this->escape(get_string('savechanges'));
$xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' ownsubmission ')]/descendant::input[@type='submit']"; $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' ownsubmission ')]/descendant::input[@type='submit']";
return array(
new Given("I follow \"$workshopname\""), $this->execute('behat_general::click_link', $workshopname);
new Given("I click on \"$xpath\" \"xpath_element\""),
new Given("I set the following fields to these values:", $table), $this->execute("behat_general::i_click_on", array($xpath, "xpath_element"));
new Given("I press \"$savechanges\""),
); $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
$this->execute("behat_forms::press_button", $savechanges);
} }
/** /**
@@ -91,12 +93,14 @@ class behat_mod_workshop extends behat_base {
$workshopname = $this->escape($workshopname); $workshopname = $this->escape($workshopname);
$editassessmentform = $this->escape(get_string('editassessmentform', 'workshop')); $editassessmentform = $this->escape(get_string('editassessmentform', 'workshop'));
$saveandclose = $this->escape(get_string('saveandclose', 'workshop')); $saveandclose = $this->escape(get_string('saveandclose', 'workshop'));
return array(
new Given("I follow \"$workshopname\""), $this->execute('behat_general::click_link', $workshopname);
new Given("I follow \"$editassessmentform\""),
new Given("I set the following fields to these values:", $table), $this->execute('behat_general::click_link', $editassessmentform);
new Given("I press \"$saveandclose\""),
); $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
$this->execute("behat_forms::press_button", $saveandclose);
} }
/** /**
@@ -114,12 +118,16 @@ class behat_mod_workshop extends behat_base {
"and contains(.,$submissionliteral)]"; "and contains(.,$submissionliteral)]";
$assess = $this->escape(get_string('assess', 'workshop')); $assess = $this->escape(get_string('assess', 'workshop'));
$saveandclose = $this->escape(get_string('saveandclose', 'workshop')); $saveandclose = $this->escape(get_string('saveandclose', 'workshop'));
return array(
new Given("I follow \"$workshopname\""), $this->execute('behat_general::click_link', $workshopname);
new Given("I click on \"$assess\" \"button\" in the \"$xpath\" \"xpath_element\""),
new Given("I set the following fields to these values:", $table), $this->execute('behat_general::i_click_on_in_the',
new Given("I press \"$saveandclose\""), array($assess, "button", $xpath, "xpath_element")
); );
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
$this->execute("behat_forms::press_button", $saveandclose);
} }
/** /**

View File

@@ -27,8 +27,7 @@
require_once(__DIR__ . '/behat_question_base.php'); require_once(__DIR__ . '/behat_question_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given, use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ExpectationException as ExpectationException, Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
@@ -48,14 +47,17 @@ class behat_question extends behat_question_base {
* @Given /^I add a "(?P<question_type_name_string>(?:[^"]|\\")*)" question filling the form with:$/ * @Given /^I add a "(?P<question_type_name_string>(?:[^"]|\\")*)" question filling the form with:$/
* @param string $questiontypename The question type name * @param string $questiontypename The question type name
* @param TableNode $questiondata The data to fill the question type form. * @param TableNode $questiondata The data to fill the question type form.
* @return Given[] the steps.
*/ */
public function i_add_a_question_filling_the_form_with($questiontypename, TableNode $questiondata) { public function i_add_a_question_filling_the_form_with($questiontypename, TableNode $questiondata) {
return array_merge(array( // Go to question bank.
new Given('I follow "' . get_string('questionbank', 'question') . '"'), $this->execute("behat_general::click_link", get_string('questionbank', 'question'));
new Given('I press "' . get_string('createnewquestion', 'question') . '"'),
), $this->finish_adding_question($questiontypename, $questiondata)); // Click on create question.
$this->execute('behat_forms::press_button', get_string('createnewquestion', 'question'));
// Add question.
$this->finish_adding_question($questiontypename, $questiondata);
} }
/** /**

View File

@@ -27,8 +27,7 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given, use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ExpectationException as ExpectationException, Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
@@ -48,15 +47,13 @@ class behat_question_base extends behat_base {
* *
* @param string $questiontypename The question type name * @param string $questiontypename The question type name
* @param TableNode $questiondata The data to fill the question type form * @param TableNode $questiondata The data to fill the question type form
* @return Given[] the steps.
*/ */
protected function finish_adding_question($questiontypename, TableNode $questiondata) { protected function finish_adding_question($questiontypename, TableNode $questiondata) {
return array( $this->execute('behat_forms::i_set_the_field_to', array($this->escape($questiontypename), 1));
new Given('I set the field "' . $this->escape($questiontypename) . '" to "1"'), $this->execute("behat_general::i_click_on", array('.submitbutton', "css_element"));
new Given('I click on ".submitbutton" "css_element"'),
new Given('I set the following fields to these values:', $questiondata), $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $questiondata);
new Given('I press "id_submitbutton"') $this->execute("behat_forms::press_button", 'id_submitbutton');
);
} }
} }