From 0a7f6a02eb5c2b343184f82ef24b0dd88a17a291 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Wed, 6 Mar 2013 13:34:09 +0800 Subject: [PATCH] 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@@­% %%', ); /**