From decf1e14c8bcb4aa6b55511b7e4daa37c83145d0 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Fri, 31 Jan 2014 18:50:15 +0800 Subject: [PATCH] MDL-43738 behat: More info about how to get/set fields --- admin/tool/behat/lang/en/tool_behat.php | 2 ++ admin/tool/behat/renderer.php | 27 +++++++++++++++++++++++++ lib/tests/behat/behat_forms.php | 8 ++++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/admin/tool/behat/lang/en/tool_behat.php b/admin/tool/behat/lang/en/tool_behat.php index b07e92f69c6..88a1ef73270 100644 --- a/admin/tool/behat/lang/en/tool_behat.php +++ b/admin/tool/behat/lang/en/tool_behat.php @@ -29,6 +29,8 @@ $string['errorcomposer'] = 'Composer dependencies are not installed.'; $string['errordataroot'] = '$CFG->behat_dataroot is not set or is invalid.'; $string['errorsetconfig'] = '$CFG->behat_dataroot, $CFG->behat_prefix and $CFG->behat_wwwroot need to be set in config.php.'; $string['erroruniqueconfig'] = '$CFG->behat_dataroot, $CFG->behat_prefix and $CFG->behat_wwwroot values need to be different than $CFG->dataroot, $CFG->prefix, $CFG->wwwroot, $CFG->phpunit_dataroot and $CFG->phpunit_prefix values.'; +$string['fieldvalueargument'] = 'Field value arguments'; +$string['fieldvalueargument_help'] = 'This argument should be completed by a field value, there are many field types, simple ones like checkboxes, selects or textareas or complex ones like date selectors. You can check Field values to see the expected field value depending on the field type you provide.'; $string['giveninfo'] = 'Given. Processes to set up the environment'; $string['infoheading'] = 'Info'; $string['installinfo'] = 'Read {$a} for installation and tests execution info'; diff --git a/admin/tool/behat/renderer.php b/admin/tool/behat/renderer.php index cc5b4ab9dde..0454436d39a 100644 --- a/admin/tool/behat/renderer.php +++ b/admin/tool/behat/renderer.php @@ -84,6 +84,33 @@ class tool_behat_renderer extends plugin_renderer_base { $stepsdefinitions ); + $stepsdefinitions = preg_replace_callback('/(FIELD_VALUE_STRING)/', + function ($matches) { + global $CFG; + + // Creating a link to a popup with the help. + $url = new moodle_url( + '/help.php', + array( + 'component' => 'tool_behat', + 'identifier' => 'fieldvalueargument', + 'lang' => current_language() + ) + ); + + // Note: this title is displayed only if JS is disabled, + // otherwise the link will have the new ajax tooltip. + $title = get_string('fieldvalueargument', 'tool_behat'); + $title = get_string('helpprefix2', '', trim($title, ". \t")); + + $attributes = array('href' => $url, 'title' => $title, + 'aria-haspopup' => 'true', 'target' => '_blank'); + + $output = html_writer::tag('a', 'FIELD_VALUE_STRING', $attributes); + return html_writer::tag('span', $output, array('class' => 'helptooltip')); + }, + $stepsdefinitions + ); } // Steps definitions. diff --git a/lib/tests/behat/behat_forms.php b/lib/tests/behat/behat_forms.php index 4934b2bd8ff..ab39bc553f7 100644 --- a/lib/tests/behat/behat_forms.php +++ b/lib/tests/behat/behat_forms.php @@ -148,7 +148,7 @@ class behat_forms extends behat_base { /** * Sets the specified value to the field. * - * @Given /^I set the field "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)"$/ + * @Given /^I set the field "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)"$/ * @throws ElementNotFoundException Thrown by behat_base::find * @param string $field * @param string $value @@ -161,7 +161,7 @@ class behat_forms extends behat_base { /** * Checks, the field matches the value. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps. * - * @Then /^the field "(?P(?:[^"]|\\")*)" matches value "(?P(?:[^"]|\\")*)"$/ + * @Then /^the field "(?P(?:[^"]|\\")*)" matches value "(?P(?:[^"]|\\")*)"$/ * @throws ElementNotFoundException Thrown by behat_base::find * @param string $field * @param string $value @@ -187,7 +187,7 @@ class behat_forms extends behat_base { /** * 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(?:[^"]|\\")*)" does not match value "(?P(?:[^"]|\\")*)"$/ + * @Then /^the field "(?P(?:[^"]|\\")*)" does not match value "(?P(?:[^"]|\\")*)"$/ * @throws ExpectationException * @throws ElementNotFoundException Thrown by behat_base::find * @param string $field @@ -232,7 +232,7 @@ class behat_forms extends behat_base { } /** - * Checks that fields values do not match the provided values. Provide a table with field/value data. + * Checks that the provided field/value pairs don't match. More info in http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps. * * @Then /^the following fields do not match these values:$/ * @throws ExpectationException -- 2.43.0