mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-43738 behat: Updating steps definitions and deprecating methods
This commit is contained in:
parent
c3f1e9532d
commit
a525414125
10 changed files with 254 additions and 118 deletions
|
@ -1,6 +1,8 @@
|
||||||
This files describes API changes in the assign code.
|
This files describes API changes in the tool_behat code.
|
||||||
|
|
||||||
=== 2.7 ===
|
=== 2.7 ===
|
||||||
|
* Constants behat_base::cap_allow, behat_base::cap_prevent and
|
||||||
|
behat_base::cap_prohibit have been removed in favour of the
|
||||||
|
lang/en/role.php language strings 'allow', 'prevent' and 'prohibit'.
|
||||||
* @_only_local tag used in .feature files replaced by @_file_upload tag
|
* @_only_local tag used in .feature files replaced by @_file_upload tag
|
||||||
* @_alerts tag used in .feature files replaced by @_alert tag
|
* @_alerts tag used in .feature files replaced by @_alert tag
|
||||||
|
|
|
@ -41,4 +41,5 @@ require_once(__DIR__ . '/behat_form_group.php');
|
||||||
* @copyright 2013 David Monllaó
|
* @copyright 2013 David Monllaó
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class behat_form_date_selector extends behat_form_group {}
|
class behat_form_date_selector extends behat_form_group {
|
||||||
|
}
|
||||||
|
|
|
@ -38,4 +38,5 @@ require_once(__DIR__ . '/behat_form_date_selector.php');
|
||||||
* @copyright 2013 David Monllaó
|
* @copyright 2013 David Monllaó
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class behat_form_date_time_selector extends behat_form_date_selector {}
|
class behat_form_date_time_selector extends behat_form_date_selector {
|
||||||
|
}
|
||||||
|
|
|
@ -38,4 +38,5 @@ require_once(__DIR__ . '/behat_form_field.php');
|
||||||
* @copyright 2014 David Monllaó
|
* @copyright 2014 David Monllaó
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class behat_form_group extends behat_form_field {}
|
class behat_form_group extends behat_form_field {
|
||||||
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ class behat_form_select extends behat_form_field {
|
||||||
// Single select sometimes needs an extra click in the option.
|
// Single select sometimes needs an extra click in the option.
|
||||||
if (!$multiple) {
|
if (!$multiple) {
|
||||||
|
|
||||||
// $options only contains 1 option.
|
// Var $options only contains 1 option.
|
||||||
$optionxpath = $this->get_option_xpath(end($options), $selectxpath);
|
$optionxpath = $this->get_option_xpath(end($options), $selectxpath);
|
||||||
|
|
||||||
// Using the driver direcly because Element methods are messy when dealing
|
// Using the driver direcly because Element methods are messy when dealing
|
||||||
|
@ -297,14 +297,14 @@ class behat_form_select extends behat_form_field {
|
||||||
// If the select is multiple, text commas must be encoded.
|
// If the select is multiple, text commas must be encoded.
|
||||||
$selectedoptions[] = trim(str_replace(',', '\,', $option->{$method}()));
|
$selectedoptions[] = trim(str_replace(',', '\,', $option->{$method}()));
|
||||||
} else {
|
} else {
|
||||||
$selectedoptions[] = trim($option->{$method}());
|
$selectedoptions[] = trim($option->{$method}());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Goutte does not keep the 'selected' attribute updated, but its getValue() returns
|
|
||||||
// the selected elements correctly, also those having commas within them.
|
|
||||||
} else {
|
} else {
|
||||||
|
// Goutte does not keep the 'selected' attribute updated, but its getValue() returns
|
||||||
|
// the selected elements correctly, also those having commas within them.
|
||||||
|
|
||||||
// Goutte returns the values as an array or as a string depending
|
// Goutte returns the values as an array or as a string depending
|
||||||
// on whether multiple options are selected or not.
|
// on whether multiple options are selected or not.
|
||||||
|
@ -322,7 +322,7 @@ class behat_form_select extends behat_form_field {
|
||||||
// If the select is multiple, text commas must be encoded.
|
// If the select is multiple, text commas must be encoded.
|
||||||
$selectedoptions[] = trim(str_replace(',', '\,', $option->{$method}()));
|
$selectedoptions[] = trim(str_replace(',', '\,', $option->{$method}()));
|
||||||
} else {
|
} else {
|
||||||
$selectedoptions[] = trim($option->{$method}());
|
$selectedoptions[] = trim($option->{$method}());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,10 +50,6 @@ use Behat\Behat\Exception\PendingException as PendingException;
|
||||||
*/
|
*/
|
||||||
class behat_data_generators extends behat_base {
|
class behat_data_generators extends behat_base {
|
||||||
|
|
||||||
const cap_allow = 'Allow';
|
|
||||||
const cap_prevent = 'Prevent';
|
|
||||||
const cap_prohibit = 'Prohibit';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var testing_data_generator
|
* @var testing_data_generator
|
||||||
*/
|
*/
|
||||||
|
@ -303,13 +299,13 @@ class behat_data_generators extends behat_base {
|
||||||
$context = $this->get_context($data['contextlevel'], $data['reference']);
|
$context = $this->get_context($data['contextlevel'], $data['reference']);
|
||||||
|
|
||||||
switch ($data['permission']) {
|
switch ($data['permission']) {
|
||||||
case self::cap_allow:
|
case get_string('allow', 'role'):
|
||||||
$permission = CAP_ALLOW;
|
$permission = CAP_ALLOW;
|
||||||
break;
|
break;
|
||||||
case self::cap_prevent:
|
case get_string('prevent', 'role'):
|
||||||
$permission = CAP_PREVENT;
|
$permission = CAP_PREVENT;
|
||||||
break;
|
break;
|
||||||
case self::cap_prohibit:
|
case get_string('prohibit', 'role'):
|
||||||
$permission = CAP_PROHIBIT;
|
$permission = CAP_PROHIBIT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -28,7 +28,8 @@
|
||||||
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
|
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
|
||||||
|
|
||||||
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
|
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
|
||||||
Behat\Behat\Context\Step\Given as Given;
|
Behat\Behat\Context\Step\Given as Given,
|
||||||
|
Behat\Behat\Context\Step\Then as Then;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deprecated behat step definitions.
|
* Deprecated behat step definitions.
|
||||||
|
@ -302,6 +303,170 @@ class behat_deprecated extends behat_base {
|
||||||
return new Given($alternative);
|
return new Given($alternative);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills in form text field with specified id|name|label|value. It works with text-based fields.
|
||||||
|
*
|
||||||
|
* @deprecated since 2.7
|
||||||
|
* @todo MDL-42862 This will be deleted in Moodle 2.9
|
||||||
|
* @see behat_forms::i_set_the_field_to()
|
||||||
|
*
|
||||||
|
* @When /^I fill in "(?P<field_string>(?:[^"]|\\")*)" with "(?P<value_string>(?:[^"]|\\")*)"$/
|
||||||
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||||
|
* @param string $field
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function fill_field($field, $value) {
|
||||||
|
$alternative = 'I set the field "' . $this->escape($field) . '" to "' . $this->escape($value) . '"';
|
||||||
|
$this->deprecated_message($alternative);
|
||||||
|
|
||||||
|
return new Given($alternative);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects option in select field with specified id|name|label|value.
|
||||||
|
*
|
||||||
|
* @deprecated since 2.7
|
||||||
|
* @todo MDL-42862 This will be deleted in Moodle 2.9
|
||||||
|
* @see behat_forms::i_set_the_field_to()
|
||||||
|
*
|
||||||
|
* @When /^I select "(?P<option_string>(?:[^"]|\\")*)" from "(?P<select_string>(?:[^"]|\\")*)"$/
|
||||||
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||||
|
* @param string $option
|
||||||
|
* @param string $select
|
||||||
|
*/
|
||||||
|
public function select_option($option, $select) {
|
||||||
|
$alternative = 'I set the field "' . $this->escape($select) . '" to "' . $this->escape($option) . '"';
|
||||||
|
$this->deprecated_message($alternative);
|
||||||
|
|
||||||
|
return new Given($alternative);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects the specified id|name|label from the specified radio button.
|
||||||
|
*
|
||||||
|
* @deprecated since 2.7
|
||||||
|
* @todo MDL-42862 This will be deleted in Moodle 2.9
|
||||||
|
* @see behat_forms::i_set_the_field_to()
|
||||||
|
*
|
||||||
|
* @When /^I select "(?P<radio_button_string>(?:[^"]|\\")*)" radio button$/
|
||||||
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||||
|
* @param string $radio The radio button id, name or label value
|
||||||
|
*/
|
||||||
|
public function select_radio($radio) {
|
||||||
|
$alternative = 'I set the field "' . $this->escape($radio) . '" to "1"';
|
||||||
|
$this->deprecated_message($alternative);
|
||||||
|
|
||||||
|
return new Given($alternative);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks checkbox with specified id|name|label|value.
|
||||||
|
*
|
||||||
|
* @deprecated since 2.7
|
||||||
|
* @todo MDL-42862 This will be deleted in Moodle 2.9
|
||||||
|
* @see behat_forms::i_set_the_field_to()
|
||||||
|
*
|
||||||
|
* @When /^I check "(?P<option_string>(?:[^"]|\\")*)"$/
|
||||||
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||||
|
* @param string $option
|
||||||
|
*/
|
||||||
|
public function check_option($option) {
|
||||||
|
$alternative = 'I set the field "' . $this->escape($option) . '" to "1"';
|
||||||
|
$this->deprecated_message($alternative);
|
||||||
|
|
||||||
|
return new Given($alternative);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unchecks checkbox with specified id|name|label|value.
|
||||||
|
*
|
||||||
|
* @deprecated since 2.7
|
||||||
|
* @todo MDL-42862 This will be deleted in Moodle 2.9
|
||||||
|
* @see behat_forms::i_set_the_field_to()
|
||||||
|
*
|
||||||
|
* @When /^I uncheck "(?P<option_string>(?:[^"]|\\")*)"$/
|
||||||
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||||
|
* @param string $option
|
||||||
|
*/
|
||||||
|
public function uncheck_option($option) {
|
||||||
|
$alternative = 'I set the field "' . $this->escape($option) . '" to ""';
|
||||||
|
$this->deprecated_message($alternative);
|
||||||
|
|
||||||
|
return new Given($alternative);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the field matches the specified value. When using multi-select fields use commas to separate selected options.
|
||||||
|
*
|
||||||
|
* @deprecated since 2.7
|
||||||
|
* @todo MDL-42862 This will be deleted in Moodle 2.9
|
||||||
|
* @see behat_forms::the_field_matches_value()
|
||||||
|
*
|
||||||
|
* @Then /^the "(?P<field_string>(?:[^"]|\\")*)" field should match "(?P<value_string>(?:[^"]|\\")*)" value$/
|
||||||
|
* @throws ExpectationException
|
||||||
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||||
|
* @param string $locator
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function the_field_should_match_value($locator, $value) {
|
||||||
|
$alternative = 'the field "' . $this->escape($locator) . '" matches value "' . $this->escape($value) . '"';
|
||||||
|
$this->deprecated_message($alternative);
|
||||||
|
|
||||||
|
return new Then($alternative);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks, that checkbox with specified in|name|label|value is checked.
|
||||||
|
*
|
||||||
|
* @deprecated since 2.7
|
||||||
|
* @todo MDL-42862 This will be deleted in Moodle 2.9
|
||||||
|
* @see behat_forms::the_field_matches_value()
|
||||||
|
*
|
||||||
|
* @Then /^the "(?P<checkbox_string>(?:[^"]|\\")*)" checkbox should be checked$/
|
||||||
|
* @param string $checkbox
|
||||||
|
*/
|
||||||
|
public function assert_checkbox_checked($checkbox) {
|
||||||
|
$alternative = 'the field "' . $this->escape($checkbox) . '" matches value "1"';
|
||||||
|
$this->deprecated_message($alternative);
|
||||||
|
|
||||||
|
return new Then($alternative);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks, that checkbox with specified in|name|label|value is unchecked.
|
||||||
|
*
|
||||||
|
* @deprecated since 2.7
|
||||||
|
* @todo MDL-42862 This will be deleted in Moodle 2.9
|
||||||
|
* @see behat_forms::the_field_matches_value()
|
||||||
|
*
|
||||||
|
* @Then /^the "(?P<checkbox_string>(?:[^"]|\\")*)" checkbox should not be checked$/
|
||||||
|
* @param string $checkbox
|
||||||
|
*/
|
||||||
|
public function assert_checkbox_not_checked($checkbox) {
|
||||||
|
$alternative = 'the field "' . $this->escape($checkbox) . '" matches value ""';
|
||||||
|
$this->deprecated_message($alternative);
|
||||||
|
|
||||||
|
return new Then($alternative);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills a moodle form with field/value data.
|
||||||
|
*
|
||||||
|
* @deprecated since 2.7
|
||||||
|
* @todo MDL-42862 This will be deleted in Moodle 2.9
|
||||||
|
* @see behat_forms::i_set_the_following_fields_to_these_values()
|
||||||
|
*
|
||||||
|
* @Given /^I fill the moodle form with:$/
|
||||||
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||||
|
* @param TableNode $data
|
||||||
|
*/
|
||||||
|
public function i_fill_the_moodle_form_with(TableNode $data) {
|
||||||
|
$alternative = 'I set the following fields to these values:';
|
||||||
|
$this->deprecated_message($alternative);
|
||||||
|
|
||||||
|
return new Given($alternative, $data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws an exception if $CFG->behat_usedeprecated is not allowed.
|
* Throws an exception if $CFG->behat_usedeprecated is not allowed.
|
||||||
*
|
*
|
||||||
|
|
|
@ -61,13 +61,13 @@ class behat_forms extends behat_base {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills a moodle form with field/value data.
|
* Fills a form with field/value data. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps.
|
||||||
*
|
*
|
||||||
* @Given /^I fill the moodle form with:$/
|
* @Given /^I set the following fields to these values:$/
|
||||||
* @throws ElementNotFoundException Thrown by behat_base::find
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||||
* @param TableNode $data
|
* @param TableNode $data
|
||||||
*/
|
*/
|
||||||
public function i_fill_the_moodle_form_with(TableNode $data) {
|
public function i_set_the_following_fields_to_these_values(TableNode $data) {
|
||||||
|
|
||||||
// Expand all fields in case we have.
|
// Expand all fields in case we have.
|
||||||
$this->expand_all_fields();
|
$this->expand_all_fields();
|
||||||
|
@ -76,15 +76,7 @@ class behat_forms extends behat_base {
|
||||||
|
|
||||||
// The action depends on the field type.
|
// The action depends on the field type.
|
||||||
foreach ($datahash as $locator => $value) {
|
foreach ($datahash as $locator => $value) {
|
||||||
|
$this->set_field_value($locator, $value);
|
||||||
// Getting the node element pointed by the label.
|
|
||||||
$fieldnode = $this->find_field($locator);
|
|
||||||
|
|
||||||
// Gets the field type from a parent node.
|
|
||||||
$field = behat_field_manager::get_form_field($fieldnode, $this->getSession());
|
|
||||||
|
|
||||||
// Delegates to the field class.
|
|
||||||
$field->set_value($value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,90 +146,46 @@ class behat_forms extends behat_base {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills in form text field with specified id|name|label|value. It works with text-based fields.
|
* Sets the specified value to the field.
|
||||||
*
|
*
|
||||||
* @When /^I fill in "(?P<field_string>(?:[^"]|\\")*)" with "(?P<value_string>(?:[^"]|\\")*)"$/
|
* @Given /^I set the field "(?P<field_string>(?:[^"]|\\")*)" to "(?P<value_string>(?:[^"]|\\")*)"$/
|
||||||
* @throws ElementNotFoundException Thrown by behat_base::find
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function fill_field($field, $value) {
|
public function i_set_the_field_to($field, $value) {
|
||||||
$this->set_field_value($field, $value);
|
$this->set_field_value($field, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects option in select field with specified id|name|label|value.
|
* Checks, the field matches the value. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps.
|
||||||
*
|
*
|
||||||
* @When /^I select "(?P<option_string>(?:[^"]|\\")*)" from "(?P<select_string>(?:[^"]|\\")*)"$/
|
* @Then /^the field "(?P<field_string>(?:[^"]|\\")*)" matches value "(?P<value_string>(?:[^"]|\\")*)"$/
|
||||||
* @throws ElementNotFoundException Thrown by behat_base::find
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
||||||
* @param string $option
|
* @param string $field
|
||||||
* @param string $select
|
|
||||||
*/
|
|
||||||
public function select_option($option, $select) {
|
|
||||||
$this->set_field_value($select, $option);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Selects the specified id|name|label from the specified radio button.
|
|
||||||
*
|
|
||||||
* @When /^I select "(?P<radio_button_string>(?:[^"]|\\")*)" radio button$/
|
|
||||||
* @throws ElementNotFoundException Thrown by behat_base::find
|
|
||||||
* @param string $radio The radio button id, name or label value
|
|
||||||
*/
|
|
||||||
public function select_radio($radio) {
|
|
||||||
$this->set_field_value($radio, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks checkbox with specified id|name|label|value.
|
|
||||||
*
|
|
||||||
* @When /^I check "(?P<option_string>(?:[^"]|\\")*)"$/
|
|
||||||
* @throws ElementNotFoundException Thrown by behat_base::find
|
|
||||||
* @param string $option
|
|
||||||
*/
|
|
||||||
public function check_option($option) {
|
|
||||||
$this->set_field_value($option, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unchecks checkbox with specified id|name|label|value.
|
|
||||||
*
|
|
||||||
* @When /^I uncheck "(?P<option_string>(?:[^"]|\\")*)"$/
|
|
||||||
* @throws ElementNotFoundException Thrown by behat_base::find
|
|
||||||
* @param string $option
|
|
||||||
*/
|
|
||||||
public function uncheck_option($option) {
|
|
||||||
$this->set_field_value($option, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks that the form element field matches the specified value. When using multi-select fields use commas to separate the selected options.
|
|
||||||
*
|
|
||||||
* @Then /^the "(?P<field_string>(?:[^"]|\\")*)" field should match "(?P<value_string>(?:[^"]|\\")*)" value$/
|
|
||||||
* @throws ExpectationException
|
|
||||||
* @throws ElementNotFoundException Thrown by behat_base::find
|
|
||||||
* @param string $locator
|
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function the_field_should_match_value($locator, $value) {
|
public function the_field_matches_value($field, $value) {
|
||||||
|
|
||||||
$fieldnode = $this->find_field($locator);
|
$fieldnode = $this->find_field($field);
|
||||||
|
|
||||||
// Get the field.
|
// Get the field.
|
||||||
$field = behat_field_manager::get_form_field($fieldnode, $this->getSession());
|
$formfield = behat_field_manager::get_form_field($fieldnode, $this->getSession());
|
||||||
|
|
||||||
// Checks if the provided value matches the current field value.
|
// Checks if the provided value matches the current field value.
|
||||||
if (!$field->matches($value)) {
|
if (!$formfield->matches($value)) {
|
||||||
$fieldvalue = $field->get_value();
|
$fieldvalue = $formfield->get_value();
|
||||||
throw new ExpectationException(
|
throw new ExpectationException(
|
||||||
'The \'' . $locator . '\' value is \'' . $fieldvalue . '\', \'' . $value . '\' expected' ,
|
'The \'' . $field . '\' value is \'' . $fieldvalue . '\', \'' . $value . '\' expected' ,
|
||||||
$this->getSession()
|
$this->getSession()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that the form element field does not match the specified value.
|
* Checks, the field does not match the value. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps.
|
||||||
*
|
*
|
||||||
* @Then /^the field "(?P<field_string>(?:[^"]|\\")*)" does not match value "(?P<value_string>(?:[^"]|\\")*)"$/
|
* @Then /^the field "(?P<field_string>(?:[^"]|\\")*)" does not match value "(?P<value_string>(?:[^"]|\\")*)"$/
|
||||||
* @throws ExpectationException
|
* @throws ExpectationException
|
||||||
|
@ -251,11 +199,11 @@ class behat_forms extends behat_base {
|
||||||
$fieldnode = $this->find_field($field);
|
$fieldnode = $this->find_field($field);
|
||||||
|
|
||||||
// Get the field.
|
// Get the field.
|
||||||
$field = behat_field_manager::get_form_field($fieldnode, $this->getSession());
|
$formfield = behat_field_manager::get_form_field($fieldnode, $this->getSession());
|
||||||
|
|
||||||
// Checks if the provided value matches the current field value.
|
// Checks if the provided value matches the current field value.
|
||||||
if ($field->matches($value)) {
|
if ($formfield->matches($value)) {
|
||||||
$fieldvalue = $field->get_value();
|
$fieldvalue = $formfield->get_value();
|
||||||
throw new ExpectationException(
|
throw new ExpectationException(
|
||||||
'The \'' . $field . '\' value matches \'' . $value . '\' and it should not match it' ,
|
'The \'' . $field . '\' value matches \'' . $value . '\' and it should not match it' ,
|
||||||
$this->getSession()
|
$this->getSession()
|
||||||
|
@ -264,11 +212,11 @@ class behat_forms extends behat_base {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if fields values matches the provided values. Provide a table with field/value data.
|
* Checks, the provided field/value matches. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps.
|
||||||
*
|
*
|
||||||
* @Then /^the following fields match these values:$/
|
* @Then /^the following fields match these values:$/
|
||||||
* @throws ExpectationException
|
* @throws ExpectationException
|
||||||
* @param TableNode $table Pairs of | field | value |
|
* @param TableNode $data Pairs of | field | value |
|
||||||
*/
|
*/
|
||||||
public function the_following_fields_match_these_values(TableNode $data) {
|
public function the_following_fields_match_these_values(TableNode $data) {
|
||||||
|
|
||||||
|
@ -279,7 +227,7 @@ class behat_forms extends behat_base {
|
||||||
|
|
||||||
// The action depends on the field type.
|
// The action depends on the field type.
|
||||||
foreach ($datahash as $locator => $value) {
|
foreach ($datahash as $locator => $value) {
|
||||||
$this->the_field_should_match_value($locator, $value);
|
$this->the_field_matches_value($locator, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +236,7 @@ class behat_forms extends behat_base {
|
||||||
*
|
*
|
||||||
* @Then /^the following fields do not match these values:$/
|
* @Then /^the following fields do not match these values:$/
|
||||||
* @throws ExpectationException
|
* @throws ExpectationException
|
||||||
* @param TableNode $table Pairs of | field | value |
|
* @param TableNode $data Pairs of | field | value |
|
||||||
*/
|
*/
|
||||||
public function the_following_fields_do_not_match_these_values(TableNode $data) {
|
public function the_following_fields_do_not_match_these_values(TableNode $data) {
|
||||||
|
|
||||||
|
@ -303,26 +251,6 @@ class behat_forms extends behat_base {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks, that checkbox with specified in|name|label|value is checked.
|
|
||||||
*
|
|
||||||
* @Then /^the "(?P<checkbox_string>(?:[^"]|\\")*)" checkbox should be checked$/
|
|
||||||
* @param string $checkbox
|
|
||||||
*/
|
|
||||||
public function assert_checkbox_checked($checkbox) {
|
|
||||||
$this->the_field_should_match_value($checkbox, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks, that checkbox with specified in|name|label|value is unchecked.
|
|
||||||
*
|
|
||||||
* @Then /^the "(?P<checkbox_string>(?:[^"]|\\")*)" checkbox should not be checked$/
|
|
||||||
* @param string $checkbox
|
|
||||||
*/
|
|
||||||
public function assert_checkbox_not_checked($checkbox) {
|
|
||||||
$this->the_field_should_match_value($checkbox, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks, that given select box contains the specified option.
|
* Checks, that given select box contains the specified option.
|
||||||
*
|
*
|
||||||
|
|
|
@ -76,7 +76,8 @@ class behat_permissions extends behat_base {
|
||||||
$roleoption = $this->find('xpath', '//select[@name="roleid"]/option[contains(.,"' . $this->escape($rolename) . '")]');
|
$roleoption = $this->find('xpath', '//select[@name="roleid"]/option[contains(.,"' . $this->escape($rolename) . '")]');
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
new Given('I select "' . $this->escape($roleoption->getText()) . '" from "' . get_string('advancedoverride', 'role') . '"'),
|
new Given('I set the field "' . get_string('advancedoverride', 'role') .
|
||||||
|
'" to "' . $this->escape($roleoption->getText()) . '"'),
|
||||||
new Given('I fill the capabilities form with the following permissions:', $table),
|
new Given('I fill the capabilities form with the following permissions:', $table),
|
||||||
new Given('I press "' . get_string('savechanges') . '"')
|
new Given('I press "' . get_string('savechanges') . '"')
|
||||||
);
|
);
|
||||||
|
@ -142,4 +143,44 @@ class behat_permissions extends behat_base {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the capability has the specified permission. Works in the role definition advanced page.
|
||||||
|
*
|
||||||
|
* @Then /^"(?P<capability_string>(?:[^"]|\\")*)" capability has "(?P<permission_string>Not set|Allow|Prevent|Prohibit)" permission$/
|
||||||
|
* @throws ExpectationException
|
||||||
|
* @param string $capabilityname
|
||||||
|
* @param string $permission
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function capability_has_permission($capabilityname, $permission) {
|
||||||
|
|
||||||
|
// We already know the name, so we just need the value.
|
||||||
|
$radioxpath = "//table[@class='rolecap']/descendant::input[@type='radio']" .
|
||||||
|
"[@name='" . $capabilityname . "'][@checked]";
|
||||||
|
|
||||||
|
$checkedradio = $this->find('xpath', $radioxpath);
|
||||||
|
|
||||||
|
switch ($permission) {
|
||||||
|
case get_string('notset', 'role'):
|
||||||
|
$perm = CAP_INHERIT;
|
||||||
|
break;
|
||||||
|
case get_string('allow', 'role'):
|
||||||
|
$perm = CAP_ALLOW;
|
||||||
|
break;
|
||||||
|
case get_string('prevent', 'role'):
|
||||||
|
$perm = CAP_PREVENT;
|
||||||
|
break;
|
||||||
|
case get_string('prohibit', 'role'):
|
||||||
|
$perm = CAP_PROHIBIT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ExpectationException('"' . $permission . '" permission does not exist', $this->getSession());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($checkedradio->getAttribute('value') != $perm) {
|
||||||
|
throw new ExpectationException('"' . $capabilityname . '" permission is not "' . $permission . '"', $this->getSession());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,8 @@ class behat_message extends behat_base {
|
||||||
}
|
}
|
||||||
|
|
||||||
$steps[] = new Given('I follow "' . get_string('messages', 'message') . '"');
|
$steps[] = new Given('I follow "' . get_string('messages', 'message') . '"');
|
||||||
$steps[] = new Given('I fill in "' . get_string('searchcombined', 'message') . '" with "' . $this->escape($userfullname) . '"');
|
$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 press "' . get_string('searchcombined', 'message') . '"');
|
||||||
$steps[] = new Given('I follow "' . $this->escape(get_string('sendmessageto', 'message', $userfullname)) . '"');
|
$steps[] = new Given('I follow "' . $this->escape(get_string('sendmessageto', 'message', $userfullname)) . '"');
|
||||||
$steps[] = new Given('I fill in "id_message" with "' . $this->escape($messagecontent) . '"');
|
$steps[] = new Given('I fill in "id_message" with "' . $this->escape($messagecontent) . '"');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue