From e88d47b4a2c19b698f7d0f1e764fa9ad04d45e6a Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 11 Mar 2013 10:00:33 +0800 Subject: [PATCH 1/2] MDL-38352 behat: Removing extra double quotes escape --- lib/testing/classes/nasty_strings.php | 2 +- lib/tests/behat/behat_transformations.php | 21 +++------------------ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/lib/testing/classes/nasty_strings.php b/lib/testing/classes/nasty_strings.php index 95026d7b0f2..826a8ed287d 100644 --- a/lib/testing/classes/nasty_strings.php +++ b/lib/testing/classes/nasty_strings.php @@ -56,7 +56,7 @@ class nasty_strings { '\' \\" \ \'$@NULL@$ @@TEST@@ < > & < > & \\\" \\ , ; : . 日本語­% %%', '\\\" \\ , ; : . 日本語­% < > & < > & \' \\" \ \'$@NULL@$ @@TEST@@ %%', '< > & < > & \' \\" \ \'$@NULL@$ 日本語­% %% @@TEST@@ \\\" \\ . , ; :', - '. 日本語& \' \\"< > & < > \\\" \\ , ; : \ \'$@NULL@$ @@TEST@@­% %%', + '. 日本語& \' \\" < > & < > \\ , ; : \ \'$@NULL@$ \\\" @@TEST@@­% %%', '& \' \\" \ < > & < > \\\" \\ , ; : . 日本語\'$@NULL@$ @@TEST@@­% %%', ); diff --git a/lib/tests/behat/behat_transformations.php b/lib/tests/behat/behat_transformations.php index c684c8a7504..a5591c8af33 100644 --- a/lib/tests/behat/behat_transformations.php +++ b/lib/tests/behat/behat_transformations.php @@ -56,7 +56,7 @@ class behat_transformations extends behat_base { * @return string The string with the arguments fixed. */ public function arg_replace_slashes($string) { - return $this->replace_slashes($string); + return str_replace('\"', '"', $string); } /** @@ -73,8 +73,8 @@ class behat_transformations extends behat_base { /** * Transformations for TableNode arguments. * - * All the transformations have to be applied to tables, - * adding them in a different method for Behat API restrictions. + * Transformations applicable to TableNode arguments should also + * be applied, adding them in a different method for Behat API restrictions. * * @Transform /^table:(.*)/ * @param TableNode $tablenode @@ -87,9 +87,6 @@ class behat_transformations extends behat_base { foreach ($rows as $rowkey => $row) { foreach ($row as $colkey => $value) { - // TableNodes values doesn't need to be escaped, but maybe somebody does it. - $rows[$rowkey][$colkey] = $this->replace_slashes($value); - // Transforms vars into nasty strings. if (preg_match('/\$NASTYSTRING(\d)/', $rows[$rowkey][$colkey])) { $rows[$rowkey][$colkey] = $this->replace_nasty_strings($rows[$rowkey][$colkey]); @@ -102,18 +99,6 @@ class behat_transformations extends behat_base { return $tablenode; } - /** - * Removes the escaped double quotes. - * - * Method reused by TableNode transformation. - * - * @param string $string - * @return string - */ - public function replace_slashes($string) { - return str_replace('\"', '"', $string); - } - /** * Replaces $NASTYSTRING vars for a nasty string. * From 37652a9cb99ce4535f91e88af6533fb6d84a3687 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 11 Mar 2013 10:03:55 +0800 Subject: [PATCH 2/2] MDL-38352 behat: Updating tests According to non-escaped double quotes in TableNodes. Also refactoring previous test affected by the issue. --- .../behat/tests/behat/nasty_strings.feature | 2 +- .../behat/restrict_available_blocks.feature | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/admin/tool/behat/tests/behat/nasty_strings.feature b/admin/tool/behat/tests/behat/nasty_strings.feature index 913579863fb..550386f1101 100644 --- a/admin/tool/behat/tests/behat/nasty_strings.feature +++ b/admin/tool/behat/tests/behat/nasty_strings.feature @@ -43,7 +43,7 @@ Feature: Transform steps arguments And I follow "Edit profile" Then I should not see "NASTYSTRING" And the "First name" field should match "va\"lue1" value - And the "Description" field should match "va\"lue2" value + And the "Description" field should match "va\\"lue2" value And the "City/town" field should match "va\"lue3" value @javascript diff --git a/blocks/tests/behat/restrict_available_blocks.feature b/blocks/tests/behat/restrict_available_blocks.feature index 29590aa2907..00cf8de40ae 100644 --- a/blocks/tests/behat/restrict_available_blocks.feature +++ b/blocks/tests/behat/restrict_available_blocks.feature @@ -4,8 +4,7 @@ Feature: Allowed blocks controls As an admin I need to restrict some blocks to be used in courses - @javascript - Scenario: Blocks can be added with the default permissions + Background: Given the following "users" exists: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@asd.com | @@ -15,7 +14,10 @@ Feature: Allowed blocks controls And the following "course enrolments" exists: | user | course | role | | teacher1 | C1 | editingteacher | - And I log in as "teacher1" + + @javascript + Scenario: Blocks can be added with the default permissions + Given I log in as "teacher1" And I follow "Course $NASTYSTRING1" And I turn editing mode on When I add the "Course completion status" block @@ -25,16 +27,7 @@ Feature: Allowed blocks controls @javascript Scenario: Blocks can not be added when the admin restricts the permissions - Given the following "users" exists: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@asd.com | - And the following "courses" exists: - | fullname | shortname | category | - | Course $NASTYSTRING1 | C1 | 0 | - And the following "course enrolments" exists: - | user | course | role | - | teacher1 | C1 | editingteacher | - And I log in as "admin" + Given I log in as "admin" And I set the following system permissions of "Teacher" role: | block/activity_modules:addinstance | Prohibit | And I am on homepage