Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 865d8e1

Browse files
committed
fix 504 by adding document type 'dom'
which is an already loaded instance
1 parent f97605a commit 865d8e1

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

library/Zend/Dom/Query.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ public function setDocumentDom(DOMDocument $document)
154154
{
155155
$this->_document = $document;
156156
$this->_docType = self::DOC_DOM;
157+
if (null !== $document->encoding) {
158+
$this->setEncoding($document->encoding);
159+
}
157160
return $this;
158161
}
159162

@@ -211,7 +214,7 @@ public function setDocumentXml($document, $encoding = null)
211214
/**
212215
* Retrieve current document
213216
*
214-
* @return string
217+
* @return string|DOMDocument
215218
*/
216219
public function getDocument()
217220
{
@@ -276,6 +279,7 @@ public function queryXpath($xpathQuery, $query = null)
276279
switch ($type) {
277280
case self::DOC_DOM:
278281
$domDoc = $this->_document;
282+
$success = true;
279283
break;
280284
case self::DOC_XML:
281285
try {

tests/Zend/Dom/QueryTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public function testDocumentTypeShouldBeAutomaticallyDiscovered()
143143
$this->assertEquals(Zend_Dom_Query::DOC_XML, $this->query->getDocumentType());
144144
$this->query->setDocument('<html><body></body></html>');
145145
$this->assertEquals(Zend_Dom_Query::DOC_HTML, $this->query->getDocumentType());
146+
$this->query->setDocument(new DOMDocument());
147+
$this->assertEquals(Zend_Dom_Query::DOC_DOM, $this->query->getDocumentType());
146148
}
147149

148150
public function testQueryingWithoutRegisteringDocumentShouldThrowException()
@@ -229,6 +231,18 @@ public function testQueryXpathShouldAllowQueryingArbitraryUsingXpath()
229231
$this->assertEquals(2, count($result), $result->getXpathQuery());
230232
}
231233

234+
public function testQueryOnDomDocument()
235+
{
236+
$document = new DOMDocument('1.0', 'utf-8');
237+
$document->loadHTML($this->getHtml(), LIBXML_PARSEHUGE);
238+
$this->query->setDocument($document);
239+
$test = $this->query->query('.foo');
240+
$this->assertTrue($test instanceof Zend_Dom_Query_Result);
241+
$testDocument = $test->getDocument();
242+
$this->assertTrue($testDocument instanceof DOMDocument);
243+
$this->assertEquals('utf-8', $testDocument->encoding);
244+
}
245+
232246
/**
233247
* @group ZF-9243
234248
*/

tests/phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
</testsuite>
55

66
<!-- Enable this for proper unit testing code coverage reports
7+
-->
78
<filter>
89
<whitelist>
910
<directory suffix=".php">../library/Zend</directory>
1011
</whitelist>
1112
</filter>
12-
-->
1313
</phpunit>

0 commit comments

Comments
 (0)