From 0a7f6a02eb5c2b343184f82ef24b0dd88a17a291 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Wed, 6 Mar 2013 13:34:09 +0800 Subject: [PATCH 1/2] MDL-37958 behat: Nasty strings in HTML Nasty strings includes html entities and non-breaking spaces followed by spaces which makes very hard to find these strings in the DOM html, this patch keeps the non-breaking spaces and all the nasty characters, but leaves them isolated from other regular spaces. It swaps the strings to HTML before finding elements in the HTML that matches that contents. --- lib/behat/behat_base.php | 6 ++++++ lib/testing/classes/nasty_strings.php | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/behat/behat_base.php b/lib/behat/behat_base.php index e3527205456..532086b084b 100644 --- a/lib/behat/behat_base.php +++ b/lib/behat/behat_base.php @@ -102,6 +102,12 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext { if ($selector == 'named') { $exceptiontype = $locator[0]; $exceptionlocator = $locator[1]; + + // If we are in a @javascript session all contents would be displayed as HTML characters. + if (get_class($this->getSession()->getDriver()) === 'Behat\Mink\Driver\Selenium2Driver') { + $locator[1] = html_entity_decode($locator[1], ENT_NOQUOTES); + } + } else { $exceptiontype = $selector; $exceptionlocator = $locator; diff --git a/lib/testing/classes/nasty_strings.php b/lib/testing/classes/nasty_strings.php index e200263ad9d..95026d7b0f2 100644 --- a/lib/testing/classes/nasty_strings.php +++ b/lib/testing/classes/nasty_strings.php @@ -48,16 +48,16 @@ class nasty_strings { * @var array */ protected static $strings = array( - '< > & < > & \' \\" \ \'$@NULL@$ @@TEST@@ \\\" \\ , ; : .  日本語 ­ % %% ', - '& \' \\" \ \'$@NULL@$ < > & < > @@TEST@@ \\\" \\ , ; : .  日本語 ­ % %% ', - '< > & < > & \' \\" \ \\\" \\ , ; : .  \'$@NULL@$ @@TEST@@ 日本語 ­ % %% ', - '< > & < > & \' \\" \ \'$@NULL@$ 日本語 ­ % %%@@TEST@@ \\\" \\ , ; : .  ', - '< > & < > \\\" \\ , ; : .  日本語& \' \\" \ \'$@NULL@$ @@TEST@@ ­ % %% ', - '\' \\" \ \'$@NULL@$ @@TEST@@ < > & < > & \\\" \\ , ; : .  日本語 ­ % %% ', - '\\\" \\ , ; : .  日本語 ­ % < > & < > & \' \\" \ \'$@NULL@$ @@TEST@@ %% ', - '< > & < > & \' \\" \ \'$@NULL@$ 日本語 ­ % %% @@TEST@@ \\\" \\ , ; : .  ', - '.  日本語& \' \\"< > & < > \\\" \\ , ; : \ \'$@NULL@$ @@TEST@@ ­ % %% ', - '& \' \\" \ < > & < > \\\" \\ , ; : .  日本語\'$@NULL@$ @@TEST@@ ­ % %% ', + '< > & < > & \' \\" \ \'$@NULL@$ @@TEST@@ \\\" \\ , ; : . 日本語­% %%', + '& \' \\" \ \'$@NULL@$ < > & < > @@TEST@@ \\\" \\ , ; : . 日本語­% %%', + '< > & < > & \' \\" \ \\\" \\ , ; : . \'$@NULL@$ @@TEST@@ 日本語­% %%', + '< > & < > & \' \\" \ \'$@NULL@$ 日本語­% %%@@TEST@@ \. \\" \\ , ; :', + '< > & < > \\\" \\ , ; : . 日本語& \' \\" \ \'$@NULL@$ @@TEST@@­% %%', + '\' \\" \ \'$@NULL@$ @@TEST@@ < > & < > & \\\" \\ , ; : . 日本語­% %%', + '\\\" \\ , ; : . 日本語­% < > & < > & \' \\" \ \'$@NULL@$ @@TEST@@ %%', + '< > & < > & \' \\" \ \'$@NULL@$ 日本語­% %% @@TEST@@ \\\" \\ . , ; :', + '. 日本語& \' \\"< > & < > \\\" \\ , ; : \ \'$@NULL@$ @@TEST@@­% %%', + '& \' \\" \ < > & < > \\\" \\ , ; : . 日本語\'$@NULL@$ @@TEST@@­% %%', ); /** From e8a88ebbd86b895d0e30a21215cda2495432fd2e Mon Sep 17 00:00:00 2001 From: David Monllao Date: Wed, 6 Mar 2013 15:47:34 +0800 Subject: [PATCH 2/2] MDL-37958 behat: Avoid problems with Background cached steps --- .../behat/restrict_available_blocks.feature | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/blocks/tests/behat/restrict_available_blocks.feature b/blocks/tests/behat/restrict_available_blocks.feature index 00cf8de40ae..29590aa2907 100644 --- a/blocks/tests/behat/restrict_available_blocks.feature +++ b/blocks/tests/behat/restrict_available_blocks.feature @@ -4,7 +4,8 @@ Feature: Allowed blocks controls As an admin I need to restrict some blocks to be used in courses - Background: + @javascript + Scenario: Blocks can be added with the default permissions Given the following "users" exists: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@asd.com | @@ -14,10 +15,7 @@ Feature: Allowed blocks controls And the following "course enrolments" exists: | user | course | role | | teacher1 | C1 | editingteacher | - - @javascript - Scenario: Blocks can be added with the default permissions - Given I log in as "teacher1" + And I log in as "teacher1" And I follow "Course $NASTYSTRING1" And I turn editing mode on When I add the "Course completion status" block @@ -27,7 +25,16 @@ Feature: Allowed blocks controls @javascript Scenario: Blocks can not be added when the admin restricts the permissions - Given I log in as "admin" + 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" And I set the following system permissions of "Teacher" role: | block/activity_modules:addinstance | Prohibit | And I am on homepage