This commit is contained in:
Andrew Nicols 2016-04-06 11:53:41 +08:00
commit d147514986
32 changed files with 865 additions and 832 deletions

View File

@ -28,9 +28,6 @@
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.
*
@ -51,12 +48,11 @@ class behat_auth extends behat_base {
$this->getSession()->visit($this->locate_path('login/index.php'));
// Enter username and password.
$behatforms = behat_context_helper::get('behat_forms');
$behatforms->i_set_the_field_to('Username', $this->escape($username));
$behatforms->i_set_the_field_to('Password', $this->escape($username));
$this->execute('behat_forms::i_set_the_field_to', array('Username', $this->escape($username)));
$this->execute('behat_forms::i_set_the_field_to', array('Password', $this->escape($username)));
// Press log in button.
$behatforms->press_button(get_string('login'));
// Press log in button, no need to check for exceptions as it will checked after this step execution.
$this->execute('behat_forms::press_button', get_string('login'));
}
/**
@ -65,22 +61,18 @@ class behat_auth extends behat_base {
* @Given /^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
// bar needs to be expanded; user_menu now lives outside the
// hamburger.
// However, the user menu *always* needs to be expanded.
$xpath = "//div[@class='usermenu']//a[contains(concat(' ', @class, ' '), ' toggle-display ')]";
array_unshift($steps, new When('I click on "'.$xpath.'" "xpath_element"'));
// 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 ')]";
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');
use Moodle\BehatExtension\Context\Step\Given as Given;
/**
* Blocks management steps definitions.
*
@ -46,16 +44,16 @@ class behat_blocks extends behat_base {
* @param string $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 (!$this->running_javascript()) {
$steps = array(
$steps,
new Given('I click on "' . get_string('go') . '" "button" in the "#add_block" "css_element"')
$this->execute('behat_general::i_click_on_in_the',
array(get_string('go'), "button", "#add_block", "css_element")
);
}
return $steps;
}
/**
@ -63,13 +61,14 @@ class behat_blocks extends behat_base {
*
* @Given /^I dock "(?P<block_name_string>(?:[^"]|\\")*)" block$/
* @param string $blockname
* @return Given
*/
public function i_dock_block($blockname) {
// Looking for both title and alt.
$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$/
* @throws DriverException The step is not available when Javascript is disabled
* @param string $blockname
* @return Given
*/
public function i_open_the_blocks_action_menu($blockname) {
@ -93,7 +91,9 @@ class behat_blocks extends behat_base {
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) {
// 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'),
new Given('I click on "Configure" "link" in the "'.$this->escape($blockname).'" "block"')
$this->execute("behat_blocks::i_open_the_blocks_action_menu", $this->escape($blockname));
$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.
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given;
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:$/
* @param TableNode $data
* @return array the list of actions to perform
*/
public function i_create_a_calendar_event_with_form_data($data) {
// Get the event name.
$eventname = $data->getRow(1);
$eventname = $eventname[1];
// Go to current month page.
$this->execute("behat_general::click_link", get_string('monththis', 'calendar'));
return array(
new Given('I follow "' . get_string('monththis', 'calendar') . '"'),
new Given('I create a calendar event:', $data),
);
// Create event.
$this->i_create_a_calendar_event($data);
}
/**
@ -62,19 +57,24 @@ class behat_calendar extends behat_base {
*
* @Given /^I create a calendar event:$/
* @param TableNode $data
* @return array the list of actions to perform
*/
public function i_create_a_calendar_event($data) {
// Get the event name.
$eventname = $data->getRow(1);
$eventname = $eventname[1];
return array(
new Given('I click on "' . get_string('newevent', 'calendar') .'" "button"'),
new Given('I set the following fields to these values:', $data),
new Given('I press "' . get_string('savechanges') . '"'),
new Given('I should see "' . $eventname . '"')
);
// Click to create new event.
$this->execute("behat_general::i_click_on", array(get_string('newevent', 'calendar'), "button"));
// Set form fields.
$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$/
* @param int $day The day of the current month
* @return Given[]
*/
public function i_hover_over_day_of_this_month_in_calendar($day) {
$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} ')]";
$daycell = "td[{$cellclasses}]";
$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.
*
* @Given /^I hover over today in the calendar$/
* @return Given[]
*/
public function i_hover_over_today_in_the_calendar() {
// For window's compatibility, using %d and not %e.

View File

@ -27,8 +27,6 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given;
/**
* 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) {
$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 (!$this->getSession()->getPage()->find('css', 'input#cohort_search_q')) {
@ -62,15 +53,23 @@ class behat_cohort extends behat_base {
$parentnodes = get_string('administrationsite') . ' > ' .
get_string('users', 'admin') . ' > ' .
get_string('accounts', 'admin');
$steps = array_merge(
array(
new Given('I am on homepage'),
new Given('I navigate to "' . get_string('cohorts', 'cohort') . '" node in "' . $parentnodes . '"')
),
$steps
$this->execute("behat_general::i_am_on_homepage");
$this->execute("behat_navigation::i_navigate_to_node_in",
array(get_string('cohorts', 'cohort'), $parentnodes)
);
}
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');
use Moodle\BehatExtension\Context\Step\Given,
Moodle\BehatExtension\Context\Step\Then,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
/**
* Steps definitions to deal with course and activities completion.
@ -55,9 +53,9 @@ class behat_completion extends behat_base {
$xpath = "//table[@id='completion-progress']" .
"/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')
$this->execute("behat_completion::go_to_the_current_course_activity_completion_report");
$this->execute("behat_general::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");
$xpath = "//table[@id='completion-progress']" .
"/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');
$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');
return array(
new Given('I follow "'.get_string('editsettings').'"'),
new Given('I set the field "'.get_string('enablecompletion', 'completion').'" to "'.$toggle.'"'),
new Given('I press "'.get_string('savechangesanddisplay').'"')
);
// Go to course editing.
$this->execute("behat_general::click_link", get_string('editsettings'));
// 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.
*
* @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) {
if ($completiontype == "manual") {
@ -125,15 +123,17 @@ class behat_completion extends behat_base {
}
$csselementforactivitytype = "li.modtype_".strtolower($activitytype);
return new Given('"//img[contains(@alt, \''.$imgalttext.'\')]" "xpath_element" ' .
'should exist in the "'.$csselementforactivitytype.'" "css_element"');
$xpathtocheck = "//img[contains(@alt, '$imgalttext')]";
$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.
*
* @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) {
if ($completiontype == "manual") {
@ -143,7 +143,10 @@ class behat_completion extends behat_base {
}
$csselementforactivitytype = "li.modtype_".strtolower($activitytype);
return new Given('"//img[contains(@alt, \''.$imgalttext.'\')]" "xpath_element" ' .
'should exist in the "'.$csselementforactivitytype.'" "css_element"');
$xpathtocheck = "//img[contains(@alt, '$imgalttext')]";
$this->execute("behat_general::should_exist_in_the",
array($xpathtocheck, "xpath_element", $csselementforactivitytype, "css_element")
);
}
}

View File

@ -2,6 +2,6 @@
"require-dev": {
"phpunit/phpunit": "4.8.*",
"phpunit/dbUnit": "1.4.*",
"moodlehq/behat-extension": "3.31.0"
"moodlehq/behat-extension": "3.31.1"
}
}

252
composer.lock generated
View File

@ -4,41 +4,40 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "769fa23c4b31f60c9fb82d5b23171e0f",
"content-hash": "5fca4c69d043cb1f985fc08cd82a64f8",
"hash": "08ee36172d6de7fe083e753b44255ed7",
"content-hash": "2bc89ce1a925ac037c899ae6f02eaa26",
"packages": [],
"packages-dev": [
{
"name": "behat/behat",
"version": "v3.0.15",
"version": "v3.1.0",
"source": {
"type": "git",
"url": "https://github.com/Behat/Behat.git",
"reference": "b35ae3d45332d80c532af69cc36f780a9397a996"
"reference": "359d987b3064d78f2d3a6ba3a355277f3b09b47f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Behat/Behat/zipball/b35ae3d45332d80c532af69cc36f780a9397a996",
"reference": "b35ae3d45332d80c532af69cc36f780a9397a996",
"url": "https://api.github.com/repos/Behat/Behat/zipball/359d987b3064d78f2d3a6ba3a355277f3b09b47f",
"reference": "359d987b3064d78f2d3a6ba3a355277f3b09b47f",
"shasum": ""
},
"require": {
"behat/gherkin": "~4.3",
"behat/gherkin": "~4.4",
"behat/transliterator": "~1.0",
"ext-mbstring": "*",
"php": ">=5.3.3",
"symfony/class-loader": "~2.1",
"symfony/config": "~2.3",
"symfony/console": "~2.1",
"symfony/dependency-injection": "~2.1",
"symfony/event-dispatcher": "~2.1",
"symfony/translation": "~2.3",
"symfony/yaml": "~2.1"
"symfony/class-loader": "~2.1|~3.0",
"symfony/config": "~2.3|~3.0",
"symfony/console": "~2.1|~3.0",
"symfony/dependency-injection": "~2.1|~3.0",
"symfony/event-dispatcher": "~2.1|~3.0",
"symfony/translation": "~2.3|~3.0",
"symfony/yaml": "~2.1|~3.0"
},
"require-dev": {
"phpspec/prophecy-phpunit": "~1.0",
"phpunit/phpunit": "~4.0",
"symfony/process": "~2.1"
"phpunit/phpunit": "~4.5",
"symfony/process": "~2.1|~3.0"
},
"suggest": {
"behat/mink-extension": "for integration with Mink testing framework",
@ -51,7 +50,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
"dev-master": "3.1.x-dev"
}
},
"autoload": {
@ -87,7 +86,7 @@
"symfony",
"testing"
],
"time": "2015-02-22 14:10:33"
"time": "2016-03-28 07:04:45"
},
{
"name": "behat/gherkin",
@ -149,24 +148,24 @@
},
{
"name": "behat/mink",
"version": "v1.7.0",
"version": "v1.7.1",
"source": {
"type": "git",
"url": "https://github.com/minkphp/Mink.git",
"reference": "6c129030ec2cc029905cf969a56ca8f087b2dfdf"
"reference": "e6930b9c74693dff7f4e58577e1b1743399f3ff9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/minkphp/Mink/zipball/6c129030ec2cc029905cf969a56ca8f087b2dfdf",
"reference": "6c129030ec2cc029905cf969a56ca8f087b2dfdf",
"url": "https://api.github.com/repos/minkphp/Mink/zipball/e6930b9c74693dff7f4e58577e1b1743399f3ff9",
"reference": "e6930b9c74693dff7f4e58577e1b1743399f3ff9",
"shasum": ""
},
"require": {
"php": ">=5.3.1",
"symfony/css-selector": "~2.1"
"symfony/css-selector": "~2.1|~3.0"
},
"require-dev": {
"symfony/phpunit-bridge": "~2.7"
"symfony/phpunit-bridge": "~2.7|~3.0"
},
"suggest": {
"behat/mink-browserkit-driver": "extremely fast headless driver for Symfony\\Kernel-based apps (Sf2, Silex)",
@ -203,24 +202,24 @@
"testing",
"web"
],
"time": "2015-09-20 20:24:03"
"time": "2016-03-05 08:26:18"
},
{
"name": "behat/mink-browserkit-driver",
"version": "v1.3.1",
"version": "v1.3.2",
"source": {
"type": "git",
"url": "https://github.com/minkphp/MinkBrowserKitDriver.git",
"reference": "2650f5420e713e3807c7f09a07370a4f48367bf9"
"reference": "10e67fb4a295efcd62ea0bf16025a85ea19534fb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/minkphp/MinkBrowserKitDriver/zipball/2650f5420e713e3807c7f09a07370a4f48367bf9",
"reference": "2650f5420e713e3807c7f09a07370a4f48367bf9",
"url": "https://api.github.com/repos/minkphp/MinkBrowserKitDriver/zipball/10e67fb4a295efcd62ea0bf16025a85ea19534fb",
"reference": "10e67fb4a295efcd62ea0bf16025a85ea19534fb",
"shasum": ""
},
"require": {
"behat/mink": "~1.7@dev",
"behat/mink": "^1.7.1@dev",
"php": ">=5.3.6",
"symfony/browser-kit": "~2.3|~3.0",
"symfony/dom-crawler": "~2.3|~3.0"
@ -259,7 +258,7 @@
"browser",
"testing"
],
"time": "2016-01-19 16:59:07"
"time": "2016-03-05 08:59:47"
},
{
"name": "behat/mink-extension",
@ -322,16 +321,16 @@
},
{
"name": "behat/mink-goutte-driver",
"version": "v1.2.0",
"version": "v1.2.1",
"source": {
"type": "git",
"url": "https://github.com/minkphp/MinkGoutteDriver.git",
"reference": "c8e254f127d6f2242b994afd4339fb62d471df3f"
"reference": "8b9ad6d2d95bc70b840d15323365f52fcdaea6ca"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/minkphp/MinkGoutteDriver/zipball/c8e254f127d6f2242b994afd4339fb62d471df3f",
"reference": "c8e254f127d6f2242b994afd4339fb62d471df3f",
"url": "https://api.github.com/repos/minkphp/MinkGoutteDriver/zipball/8b9ad6d2d95bc70b840d15323365f52fcdaea6ca",
"reference": "8b9ad6d2d95bc70b840d15323365f52fcdaea6ca",
"shasum": ""
},
"require": {
@ -341,7 +340,7 @@
"php": ">=5.3.1"
},
"require-dev": {
"symfony/phpunit-bridge": "~2.7"
"symfony/phpunit-bridge": "~2.7|~3.0"
},
"type": "mink-driver",
"extra": {
@ -373,20 +372,20 @@
"headless",
"testing"
],
"time": "2015-09-21 21:31:11"
"time": "2016-03-05 09:04:22"
},
{
"name": "behat/mink-selenium2-driver",
"version": "v1.3.0",
"version": "v1.3.1",
"source": {
"type": "git",
"url": "https://github.com/minkphp/MinkSelenium2Driver.git",
"reference": "bedbf1999c7ba1bc6921b30ee2eadf383e7ff5c9"
"reference": "473a9f3ebe0c134ee1e623ce8a9c852832020288"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/minkphp/MinkSelenium2Driver/zipball/bedbf1999c7ba1bc6921b30ee2eadf383e7ff5c9",
"reference": "bedbf1999c7ba1bc6921b30ee2eadf383e7ff5c9",
"url": "https://api.github.com/repos/minkphp/MinkSelenium2Driver/zipball/473a9f3ebe0c134ee1e623ce8a9c852832020288",
"reference": "473a9f3ebe0c134ee1e623ce8a9c852832020288",
"shasum": ""
},
"require": {
@ -434,7 +433,7 @@
"testing",
"webdriver"
],
"time": "2015-09-21 21:02:54"
"time": "2016-03-05 09:10:18"
},
{
"name": "behat/transliterator",
@ -798,20 +797,20 @@
},
{
"name": "moodlehq/behat-extension",
"version": "v3.31.0",
"version": "v3.31.1",
"source": {
"type": "git",
"url": "https://github.com/moodlehq/moodle-behat-extension.git",
"reference": "d985e9da29914b0da90d61c47aadc455586eeee5"
"reference": "d876ea5940e7ad115318140ae37f228c70450225"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/moodlehq/moodle-behat-extension/zipball/d985e9da29914b0da90d61c47aadc455586eeee5",
"reference": "d985e9da29914b0da90d61c47aadc455586eeee5",
"url": "https://api.github.com/repos/moodlehq/moodle-behat-extension/zipball/d876ea5940e7ad115318140ae37f228c70450225",
"reference": "d876ea5940e7ad115318140ae37f228c70450225",
"shasum": ""
},
"require": {
"behat/behat": "3.0.*",
"behat/behat": "3.1.*",
"behat/mink": "~1.7",
"behat/mink-extension": "~2.1",
"behat/mink-goutte-driver": "~1.2",
@ -843,7 +842,7 @@
"Behat",
"moodle"
],
"time": "2016-03-04 07:15:40"
"time": "2016-04-01 01:57:33"
},
{
"name": "phpdocumentor/reflection-docblock",
@ -1257,16 +1256,16 @@
},
{
"name": "phpunit/phpunit",
"version": "4.8.23",
"version": "4.8.24",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "6e351261f9cd33daf205a131a1ba61c6d33bd483"
"reference": "a1066c562c52900a142a0e2bbf0582994671385e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6e351261f9cd33daf205a131a1ba61c6d33bd483",
"reference": "6e351261f9cd33daf205a131a1ba61c6d33bd483",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a1066c562c52900a142a0e2bbf0582994671385e",
"reference": "a1066c562c52900a142a0e2bbf0582994671385e",
"shasum": ""
},
"require": {
@ -1325,7 +1324,7 @@
"testing",
"xunit"
],
"time": "2016-02-11 14:56:33"
"time": "2016-03-14 06:16:08"
},
{
"name": "phpunit/phpunit-mock-objects",
@ -1385,16 +1384,16 @@
},
{
"name": "react/promise",
"version": "v2.2.2",
"version": "v2.4.0",
"source": {
"type": "git",
"url": "https://github.com/reactphp/promise.git",
"reference": "3aacad8bf10c7d83e6fa2089d413529888c2bedf"
"reference": "f942da7b505d1a294284ab343d05df42d02ad6d9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/reactphp/promise/zipball/3aacad8bf10c7d83e6fa2089d413529888c2bedf",
"reference": "3aacad8bf10c7d83e6fa2089d413529888c2bedf",
"url": "https://api.github.com/repos/reactphp/promise/zipball/f942da7b505d1a294284ab343d05df42d02ad6d9",
"reference": "f942da7b505d1a294284ab343d05df42d02ad6d9",
"shasum": ""
},
"require": {
@ -1425,7 +1424,7 @@
}
],
"description": "A lightweight implementation of CommonJS Promises/A for PHP",
"time": "2016-02-26 19:09:02"
"time": "2016-03-31 13:10:33"
},
{
"name": "sebastian/comparator",
@ -1800,16 +1799,16 @@
},
{
"name": "symfony/browser-kit",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/browser-kit.git",
"reference": "6b2085020b4e86fcb7ae44c3ab8ddb91774b33d2"
"reference": "745c19467255cf32eaf311f000eecafd83ca5586"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/browser-kit/zipball/6b2085020b4e86fcb7ae44c3ab8ddb91774b33d2",
"reference": "6b2085020b4e86fcb7ae44c3ab8ddb91774b33d2",
"url": "https://api.github.com/repos/symfony/browser-kit/zipball/745c19467255cf32eaf311f000eecafd83ca5586",
"reference": "745c19467255cf32eaf311f000eecafd83ca5586",
"shasum": ""
},
"require": {
@ -1853,20 +1852,20 @@
],
"description": "Symfony BrowserKit Component",
"homepage": "https://symfony.com",
"time": "2016-01-27 11:34:40"
"time": "2016-03-04 07:54:35"
},
{
"name": "symfony/class-loader",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/class-loader.git",
"reference": "517ab0554b6a5744d04480cb06873ffbd9442d73"
"reference": "7d362c22710980730d46a5d039e788946a2938cb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/class-loader/zipball/517ab0554b6a5744d04480cb06873ffbd9442d73",
"reference": "517ab0554b6a5744d04480cb06873ffbd9442d73",
"url": "https://api.github.com/repos/symfony/class-loader/zipball/7d362c22710980730d46a5d039e788946a2938cb",
"reference": "7d362c22710980730d46a5d039e788946a2938cb",
"shasum": ""
},
"require": {
@ -1906,20 +1905,20 @@
],
"description": "Symfony ClassLoader Component",
"homepage": "https://symfony.com",
"time": "2016-01-30 15:58:35"
"time": "2016-03-10 19:33:53"
},
{
"name": "symfony/config",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/config.git",
"reference": "0f8f94e6a32b5c480024eed5fa5cbd2790d0ad19"
"reference": "5273f4724dc5288fe7a33cb08077ab9852621f2c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/config/zipball/0f8f94e6a32b5c480024eed5fa5cbd2790d0ad19",
"reference": "0f8f94e6a32b5c480024eed5fa5cbd2790d0ad19",
"url": "https://api.github.com/repos/symfony/config/zipball/5273f4724dc5288fe7a33cb08077ab9852621f2c",
"reference": "5273f4724dc5288fe7a33cb08077ab9852621f2c",
"shasum": ""
},
"require": {
@ -1959,20 +1958,20 @@
],
"description": "Symfony Config Component",
"homepage": "https://symfony.com",
"time": "2016-02-22 16:12:45"
"time": "2016-03-04 07:54:35"
},
{
"name": "symfony/console",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "56cc5caf051189720b8de974e4746090aaa10d44"
"reference": "9a5aef5fc0d4eff86853d44202b02be8d5a20154"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/56cc5caf051189720b8de974e4746090aaa10d44",
"reference": "56cc5caf051189720b8de974e4746090aaa10d44",
"url": "https://api.github.com/repos/symfony/console/zipball/9a5aef5fc0d4eff86853d44202b02be8d5a20154",
"reference": "9a5aef5fc0d4eff86853d44202b02be8d5a20154",
"shasum": ""
},
"require": {
@ -2019,20 +2018,20 @@
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
"time": "2016-02-28 16:20:50"
"time": "2016-03-17 09:19:04"
},
{
"name": "symfony/css-selector",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/css-selector.git",
"reference": "8d83ff9777cdbd83e7f90d9c48f4729823791a5e"
"reference": "07b7ced3ae0c12918477c095453ea8595000810e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/8d83ff9777cdbd83e7f90d9c48f4729823791a5e",
"reference": "8d83ff9777cdbd83e7f90d9c48f4729823791a5e",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/07b7ced3ae0c12918477c095453ea8595000810e",
"reference": "07b7ced3ae0c12918477c095453ea8595000810e",
"shasum": ""
},
"require": {
@ -2072,20 +2071,20 @@
],
"description": "Symfony CssSelector Component",
"homepage": "https://symfony.com",
"time": "2016-01-27 05:14:19"
"time": "2016-03-04 07:54:35"
},
{
"name": "symfony/dependency-injection",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/dependency-injection.git",
"reference": "62251761a7615435b22ccf562384c588b431be44"
"reference": "f7b4a498e679fa440b16facb934680a1527ed48c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/dependency-injection/zipball/62251761a7615435b22ccf562384c588b431be44",
"reference": "62251761a7615435b22ccf562384c588b431be44",
"url": "https://api.github.com/repos/symfony/dependency-injection/zipball/f7b4a498e679fa440b16facb934680a1527ed48c",
"reference": "f7b4a498e679fa440b16facb934680a1527ed48c",
"shasum": ""
},
"require": {
@ -2134,20 +2133,20 @@
],
"description": "Symfony DependencyInjection Component",
"homepage": "https://symfony.com",
"time": "2016-02-28 16:34:46"
"time": "2016-03-21 07:27:21"
},
{
"name": "symfony/dom-crawler",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/dom-crawler.git",
"reference": "e1a4b4c83f5ee6f5902f1d53035e3718909a0c11"
"reference": "aae5c37d243c6ec11db62221aaff37e7f8005926"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/e1a4b4c83f5ee6f5902f1d53035e3718909a0c11",
"reference": "e1a4b4c83f5ee6f5902f1d53035e3718909a0c11",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/aae5c37d243c6ec11db62221aaff37e7f8005926",
"reference": "aae5c37d243c6ec11db62221aaff37e7f8005926",
"shasum": ""
},
"require": {
@ -2190,20 +2189,20 @@
],
"description": "Symfony DomCrawler Component",
"homepage": "https://symfony.com",
"time": "2016-02-28 16:20:50"
"time": "2016-03-23 13:11:46"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "78c468665c9568c3faaa9c416a7134308f2d85c3"
"reference": "47d2d8cade9b1c3987573d2943bb9352536cdb87"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/78c468665c9568c3faaa9c416a7134308f2d85c3",
"reference": "78c468665c9568c3faaa9c416a7134308f2d85c3",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/47d2d8cade9b1c3987573d2943bb9352536cdb87",
"reference": "47d2d8cade9b1c3987573d2943bb9352536cdb87",
"shasum": ""
},
"require": {
@ -2250,20 +2249,20 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
"time": "2016-01-27 05:14:19"
"time": "2016-03-07 14:04:32"
},
{
"name": "symfony/filesystem",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "65cb36b6539b1d446527d60457248f30d045464d"
"reference": "f08ffdf229252cd2745558cb2112df43903bcae4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/65cb36b6539b1d446527d60457248f30d045464d",
"reference": "65cb36b6539b1d446527d60457248f30d045464d",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/f08ffdf229252cd2745558cb2112df43903bcae4",
"reference": "f08ffdf229252cd2745558cb2112df43903bcae4",
"shasum": ""
},
"require": {
@ -2299,20 +2298,20 @@
],
"description": "Symfony Filesystem Component",
"homepage": "https://symfony.com",
"time": "2016-02-22 15:02:30"
"time": "2016-03-27 10:20:16"
},
{
"name": "symfony/polyfill-apcu",
"version": "v1.1.0",
"version": "v1.1.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-apcu.git",
"reference": "d1911e6caeb4b6a4c8e2d5c46b978a66b3745e4c"
"reference": "0c901e4e65a2f7ece68f0fd249b56d6ad3adc214"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-apcu/zipball/d1911e6caeb4b6a4c8e2d5c46b978a66b3745e4c",
"reference": "d1911e6caeb4b6a4c8e2d5c46b978a66b3745e4c",
"url": "https://api.github.com/repos/symfony/polyfill-apcu/zipball/0c901e4e65a2f7ece68f0fd249b56d6ad3adc214",
"reference": "0c901e4e65a2f7ece68f0fd249b56d6ad3adc214",
"shasum": ""
},
"require": {
@ -2327,9 +2326,6 @@
"autoload": {
"files": [
"bootstrap.php"
],
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
@ -2355,11 +2351,11 @@
"portable",
"shim"
],
"time": "2016-01-20 09:13:37"
"time": "2016-03-03 16:49:40"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.1.0",
"version": "v1.1.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
@ -2418,16 +2414,16 @@
},
{
"name": "symfony/process",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe"
"reference": "fb467471952ef5cf8497c029980e556b47545333"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe",
"reference": "7dedd5b60550f33dca16dd7e94ef8aca8b67bbfe",
"url": "https://api.github.com/repos/symfony/process/zipball/fb467471952ef5cf8497c029980e556b47545333",
"reference": "fb467471952ef5cf8497c029980e556b47545333",
"shasum": ""
},
"require": {
@ -2463,20 +2459,20 @@
],
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
"time": "2016-02-02 13:33:15"
"time": "2016-03-23 13:11:46"
},
{
"name": "symfony/translation",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/translation.git",
"reference": "b7b4ebadd2b5e614ff7d2d6fc63e0ed0578909c7"
"reference": "d60b8e076d22953aabebeebda53bf334438e7aca"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/translation/zipball/b7b4ebadd2b5e614ff7d2d6fc63e0ed0578909c7",
"reference": "b7b4ebadd2b5e614ff7d2d6fc63e0ed0578909c7",
"url": "https://api.github.com/repos/symfony/translation/zipball/d60b8e076d22953aabebeebda53bf334438e7aca",
"reference": "d60b8e076d22953aabebeebda53bf334438e7aca",
"shasum": ""
},
"require": {
@ -2527,20 +2523,20 @@
],
"description": "Symfony Translation Component",
"homepage": "https://symfony.com",
"time": "2016-02-02 09:49:18"
"time": "2016-03-25 01:40:30"
},
{
"name": "symfony/yaml",
"version": "v2.8.3",
"version": "v2.8.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "2a4ee40acb880c56f29fb1b8886e7ffe94f3b995"
"reference": "584e52cb8f788a887553ba82db6caacb1d6260bb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/2a4ee40acb880c56f29fb1b8886e7ffe94f3b995",
"reference": "2a4ee40acb880c56f29fb1b8886e7ffe94f3b995",
"url": "https://api.github.com/repos/symfony/yaml/zipball/584e52cb8f788a887553ba82db6caacb1d6260bb",
"reference": "584e52cb8f788a887553ba82db6caacb1d6260bb",
"shasum": ""
},
"require": {
@ -2576,7 +2572,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2016-02-23 07:41:20"
"time": "2016-03-04 07:54:35"
}
],
"aliases": [],

View File

@ -27,8 +27,7 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode,
use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\DriverException as DriverException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
@ -48,7 +47,8 @@ class behat_course extends behat_base {
* @Given /^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$/
*/
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:$/
* @param TableNode $table The course data
* @return Given[]
*/
public function i_create_a_course_with(TableNode $table) {
$steps = array(
new Given('I go to the courses management page'),
new Given('I should see the "'.get_string('categories').'" management page'),
new Given('I click on category "'.get_string('miscellaneous').'" in the management interface'),
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"')
// Go to course management page.
$this->i_go_to_the_courses_management_page();
// Ensure you are on course management page.
$this->execute("behat_course::i_should_see_the_courses_management_page", get_string('categories'));
// 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
@ -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
// format field when the editor is being rendered and the click misses the field coordinates.
$steps[] = new Given('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);
} else {
$steps[] = new Given('I set the following fields to these values:', $table);
$this->execute("behat_forms::i_expand_all_fieldsets");
$this->execute("behat_forms::i_set_the_field_to", array($formatfield, $formatvalue));
}
$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.
*
* @Given /^I go to the courses management page$/
* @return Given[]
*/
public function i_go_to_the_courses_management_page() {
return array(
new Given('I am on homepage'),
new Given('I navigate to "' . get_string('coursemgmt', 'admin') . '" node in "' . get_string('administrationsite') . ' > ' . get_string('courses', 'admin') . '"')
$parentnodes = 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 int $section The section number
* @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) {
return array(
new Given('I add a "' . $this->escape($activity) . '" to section "' . $this->escape($section) . '"'),
new Given('I wait to be redirected'),
new Given('I set the following fields to these values:', $data),
new Given('I press "' . get_string('savechangesandreturntocourse') . '"')
// Add activity to section.
$this->execute("behat_course::i_add_to_section",
array($this->escape($activity), $this->escape($section))
);
// 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+)"$/
* @param int $sectionnumber The section number
* @return Given[]
*/
public function i_delete_section($sectionnumber) {
// Ensures the section exists.
@ -253,7 +271,11 @@ class behat_course extends behat_base {
$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$/
* @param int $sectionnumber The section number
* @return Given[]
*/
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);
}
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$/
* @param int $sectionnumber The section number
* @return Given[]
*/
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);
}
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');
}
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:$/
* @param int $sectionnumber The section number
* @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) {
return array(
new Given('I edit the section "' . $sectionnumber . '"'),
new Given('I set the following fields to these values:', $data),
new Given('I press "' . get_string('savechanges') . '"')
);
// Edit given section.
$this->execute("behat_course::i_edit_the_section");
// 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+)"$/
* @param string $activityname The activity name
* @param int $sectionnumber The number of section
* @return Given[]
*/
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 ')]";
return array(
new Given('I drag "' . $this->escape($activitynode->getXpath()) . '" "xpath_element" ' .
'and I drop it in "' . $this->escape($destinationxpath) . '" "xpath_element"'),
$this->execute("behat_general::i_drag_and_i_drop_it_in",
array($this->escape($activitynode->getXpath()), "xpath_element",
$this->escape($destinationxpath), "xpath_element")
);
} else {
// Following links with no-JS.
// Moving to the fist spot of the section (before all other section's activities).
return array(
new Given('I click on "a.editing_move" "css_element" in the "' . $this->escape($activityname) . '" activity'),
new Given('I click on "li.movehere a" "css_element" in the "' . $this->escape($sectionxpath) . '" "xpath_element"'),
$this->execute('behat_course::i_click_on_in_the_activity',
array("a.editing_move", "css_element", $this->escape($activityname))
);
$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
* @param string $activityname
* @param string $newactivityname
* @return Given[]
*/
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');
}
// Adding chr(10) to save changes.
$activity = $this->escape($activityname);
return array(
new Given('I click on "' . get_string('edittitle') . '" "link" in the "' . $activity .'" activity'),
new Given('I set the field "title" to "' . $this->escape($newactivityname) . chr(10) . '"')
$this->execute('behat_course::i_click_on_in_the_activity',
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$/
* @throws DriverException The step is not available when Javascript is disabled
* @param string $activityname
* @return Given
*/
public function i_open_actions_menu($activityname) {
@ -706,7 +743,10 @@ class behat_course extends behat_base {
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$/
* @throws DriverException The step is not available when Javascript is disabled
* @param string $activityname
* @return Given
*/
public function i_close_actions_menu($activityname) {
@ -730,7 +769,9 @@ class behat_course extends behat_base {
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'])) {
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$/
* @param string $activityname
* @return Given[]
*/
public function i_indent_right_activity($activityname) {
$steps = array();
$activity = $this->escape($activityname);
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$/
* @param string $activityname
* @return Given[]
*/
public function i_indent_left_activity($activityname) {
$steps = array();
$activity = $this->escape($activityname);
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$/
* @param string $activityname
* @return Given[]
*/
public function i_delete_activity($activityname) {
$steps = array();
$activity = $this->escape($activityname);
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.
// Not using chain steps here because the exceptions catcher have problems detecting
// JS modal windows and avoiding interacting them at the same time.
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 {
$steps[] = new Given('I press "' . get_string('yes') . '"');
$this->execute("behat_forms::press_button", get_string('yes'));
}
return $steps;
@ -827,16 +869,17 @@ class behat_course extends behat_base {
*
* @Given /^I duplicate "(?P<activity_name_string>(?:[^"]|\\")*)" activity$/
* @param string $activityname
* @return Given[]
*/
public function i_duplicate_activity($activityname) {
$steps = array();
$activity = $this->escape($activityname);
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');
return $steps;
$this->execute('behat_course::i_click_on_in_the_activity',
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:$/
* @param string $activityname
* @param TableNode $data
* @return Given[]
*/
public function i_duplicate_activity_editing_the_new_copy_with($activityname, TableNode $data) {
$steps = array();
$activity = $this->escape($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.
$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 ')]" .
"/descendant::div[contains(concat(' ', @class, ' '), ' lightbox ')][contains(@style, 'display: none')]";
$steps[] = new Given('I wait until the page is ready');
$steps[] = new Given('I wait until "' . $this->escape($hiddenlightboxxpath) .'" "xpath_element" exists');
$this->execute("behat_general::wait_until_exists",
array($this->escape($hiddenlightboxxpath), "xpath_element")
);
// 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
// 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.
$steps[] = new Given('I click on "' . get_string('editsettings') . '" "link" in the "' .
$this->escape($duplicatedxpath) . '" "xpath_element"');
$this->execute('behat_general::i_click_on_in_the',
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$/
* @param string $name
* @return Given[]
*/
public function i_move_category_to_top_level_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() . '"'),
new Given('I press "bulkmovecategories"'),
$this->execute('behat_forms::i_set_the_field_to',
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$/
* @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) {
$return = array(
new Given('I should see "Course and category management" in the "h2" "css_element"')
$this->execute("behat_general::assert_element_contains_text",
array("Course and category management", "h2", "css_element")
);
switch ($mode) {
case "Courses":
$return[] = new Given('"#category-listing" "css_element" should not exist');
$return[] = new Given('"#course-listing" "css_element" should exist');
$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":
$return[] = new Given('"#category-listing" "css_element" should exist');
$return[] = new Given('"#course-listing" "css_element" should exist');
$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:
$return[] = new Given('"#category-listing" "css_element" should exist');
$return[] = new Given('"#course-listing" "css_element" should exist');
$this->execute("behat_general::should_exist", array("#category-listing", "css_element"));
$this->execute("behat_general::should_exist", array("#course-listing", "css_element"));
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$/
* @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) {
$return = $this->i_should_see_the_courses_management_page($mode);
array_pop($return);
$return[] = new Given('"#course-detail" "css_element" should exist');
return $return;
$this->execute("behat_general::assert_element_contains_text",
array("Course and category management", "h2", "css_element"));
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');
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode;
use Behat\Gherkin\Node\TableNode as TableNode;
/**
* Steps definitions for general enrolment actions.
@ -48,14 +47,23 @@ class behat_enrol extends behat_base {
* @param TableNode $table
*/
public function i_add_enrolment_method_with($enrolmethod, TableNode $table) {
return array(
new Given('I expand "' . get_string('users', 'admin') . '" node'),
new Given('I follow "' . get_string('type_enrol_plural', 'plugin') . '"'),
new Given('I select "' . $this->escape($enrolmethod) . '" from the "' .
get_string('addinstance', 'enrol') . '" singleselect'),
new Given('I set the following fields to these values:', $table),
new Given('I press "' . get_string('addinstance', 'enrol') . '"'),
// Navigate to enrolment method page.
$parentnodes = get_string('courseadministration') . ' > ' . get_string('users', 'admin');
$this->execute("behat_navigation::i_navigate_to_node_in",
array(get_string('type_enrol_plural', 'plugin'), $parentnodes)
);
// 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>(?:[^"]|\\")*)"$/
* @param string $userfullname
* @param string $rolename
* @return Given[]
*/
public function i_enrol_user_as($userfullname, $rolename) {
$steps = array(
new Given('I follow "' . get_string('enrolledusers', 'enrol') . '"'),
new Given('I press "' . get_string('enrolusers', 'enrol') . '"')
// Navigate to enrolment page.
$parentnodes = get_string('courseadministration') . ' > ' . get_string('users', 'admin');
$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()) {
// We have a div here, not a tr.
$userliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname);
$userrowxpath = "//div[contains(concat(' ',normalize-space(@class),' '),' user ')][contains(., $userliteral)]";
$steps[] = new Given('I set the field "' . get_string('assignroles', 'role') . '" to "' . $rolename . '"');
$steps[] = new Given('I click on "' . get_string('enrol', 'enrol') . '" "button" in the "' . $userrowxpath . '" "xpath_element"');
$steps[] = new Given('I press "' . get_string('finishenrollingusers', 'enrol') . '"');
$this->execute('behat_general::i_click_on_in_the',
array(get_string('enrol', 'enrol'), "button", $userrowxpath, "xpath_element")
);
$this->execute("behat_forms::press_button", get_string('finishenrollingusers', 'enrol'));
} else {
$steps[] = new Given('I set the field "' . get_string('assignrole', 'role') . '" to "' . $rolename . '"');
$steps[] = new Given('I set the field "addselect" to "' . $userfullname . '"');
$steps[] = new Given('I press "add"');
$this->execute('behat_forms::i_set_the_field_to', array("addselect", $userfullname));
$this->execute("behat_forms::press_button", "add");
}
return $steps;
}
}

View File

@ -26,9 +26,6 @@
require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');
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\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' .
' 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.
foreach ($criteria as $name => $criterion) {
@ -192,12 +186,11 @@ class behat_gradingform_guide extends behat_base {
if ($criterionid) {
$criterionroot = 'advancedgrading[criteria]' . '[' . $criterionid . ']';
$steps[] = new Given('I set the field "' . $criterionroot . '[score]' . '" to "' . $points . '"');
$steps[] = new Given('I set the field "' . $criterionroot . '[remark]' . '" to "' . $criterion[1] . '"');
$this->execute('behat_forms::i_set_the_field_to', array($criterionroot . '[score]', $points));
$this->execute('behat_forms::i_set_the_field_to', array($criterionroot . '[remark]', $criterion[1]));
}
}
return $steps;
}
/**

View File

@ -28,7 +28,6 @@
require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');
use Behat\Gherkin\Node\TableNode as TableNode,
Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
Behat\Mink\Exception\ExpectationException as ExpectationException;
@ -225,7 +224,6 @@ class behat_gradingform_rubric extends behat_base {
* @param string $currentvalue
* @param string $value
* @param string $criterionname
* @return Given[]
*/
public function i_replace_rubric_level_with($currentvalue, $value, $criterionname) {
@ -275,7 +273,6 @@ class behat_gradingform_rubric extends behat_base {
*
* @throws ExpectationException
* @param TableNode $rubric
* @return void
*/
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' .
' 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.
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.
if (!in_array('checked', explode(' ', $levelnode->getAttribute('class')))) {
$steps[] = new Given('I click on "' . $selectedlevelxpath . '" "xpath_element" in the "' .
$this->escape($name) . '" "table_row"');
$this->execute('behat_general::i_click_on_in_the',
array($selectedlevelxpath, "xpath_element", $this->escape($name), "table_row")
);
}
} else {
@ -321,7 +316,6 @@ class behat_gradingform_rubric extends behat_base {
$radioxpath = $this->get_criterion_xpath($name) .
$selectedlevelxpath . "/descendant::input[@type='radio']";
$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.
$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.
$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');
use Behat\Gherkin\Node\TableNode as TableNode,
Moodle\BehatExtension\Context\Step\Given as Given,
Moodle\BehatExtension\Context\Step\When as When;
use Behat\Gherkin\Node\TableNode as TableNode;
/**
* 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$/
* @param string $activityname
* @return Given[]
*/
public function i_go_to_advanced_grading_page($activityname) {
return array(
new Given('I follow "' . $this->escape($activityname) . '"'),
new Given('I follow "' . get_string('gradingmanagement', 'grading') . '"'),
);
$this->execute('behat_general::click_link', $this->escape($activityname));
$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$/
* @param string $activityname
* @return Given[]
*/
public function i_go_to_advanced_grading_definition_page($activityname) {
@ -72,10 +68,9 @@ class behat_grading extends behat_base {
$definitionxpath = "//a[@class='action']" .
"[./descendant::*[contains(., $newactionliteral) or contains(., $editactionliteral)]]";
return array(
new Given('I go to "' . $this->escape($activityname) . '" advanced grading page'),
new Given('I click on "' . $this->escape($definitionxpath) . '" "xpath_element"'),
);
$this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
$this->execute("behat_general::i_click_on", array($this->escape($definitionxpath), "xpath_element"));
}
/**
* 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$/
* @param string $userfullname The user full name including firstname and lastname.
* @param string $activityname The activity name
* @return Given[]
*/
public function i_go_to_activity_advanced_grading_page($userfullname, $activityname) {
// Step to access the user grade page from the grading page.
$usergradetext = get_string('gradeuser', 'assign', $userfullname);
$gradeuserstep = new Given('I follow "' . $this->escape($usergradetext) . '"');
// Shortcut in case we already are in the grading page.
$usergradetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($usergradetext);
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(
new Given('I follow "' . $this->escape($activityname) . '"'),
new Given('I follow "' . $this->escape(get_string('viewgrading', 'assign')) . '"'),
$gradeuserstep
);
$this->execute('behat_general::click_link', $this->escape($activityname));
$this->execute('behat_general::click_link', $this->escape(get_string('viewgrading', 'assign')));
$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$/
* @param string $activityname
* @return Given[]
*/
public function i_publish_grading_form_definition_as_a_public_template($activityname) {
return array(
new Given('I go to "' . $this->escape($activityname) . '" advanced grading page'),
new Given('I click on "' . $this->escape(get_string("manageactionshare", "grading")) . '" "link"'),
new Given('I press "' . get_string('continue') . '"')
);
$this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
$this->execute("behat_general::i_click_on", array($this->escape(get_string("manageactionshare", "grading")), "link"));
$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$/
* @param string $activityname
* @param string $templatename
* @return Given[]
*/
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]]|" .
"/a[./descendant::div[text()=$literalownform]]";
return array(
new Given('I go to "' . $this->escape($activityname) . '" advanced grading page'),
new Given('I follow "' . $this->escape(get_string('manageactionclone', 'grading')) . '"'),
new Given('I set the field "' . get_string('searchownforms', 'grading') . '" to "1"'),
new Given('I click on "' . get_string('search') . '" "button" in the "region-main" "region"'),
new Given('I click on "' . $this->escape($usetemplatexpath) . '" "xpath_element" ' .
'in the "' . $this->escape($templatexpath) . '" "xpath_element"'),
new Given('I press "' . get_string('continue') . '"')
$this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
$this->execute('behat_general::click_link', $this->escape(get_string('manageactionclone', 'grading')));
$this->execute('behat_forms::i_set_the_field_to', array(get_string('searchownforms', 'grading'), 1));
$this->execute('behat_general::i_click_on_in_the',
array(get_string('search'), "button", "region-main", "region")
);
$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.
*
* @When /^I save the advanced grading form$/
* @return When[]
*/
public function i_save_the_advanced_grading_form() {
return array(
new When('I press "' . get_string('savechanges') . '"'),
new When('I press "' . get_string('continue') . '"')
);
$this->execute('behat_forms::press_button', get_string('savechanges'));
$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:$/
* @param TableNode $data
* @return Given[]
*/
public function i_complete_the_advanced_grading_form_with_these_values(TableNode $data) {
return array(
new Given('I set the following fields to these values:', $data),
new Given('I save the advanced grading form')
);
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
$this->execute('behat_grading::i_save_the_advanced_grading_form');
}
}

View File

@ -27,9 +27,7 @@
require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given,
Moodle\BehatExtension\Context\Step\Then,
Behat\Mink\Exception\ExpectationException as ExpectationException,
use Behat\Mink\Exception\ExpectationException as ExpectationException,
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 "([^"]*)"$/
* @param string $student
* @param string $itemname
* @return Given
*/
public function i_click_on_student_and_grade_item($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$/
* @param string $student
* @param string $itemname
* @return Given
*/
public function i_click_away_from_student_and_grade_value($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$/
* @param string $student
* @param string $itemname
* @return Given
*/
public function i_click_away_from_student_and_grade_feedback($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 $itemname
* @param string $value
* @return Then
*/
public function the_grade_should_match($student, $itemname, $value) {
$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 "([^"]*)"$/
* @param string $student
* @param string $itemname
* @return Then
*/
public function i_should_see_grade_field($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 "([^"]*)"$/
* @param string $student
* @param string $itemname
* @return Then
*/
public function i_should_see_feedback_field($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 "([^"]*)"$/
* @param string $student
* @param string $itemname
* @return Then
*/
public function i_should_not_see_grade_field($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 "([^"]*)"$/
* @param string $student
* @param string $itemname
* @return Then
*/
public function i_should_not_see_feedback_field($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']";
}
}

View File

@ -27,8 +27,7 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode;
use Behat\Gherkin\Node\TableNode as TableNode;
class behat_grade extends behat_base {
@ -39,13 +38,12 @@ class behat_grade extends behat_base {
* @param int $grade
* @param string $userfullname the user's fullname as returned by fullname()
* @param string $itemname
* @return Given
*/
public function i_give_the_grade($grade, $userfullname, $itemname) {
$gradelabel = $userfullname . ' ' . $itemname;
$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 $userfullname the user's fullname as returned by fullname()
* @param string $itemname
* @return Given
*/
public function i_give_the_feedback($feedback, $userfullname, $itemname) {
$gradelabel = $userfullname . ' ' . $itemname;
$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>(?:[^"]|\\")*)":$/
* @param string $gradeitem
* @param TableNode $data
* @return Given[]
*/
public function i_set_the_following_settings_for_grade_item($gradeitem, TableNode $data) {
$steps = array();
$gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
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');
$edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('edit') . ' ');
$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);
$steps[] = new Given('I press "' . $this->escape($savechanges) . '"');
return $steps;
$this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
$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 $gradeitem The grade item name.
* @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) {
$steps = array();
$gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
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');
$edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('editcalculation', 'grades'));
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$steps[] = new Given('I click on "' . $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');
}
$this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
// Mapping names to idnumbers.
$datahash = $data->getRowsHash();
@ -139,20 +127,13 @@ class behat_grade extends behat_base {
" or " .
"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 $gradeitem The grade item name.
* @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) {
$steps = array();
$gradecategorytotal = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem . ' total');
$gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
@ -175,7 +154,7 @@ class behat_grade extends behat_base {
$xpath = "//tr[contains(.,$gradecategorytotal)]//*[contains(@class,'moodle-actionmenu')]" .
"//a[contains(@class,'toggle-display')]";
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');
$edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('editcalculation', 'grades'));
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$steps[] = new Given('I click on "' . $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');
$this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
// Mapping names to idnumbers.
$datahash = $data->getRowsHash();
@ -199,18 +175,13 @@ class behat_grade extends behat_base {
"parent::li[@class='categoryitem' | @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'));
// After adding id numbers we should wait until the page is reloaded.
$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;
$this->execute('behat_forms::i_set_the_field_to', array(get_string('calculation', 'grades'), $calculation));
$this->execute('behat_forms::press_button', $savechanges);
}
/**
@ -220,7 +191,6 @@ class behat_grade extends behat_base {
*
* @Given /^I reset weights for grade category "(?P<grade_item_string>(?:[^"]|\\")*)"$/
* @param $gradeitem
* @return array
*/
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);
$xpath = "//tr[contains(.,$gradeitemliteral)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
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));
$steps[] = new Given('I click on "' . $this->escape($linktext) . '" "link"');
return $steps;
$this->execute("behat_general::i_click_on", array($this->escape($linktext), "link"));
}
/**
@ -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>(?:[^"]|\\")*)"$/
* @param string $coursename
* @param string $version
* @return Given
*/
public function gradebook_calculations_for_the_course_are_frozen_at_version($coursename, $version) {
global $DB;

View File

@ -27,7 +27,6 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Then;
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>(?:[^"]|\\")*)"$/
* @param string $groups one or comma seperated list of groups.
* @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) {
$steps = array();
$groups = array_map('trim', explode(',', $groups));
foreach ($groups as $groupname) {
@ -108,9 +105,7 @@ class behat_groups extends behat_base {
$xpath = "//h3[normalize-space(.) = '{$grouping}']/following-sibling::table//tr//".
"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 . ') {
return "";
} else {
} else if (typeof M.util !== "undefined") {
return M.util.pending_js.join(":");
} else {
return "incomplete"
}
}();';
$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 .
' 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');
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;
/**

View File

@ -29,9 +29,6 @@ require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
require_once(__DIR__ . '/../../../lib/behat/behat_field_manager.php');
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\Mink\Exception\ExpectationException as ExpectationException,
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$/
*/
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()) {
// Press button in the specified select container.
@ -480,11 +476,10 @@ class behat_forms extends behat_base {
"or .//select[(./@name='" . $singleselect . "' or ./@id='". $singleselect . "')]" .
")]";
$actions[] = new Given('I click on "' . get_string('go') . '" "button" in the "' . $containerxpath .
'" "xpath_element"');
$this->execute('behat_general::i_click_on_in_the',
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,
WebDriver\Exception\NoSuchElement as NoSuchElement,
WebDriver\Exception\StaleElementReference as StaleElementReference,
Behat\Gherkin\Node\TableNode as TableNode,
Moodle\BehatExtension\Context\Step\Given as Given;
Behat\Gherkin\Node\TableNode as TableNode;
/**
* Cross component steps definitions.
@ -258,8 +257,9 @@ class behat_general extends behat_base {
*/
public function wait_until_the_page_is_ready() {
// No need to wait if not running JS.
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);

View File

@ -496,88 +496,12 @@ class behat_hooks extends behat_base {
* @see Moodle\BehatExtension\Tester\MoodleStepTester
*/
public function i_look_for_exceptions() {
// If the step already failed in a hook throw the exception.
if (!is_null(self::$currentstepexception)) {
throw self::$currentstepexception;
}
// 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.
}
$this->look_for_exceptions();
}
/**

View File

@ -27,8 +27,6 @@
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\DriverException as DriverException;
@ -147,23 +145,22 @@ class behat_navigation extends behat_base {
* @Given /^I follow "(?P<nodetext_string>(?:[^"]|\\")*)" in the user menu$/
*
* @param string $nodetext
* @return bool|void
*/
public function i_follow_in_the_user_menu($nodetext) {
$steps = array();
if ($this->running_javascript()) {
// The user menu must be expanded when JS is enabled.
$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.
// The CSS path is always present, with or without JS.
$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 ($nodetext === get_string('administrationsite')) {
// 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;
}
@ -413,6 +413,6 @@ class behat_navigation extends behat_base {
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');
use Behat\Mink\Exception\ExpectationException as ExpectationException,
Moodle\BehatExtension\Context\Step\Given as Given,
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:$/
* @param string $rolename
* @param TableNode $table
* @return void Executes other steps
*/
public function i_set_the_following_system_permissions_of_role($rolename, $table) {
$parentnodes = get_string('administrationsite') . ' > ' .
get_string('users', 'admin') . ' > ' .
get_string('permissions', 'role');
return array(
new Given('I am on homepage'),
new Given('I navigate to "' . get_string('defineroles', 'role') . '" node in "' . $parentnodes . '"'),
new Given('I follow "Edit ' . $this->escape($rolename) . ' role"'),
new Given('I fill the capabilities form with the following permissions:', $table),
new Given('I press "' . get_string('savechanges') . '"')
// 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('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:$/
* @param string $rolename
* @param TableNode $table
* @return void Executes other steps
*/
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.
$roleoption = $this->find('xpath', '//select[@name="roleid"]/option[contains(.,"' . $this->escape($rolename) . '")]');
$result = array(
new Given('I set the field "' . get_string('advancedoverride', 'role') .
'" to "' . $this->escape($roleoption->getText()) . '"'));
$this->execute('behat_forms::i_set_the_field_to',
array(get_string('advancedoverride', 'role'), $this->escape($roleoption->getText()))
);
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') . '"');
return $result;
$this->execute("behat_permissions::i_fill_the_capabilities_form_with_the_following_permissions", $table);
$this->execute('behat_forms::press_button', get_string('savechanges'));
}
/**
@ -192,13 +197,21 @@ class behat_permissions extends behat_base {
$parentnodes = get_string('administrationsite') . ' > ' .
get_string('users', 'admin') . ' > ' .
get_string('permissions', 'role');
return array(
new Given('I am on homepage'),
new Given('I navigate to "' . get_string('defineroles', 'role') . '" node in "' . $parentnodes . '"'),
new Given('I follow "Allow role assignments"'),
new Given('I fill in the allowed role assignments form for the "' . $rolename . '" role with:', $table),
new Given('I press "' . get_string('savechanges') . '"')
// 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('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');
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
/**
* Messaging system steps definitions.
@ -49,21 +48,27 @@ class behat_message extends behat_base {
*/
public function i_send_message_to_user($messagecontent, $userfullname) {
$steps = array();
$steps[] = new Given('I am on homepage');
if ($this->running_javascript()) {
$steps[] = new Given('I follow "' . get_string('messages', 'message') . '" in the user menu');
} else {
$steps[] = new Given('I follow "' . 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') . '"');
// Visit home page and follow messages.
$this->execute("behat_general::i_am_on_homepage");
return $steps;
if ($this->running_javascript()) {
$this->execute("behat_navigation::i_follow_in_the_user_menu", get_string('messages', 'message'));
} else {
$this->execute("behat_general::click_link", get_string('messages', 'message'));
}
$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');
use Moodle\BehatExtension\Context\Step\Given as Given;
/**
* Choice activity definitions.
*
@ -49,12 +47,11 @@ class behat_mod_choice extends behat_base {
*/
public function I_choose_option_from_activity($option, $choiceactivity) {
// Escaping again the strings as backslashes have been removed by the automatic transformation.
return array(
new Given('I follow "' . $this->escape($choiceactivity) . '"'),
new Given('I set the field "' . $this->escape($option) . '" to "1"'),
new Given('I press "' . get_string('savemychoice', 'choice') . '"')
);
$this->execute("behat_general::click_link", $this->escape($choiceactivity));
$this->execute('behat_forms::i_set_the_field_to', array( $this->escape($option), 1));
$this->execute("behat_forms::press_button", get_string('savemychoice', 'choice'));
}
/**

View File

@ -27,9 +27,7 @@
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given,
Moodle\BehatExtension\Context\Step\When as When,
Behat\Gherkin\Node\TableNode as TableNode;
use Behat\Gherkin\Node\TableNode as TableNode;
/**
* Database-related steps definitions.
*
@ -48,27 +46,22 @@ class behat_mod_data extends behat_base {
* @param string $fieldtype
* @param string $activityname
* @param TableNode $fielddata
* @return Given[]
*/
public function i_add_a_field_to_database_and_i_fill_the_form_with($fieldtype, $activityname, TableNode $fielddata) {
$steps = array(
new Given('I follow "' . $this->escape($activityname) . '"'),
new Given('I follow "' . get_string('fields', 'mod_data') . '"'),
new Given('I set the field "newtype" to "' . $this->escape($fieldtype) . '"')
);
$this->execute("behat_general::click_link", $this->escape($activityname));
$this->execute("behat_general::click_link", get_string('fields', 'mod_data'));
$this->execute('behat_forms::i_set_the_field_to', array('newtype', $this->escape($fieldtype)));
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(
$steps,
new Given('I set the following fields to these values:', $fielddata),
new Given('I press "' . get_string('add') . '"')
);
return $steps;
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $fielddata);
$this->execute('behat_forms::press_button', get_string('add'));
}
/**
@ -78,14 +71,12 @@ class behat_mod_data extends behat_base {
*
* @param string $activityname
* @param TableNode $entrydata
* @return When[]
*/
public function i_add_an_entry_to_database_with($activityname, TableNode $entrydata) {
return array(
new When('I follow "' . $this->escape($activityname) . '"'),
new When('I follow "' . get_string('add', 'mod_data') . '"'),
new When('I set the following fields to these values:', $entrydata),
);
$this->execute("behat_general::click_link", $this->escape($activityname));
$this->execute("behat_general::click_link", get_string('add', 'mod_data'));
$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');
use Behat\Behat\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode,
use Behat\Gherkin\Node\TableNode as TableNode,
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
*/
public function i_add_question_to_the_feedback_with($questiontype, TableNode $questiondata) {
$rv = array();
$questiontype = $this->escape($questiontype);
$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();
$modifiedrows = array();
@ -64,12 +64,10 @@ class behat_mod_feedback extends behat_base {
}
$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'));
$rv[] = new Given("I press \"{$saveitem}\"");
return $rv;
$this->execute("behat_forms::press_button", $saveitem);
}
/**
@ -84,14 +82,20 @@ class behat_mod_feedback extends behat_base {
$coursename = $this->escape($coursename);
$feedbackname = $this->escape($feedbackname);
$completeform = $this->escape(get_string('complete_the_form', 'feedback'));
return [
new Given("I log in as \"$username\""),
new Given("I follow \"$coursename\""),
new Given("I follow \"$feedbackname\""),
new Given("I follow \"$completeform\""),
new Given("I set the following fields to these values:", $answers),
new Given("I press \"Submit your answers\""),
new Given("I log out")
];
// Log in as user.
$this->execute('behat_auth::i_log_in_as', $username);
// Navigate to feedback complete form.
$this->execute('behat_general::click_link', $coursename);
$this->execute('behat_general::click_link', $feedbackname);
$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');
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode;
use Behat\Gherkin\Node\TableNode as TableNode;
/**
* Forum-related steps definitions.
*
@ -47,7 +46,7 @@ class behat_mod_forum extends behat_base {
* @param 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
*/
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) {
return array(
new Given('I follow "' . $this->escape($forumname) . '"'),
new Given('I follow "' . $this->escape($postsubject) . '"'),
new Given('I follow "' . 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')
);
// Navigate to forum.
$this->execute('behat_general::click_link', $this->escape($forumname));
$this->execute('behat_general::click_link', $this->escape($postsubject));
$this->execute('behat_general::click_link', get_string('reply', 'forum'));
// 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 TableNode $table
* @param string $buttonstr
* @return Given[]
*/
protected function add_new_discussion($forumname, TableNode $table, $buttonstr) {
// Escaping $forumname as it has been stripped automatically by the transformer.
return array(
new Given('I follow "' . $this->escape($forumname) . '"'),
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')
);
// Navigate to forum.
$this->execute('behat_general::click_link', $this->escape($forumname));
$this->execute('behat_forms::press_button', $buttonstr);
// 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');
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode;
use Behat\Gherkin\Node\TableNode as TableNode;
/**
* Glossary-related steps definitions.
@ -47,11 +46,11 @@ class behat_mod_glossary extends behat_base {
* @param TableNode $data
*/
public function i_add_a_glossary_entry_with_the_following_data(TableNode $data) {
return array(
new Given('I press "' . get_string('addentry', 'mod_glossary') . '"'),
new Given('I set the following fields to these values:', $data),
new Given('I press "' . get_string('savechanges') . '"')
);
$this->execute("behat_forms::press_button", get_string('addentry', 'mod_glossary'));
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
$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) {
return array(
new Given('I follow "' . get_string('categoryview', 'mod_glossary') . '"'),
new Given('I press "' . 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) . '"'),
new Given('I press "' . get_string('savechanges') . '"'),
new Given('I press "' . get_string('back', 'mod_glossary') . '"')
);
$this->execute("behat_general::click_link", get_string('categoryview', 'mod_glossary'));
$this->execute("behat_forms::press_button", get_string('editcategories', 'mod_glossary'));
$this->execute("behat_forms::press_button", get_string('add').' '.get_string('category', '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__ . '/../../../../question/tests/behat/behat_question_base.php');
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode;
use Behat\Gherkin\Node\TableNode as TableNode;
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'));
$menuxpath = "//div[contains(@class, ' page-add-actions ')][last()]//a[contains(@class, ' textmenu')]";
$itemxpath = "//div[contains(@class, ' page-add-actions ')][last()]//a[contains(@class, ' addquestion ')]";
return array_merge(array(
new Given("I follow \"$quizname\""),
new Given("I navigate to \"$editquiz\" node in \"$quizadmin\""),
new Given("I click on \"$menuxpath\" \"xpath_element\""),
new Given("I click on \"$itemxpath\" \"xpath_element\""),
), $this->finish_adding_question($questiontype, $questiondata));
$this->execute('behat_general::click_link', $quizname);
$this->execute("behat_navigation::i_navigate_to_node_in", array($editquiz, $quizadmin));
$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
*/
public function i_set_the_max_mark_for_quiz_question($questionname, $newmark) {
return array(
new Given('I follow "' . $this->escape(get_string('editmaxmark', 'quiz')) . '"'),
new Given('I wait until "li input[name=maxmark]" "css_element" exists'),
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::click_link', $this->escape(get_string('editmaxmark', 'quiz')));
$this->execute('behat_general::wait_until_exists', array("li input[name=maxmark]", "css_element"));
$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 {
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.
* @Given /^I follow "(?P<link_string>(?:[^"]|\\")*)" in the open menu$/
* @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) {
$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+)"$/
* @param string $questionname the name of the question we are looking for.
* @param number $pagenumber the page it should be found on.
* @return array of steps.
*/
public function i_should_see_on_quiz_page($questionname, $pagenumber) {
$xpath = "//li[contains(., '" . $this->escape($questionname) .
"')][./preceding-sibling::li[contains(@class, 'pagenumber')][1][contains(., 'Page " .
$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+)"$/
* @param string $questionname the name of the question we are looking for.
* @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) {
$xpath = "//li[contains(., '" . $this->escape($questionname) .
"')][./preceding-sibling::li[contains(@class, 'pagenumber')][1][contains(., 'Page " .
$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$/
* @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.
* @return array of steps.
*/
public function i_should_see_before_on_the_edit_quiz_page($firstquestionname, $secondquestionname) {
$xpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($firstquestionname) .
"')]/following-sibling::li[contains(@class, ' slot ')][1]" .
"[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$/
* @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.
* @return array of steps.
*/
public function should_have_number_on_the_edit_quiz_page($questionname, $number) {
$xpath = "//li[contains(@class, 'slot') and contains(., '" . $this->escape($questionname) .
"')]//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>(?:[^"]|\\")*)"$/
* @param string $addorremoves 'Add' or 'Remove'.
* @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) {
$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) {
$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) {
$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) {
$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
* @param strung $heading
* @param string $heading
* @return string
*/
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 $target the target place to move to. One of the links in the pop-up like
* "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) {
$iconxpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) .
"')]//span[contains(@class, 'editing_move')]";
return array(
new Given('I click on "' . $iconxpath . '" "xpath_element"'),
new Given('I click on "' . $this->escape($target) . '" "text"'),
);
$this->execute("behat_general::i_click_on", array($iconxpath, "xpath_element"));
$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$/
* @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"
* @return array of steps.
*/
public function i_move_question_after_item_by_dragging($questionname, $target) {
$iconxpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) .
"')]//span[contains(@class, 'editing_move')]//img";
$destinationxpath = "//li[contains(@class, ' slot ') or contains(@class, 'pagenumber ')]" .
"[contains(., '" . $this->escape($target) . "')]";
return array(
new Given('I drag "' . $iconxpath . '" "xpath_element" ' .
'and I drop it in "' . $destinationxpath . '" "xpath_element"'),
$this->execute('behat_general::i_drag_and_i_drop_it_in',
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) .
"')]";
$deletexpath = "//a[contains(@class, 'editing_delete')]";
return array(
new Given('I click on "' . $slotxpath . $deletexpath . '" "xpath_element"'),
new Given('I click on "Yes" "button" in the "Confirm" "dialogue"'),
$this->execute("behat_general::i_click_on", array($slotxpath . $deletexpath, "xpath_element"));
$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.
*/
public function i_set_the_section_heading_for($sectionname, $sectionheading) {
return array(
new Given('I follow "' . $this->escape("Edit heading '{$sectionname}'") . '"'),
new Given('I should see "' . $this->escape(get_string('edittitleinstructions')) . '"'),
new Given('I set the field "section" to "' . $this->escape($sectionheading) . chr(10) . '"'),
);
$this->execute('behat_general::click_link', $this->escape("Edit heading '{$sectionname}'"));
$this->execute('behat_general::assert_page_contains_text', $this->escape(get_string('edittitleinstructions')));
$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');
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode;
use Behat\Gherkin\Node\TableNode as TableNode;
/**
* 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)]]/".
"descendant-or-self::a[./img[@alt=$switchphase]]";
$continue = $this->escape(get_string('continue'));
return array(
new Given("I follow \"$workshopname\""),
new Given("I click on \"$xpath\" \"xpath_element\""),
new Given("I press \"$continue\""),
);
$this->execute('behat_general::click_link', $workshopname);
$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);
$savechanges = $this->escape(get_string('savechanges'));
$xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' ownsubmission ')]/descendant::input[@type='submit']";
return array(
new Given("I follow \"$workshopname\""),
new Given("I click on \"$xpath\" \"xpath_element\""),
new Given("I set the following fields to these values:", $table),
new Given("I press \"$savechanges\""),
);
$this->execute('behat_general::click_link', $workshopname);
$this->execute("behat_general::i_click_on", array($xpath, "xpath_element"));
$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);
$editassessmentform = $this->escape(get_string('editassessmentform', 'workshop'));
$saveandclose = $this->escape(get_string('saveandclose', 'workshop'));
return array(
new Given("I follow \"$workshopname\""),
new Given("I follow \"$editassessmentform\""),
new Given("I set the following fields to these values:", $table),
new Given("I press \"$saveandclose\""),
);
$this->execute('behat_general::click_link', $workshopname);
$this->execute('behat_general::click_link', $editassessmentform);
$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)]";
$assess = $this->escape(get_string('assess', 'workshop'));
$saveandclose = $this->escape(get_string('saveandclose', 'workshop'));
return array(
new Given("I follow \"$workshopname\""),
new Given("I click on \"$assess\" \"button\" in the \"$xpath\" \"xpath_element\""),
new Given("I set the following fields to these values:", $table),
new Given("I press \"$saveandclose\""),
$this->execute('behat_general::click_link', $workshopname);
$this->execute('behat_general::i_click_on_in_the',
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');
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode,
use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ExpectationException as ExpectationException,
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:$/
* @param string $questiontypename The question type name
* @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) {
return array_merge(array(
new Given('I follow "' . get_string('questionbank', 'question') . '"'),
new Given('I press "' . get_string('createnewquestion', 'question') . '"'),
), $this->finish_adding_question($questiontypename, $questiondata));
// Go to question bank.
$this->execute("behat_general::click_link", get_string('questionbank', 'question'));
// 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');
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode,
use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ExpectationException as ExpectationException,
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 TableNode $questiondata The data to fill the question type form
* @return Given[] the steps.
*/
protected function finish_adding_question($questiontypename, TableNode $questiondata) {
return array(
new Given('I set the field "' . $this->escape($questiontypename) . '" to "1"'),
new Given('I click on ".submitbutton" "css_element"'),
new Given('I set the following fields to these values:', $questiondata),
new Given('I press "id_submitbutton"')
);
$this->execute('behat_forms::i_set_the_field_to', array($this->escape($questiontypename), 1));
$this->execute("behat_general::i_click_on", array('.submitbutton', "css_element"));
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $questiondata);
$this->execute("behat_forms::press_button", 'id_submitbutton');
}
}