This repository was archived by the owner on Oct 2, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,9 @@ public function setDocumentDom(DOMDocument $document)
154
154
{
155
155
$ this ->_document = $ document ;
156
156
$ this ->_docType = self ::DOC_DOM ;
157
+ if (null !== $ document ->encoding ) {
158
+ $ this ->setEncoding ($ document ->encoding );
159
+ }
157
160
return $ this ;
158
161
}
159
162
@@ -211,7 +214,7 @@ public function setDocumentXml($document, $encoding = null)
211
214
/**
212
215
* Retrieve current document
213
216
*
214
- * @return string
217
+ * @return string|DOMDocument
215
218
*/
216
219
public function getDocument ()
217
220
{
@@ -276,6 +279,7 @@ public function queryXpath($xpathQuery, $query = null)
276
279
switch ($ type ) {
277
280
case self ::DOC_DOM :
278
281
$ domDoc = $ this ->_document ;
282
+ $ success = true ;
279
283
break ;
280
284
case self ::DOC_XML :
281
285
try {
Original file line number Diff line number Diff line change @@ -143,6 +143,8 @@ public function testDocumentTypeShouldBeAutomaticallyDiscovered()
143
143
$ this ->assertEquals (Zend_Dom_Query::DOC_XML , $ this ->query ->getDocumentType ());
144
144
$ this ->query ->setDocument ('<html><body></body></html> ' );
145
145
$ 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 ());
146
148
}
147
149
148
150
public function testQueryingWithoutRegisteringDocumentShouldThrowException ()
@@ -229,6 +231,18 @@ public function testQueryXpathShouldAllowQueryingArbitraryUsingXpath()
229
231
$ this ->assertEquals (2 , count ($ result ), $ result ->getXpathQuery ());
230
232
}
231
233
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
+
232
246
/**
233
247
* @group ZF-9243
234
248
*/
Original file line number Diff line number Diff line change 4
4
</testsuite >
5
5
6
6
<!-- Enable this for proper unit testing code coverage reports
7
+ -->
7
8
<filter >
8
9
<whitelist >
9
10
<directory suffix =" .php" >../library/Zend</directory >
10
11
</whitelist >
11
12
</filter >
12
- -->
13
13
</phpunit >
You can’t perform that action at this time.
0 commit comments