File tree Expand file tree Collapse file tree 2 files changed +58
-3
lines changed
tests/unit/Codeception/Module Expand file tree Collapse file tree 2 files changed +58
-3
lines changed Original file line number Diff line number Diff line change @@ -283,6 +283,46 @@ public function seeSoapResponseContainsStructure($xml) {
283283
284284 }
285285
286+ /**
287+ * Checks XML response with XPath locator
288+ *
289+ * ``` php
290+ * <?php
291+ * $I->seeSoapResponseContainsXPath('//root/user[@id=1]');
292+ * ?>
293+ * ```
294+ *
295+ * @param $xpath
296+ */
297+ public function seeSoapResponseContainsXPath ($ xpath )
298+ {
299+ $ path = new \DOMXPath ($ this ->xmlResponse );
300+ $ res = $ path ->query ($ xpath );
301+ if ($ res === false ) $ this ->fail ("XPath selector is malformed " );
302+ $ this ->assertGreaterThen (0 , $ res ->length );
303+ }
304+
305+ /**
306+ * Checks XML response doesn't contain XPath locator
307+ *
308+ * ``` php
309+ * <?php
310+ * $I->dontSeeSoapResponseContainsXPath('//root/user[@id=1]');
311+ * ?>
312+ * ```
313+ *
314+ * @param $xpath
315+ */
316+ public function dontSeeSoapResponseContainsXPath ($ xpath )
317+ {
318+ $ path = new \DOMXPath ($ this ->xmlResponse );
319+ $ res = $ path ->query ($ xpath );
320+ if ($ res === false ) $ this ->fail ("XPath selector is malformed " );
321+ $ this ->assertEquals (0 , $ res ->length );
322+ }
323+
324+
325+
286326 /**
287327 * Checks response code from server.
288328 *
Original file line number Diff line number Diff line change @@ -77,7 +77,24 @@ public function testSeeXmlIncludes() {
7777 $ dom ->loadXML ('<?xml version="1.0" encoding="UTF-8"?> <doc> <a a2="2" a1="1" >123</a> </doc> ' );
7878 $ this ->module ->seeSoapResponseIncludes ('<a a2="2" a1="1" >123</a> ' );
7979 }
80-
80+
81+ public function testSeeXmlContainsXPath () {
82+ $ dom = new DOMDocument ();
83+ $ this ->module ->xmlResponse = $ dom ;
84+ $ dom ->preserveWhiteSpace = false ;
85+ $ dom ->loadXML ('<?xml version="1.0" encoding="UTF-8"?> <doc> <a a2="2" a1="1" >123</a> </doc> ' );
86+ $ this ->module ->seeSoapResponseContainsXPath ('//doc/a[@a2=2 and @a1=1] ' );
87+ }
88+
89+ public function testSeeXmlNotContainsXPath () {
90+ $ dom = new DOMDocument ();
91+ $ this ->module ->xmlResponse = $ dom ;
92+ $ dom ->preserveWhiteSpace = false ;
93+ $ dom ->loadXML ('<?xml version="1.0" encoding="UTF-8"?> <doc> <a a2="2" a1="1" >123</a> </doc> ' );
94+ $ this ->module ->dontSeeSoapResponseContainsXPath ('//doc/a[@a2=2 and @a31] ' );
95+ }
96+
97+
8198 public function testSeeXmlEquals () {
8299 $ dom = new DOMDocument ();
83100 $ this ->module ->xmlResponse = $ dom ;
@@ -106,8 +123,6 @@ public function testGrabTextFrom() {
106123 $ this ->assertEquals ('123 ' , $ res );
107124 $ res = $ this ->module ->grabTextContentFrom ('descendant-or-self::doc/descendant::node ' );
108125 $ this ->assertEquals ('123 ' , $ res );
109-
110-
111126 }
112127
113128}
You can’t perform that action at this time.
0 commit comments