This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Added fix and unit test for queryContentRegexAssertion() method - #33
Closed
RalfEggert wants to merge 2 commits into
Closed
Added fix and unit test for queryContentRegexAssertion() method#33RalfEggert wants to merge 2 commits into
RalfEggert wants to merge 2 commits into
Conversation
…did not check all matches
| $nodeValues[] = $node->nodeValue; | ||
| } | ||
|
|
||
| if (!preg_match($pattern, implode('', $nodeValues))) { |
Member
There was a problem hiding this comment.
The concern I have with this approach is that the regex might match across content boundaries.
As an example, consider this markup:
<div>foo</div>
<div>bar</div>and then the following assertion:
$this->assertQueryContentRegex('div', '/foobar/');The above, with the change you suggest here, would be a false positive.
I'd suggest doing the regex in the loop itself:
$found = false;
foreach ($result as $node) {
if (preg_match($pattern, $node->nodeValue)) {
$found = true;
break;
}
}
if (! $found) {
throw new PHPUnit_Framework_ExpectationFailedException(/* ... */);
}
$this->assertTrue($found);This approach will resolve the issue you reported in #32, while ensuring we
don't get false positives due to boundary issues.
Contributor
Author
|
I added another test case to handle unexpected false positives and added for solution. I had to tweak it a little otherwise the exception message had to actual content to output. I hope that tweak is ok. |
weierophinney
added a commit
that referenced
this pull request
Sep 6, 2016
Member
|
Thanks, @RalfEggert! Cherry-picked to master, for release with 3.0.2. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Solves issue for #32.