Permalink
Browse files

Fixes #763

 * `assertTag()` fails to match content in CDATA sections.
  • Loading branch information...
whatthejeff committed Mar 11, 2013
1 parent 82335c2 commit 2c67e52445416bb7c14046b432acd7eb79e4e612
Showing with 26 additions and 2 deletions.
  1. +2 −1 PHPUnit/Util/XML.php
  2. +23 −0 Tests/Framework/AssertTest.php
  3. +1 −1 Tests/_files/SelectorAssertionsFixture.html
View
@@ -907,7 +907,8 @@ protected static function getNodeText(DOMNode $node)
$result = '';
foreach ($node->childNodes as $childNode) {
- if ($childNode->nodeType === XML_TEXT_NODE) {
+ if ($childNode->nodeType === XML_TEXT_NODE ||
+ $childNode->nodeType === XML_CDATA_SECTION_NODE) {
$result .= trim($childNode->data) . ' ';
} else {
$result .= self::getNodeText($childNode);
@@ -2835,6 +2835,29 @@ public function testAssertTagRegexpContentFalse()
$this->assertTag($matcher, $this->html);
}
+ /**
+ * @covers PHPUnit_Framework_Assert::assertTag
+ */
+ public function testAssertTagCdataContentTrue()
+ {
+ $matcher = array('tag' => 'script',
+ 'content' => 'alert(\'Hello, world!\');');
+ $this->assertTag($matcher, $this->html);
+ }
+
+ /**
+ * @covers PHPUnit_Framework_Assert::assertTag
+ * @expectedException PHPUnit_Framework_AssertionFailedError
+ */
+ public function testAssertTagCdataontentFalse()
+ {
+ $matcher = array('tag' => 'script',
+ 'content' => 'asdf');
+ $this->assertTag($matcher, $this->html);
+ }
+
+
+
/**
* @covers PHPUnit_Framework_Assert::assertTag
*/
@@ -4,7 +4,7 @@
<head>
<title>Login</title>
<link type="text/css" rel="Stylesheet" href="/stylesheets/screen.css">
- <script type="text/javaScript" src="/javascripts/login.js">
+ <script type="text/javascript">alert('Hello, world!');</script>
</head>
<body id="login">
<ul id="my_ul" class="my_ul_class">

0 comments on commit 2c67e52

Please sign in to comment.