Skip to content

Commit

Permalink
MDL-37958 behat: Nasty strings in HTML
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
David Monllao committed Mar 6, 2013
1 parent c629c91 commit 0a7f6a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 6 additions & 0 deletions lib/behat/behat_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ protected function find_all($selector, $locator, $exception = false, $node = fal
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;
Expand Down
20 changes: 10 additions & 10 deletions lib/testing/classes/nasty_strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ class nasty_strings {
* @var array
*/
protected static $strings = array(
'< > & &lt; &gt; &amp; \' \\" \ \'$@NULL@$ @@TEST@@ \\\" \\ , ; : .  日本語 ­ % %% ',
'&amp; \' \\" \ \'$@NULL@$ < > & &lt; &gt; @@TEST@@ \\\" \\ , ; : .  日本語 ­ % %% ',
'< > & &lt; &gt; &amp; \' \\" \ \\\" \\ , ; : .  \'$@NULL@$ @@TEST@@ 日本語 ­ % %% ',
'< > & &lt; &gt; &amp; \' \\" \ \'$@NULL@$ 日本語 ­ % %%@@TEST@@ \\\" \\ , ; :',
'< > & &lt; &gt; \\\" \\ , ; : .  日本語&amp; \' \\" \ \'$@NULL@$ @@TEST@@ ­ % %% ',
'\' \\" \ \'$@NULL@$ @@TEST@@ < > & &lt; &gt; &amp; \\\" \\ , ; : .  日本語 ­ % %% ',
'\\\" \\ , ; : .  日本語 ­ % < > & &lt; &gt; &amp; \' \\" \ \'$@NULL@$ @@TEST@@ %% ',
'< > & &lt; &gt; &amp; \' \\" \ \'$@NULL@$ 日本語 ­ % %% @@TEST@@ \\\" \\ , ; :',
' 日本語&amp; \' \\"< > & &lt; &gt; \\\" \\ , ; : \ \'$@NULL@$ @@TEST@@ ­ % %% ',
'&amp; \' \\" \ < > & &lt; &gt; \\\" \\ , ; : .  日本語\'$@NULL@$ @@TEST@@ ­ % %% ',
'< > & &lt; &gt; &amp; \' \\" \ \'$@NULL@$ @@TEST@@ \\\" \\ , ; : . 日本語­% %%',
'&amp; \' \\" \ \'$@NULL@$ < > & &lt; &gt; @@TEST@@ \\\" \\ , ; : . 日本語­% %%',
'< > & &lt; &gt; &amp; \' \\" \ \\\" \\ , ; : . \'$@NULL@$ @@TEST@@ 日本語­% %%',
'< > & &lt; &gt; &amp; \' \\" \ \'$@NULL@$ 日本語­% %%@@TEST@@ \\\" \\ , ; :',
'< > & &lt; &gt; \\\" \\ , ; : . 日本語&amp; \' \\" \ \'$@NULL@$ @@TEST@@­% %%',
'\' \\" \ \'$@NULL@$ @@TEST@@ < > & &lt; &gt; &amp; \\\" \\ , ; : . 日本語­% %%',
'\\\" \\ , ; : . 日本語­% < > & &lt; &gt; &amp; \' \\" \ \'$@NULL@$ @@TEST@@ %%',
'< > & &lt; &gt; &amp; \' \\" \ \'$@NULL@$ 日本語­% %% @@TEST@@ \\\" \\ , ; :',
'. 日本語&amp; \' \\"< > & &lt; &gt; \\\" \\ , ; : \ \'$@NULL@$ @@TEST@@­% %%',
'&amp; \' \\" \ < > & &lt; &gt; \\\" \\ , ; : . 日本語\'$@NULL@$ @@TEST@@­% %%',
);

/**
Expand Down

0 comments on commit 0a7f6a0

Please sign in to comment.