@@ -255,8 +255,8 @@ public function dontSeeSoapResponseIncludes($xml)
255255 * ```
256256 *
257257 * Use this method to check XML of valid structure is returned.
258- * This method doesn't use schema for validation.
259- * This method dosn't require whole response XML to match the structure.
258+ * This method does not use schema for validation.
259+ * This method does not require path from root to match the structure.
260260 *
261261 * @param $xml
262262 */
@@ -285,9 +285,57 @@ public function seeSoapResponseContainsStructure($xml) {
285285 * @param $code
286286 */
287287 public function seeResponseCodeIs ($ code ) {
288- \PHPUnit_Framework_Assert::assertEquals ($ code , $ this ->client ->getResponse ()->getStatusCode (), "soap response code matches expected " );
288+ \PHPUnit_Framework_Assert::assertEquals ($ code , $ this ->client ->getResponse ()->getStatus (), "soap response code matches expected " );
289289 }
290290
291+ /**
292+ * Finds and returns text contents of element.
293+ * Element is matched by either CSS or XPath
294+ *
295+ * @version 1.1
296+ * @param $cssOrXPath
297+ * @return string
298+ */
299+ public function grabTextFrom ($ cssOrXPath ) {
300+ $ el = $ this ->matchElement ($ cssOrXPath );
301+ return $ el ->textContent ;
302+ }
303+
304+ /**
305+ * Finds and returns attribute of element.
306+ * Element is matched by either CSS or XPath
307+ *
308+ * @version 1.1
309+ * @param $cssOrXPath
310+ * @param $attribute
311+ * @return string
312+ */
313+ public function grabAttributeFrom ($ cssOrXPath , $ attribute ) {
314+ $ el = $ this ->matchElement ($ cssOrXPath );
315+ if (!$ el ->hasAttribute ($ attribute )) $ this ->fail ("Attribute not found in element matched by ' $ cssOrXPath' " );
316+ return $ el ->getAttribute ($ attribute );
317+ }
318+
319+ /**
320+ * @param $cssOrXPath
321+ * @return \DOMElement
322+ */
323+ protected function matchElement ($ cssOrXPath )
324+ {
325+ $ xpath = new \DOMXpath ($ this ->xmlResponse );
326+ try {
327+ $ selector = \Symfony \Component \CssSelector \CssSelector::toXPath ($ cssOrXPath );
328+ $ els = $ xpath ->query ($ selector );
329+ if ($ els ) return $ els ->item (0 );
330+ } catch (\Symfony \Component \CssSelector \Exception \ParseException $ e ) {}
331+ $ els = $ xpath ->query ($ cssOrXPath );
332+ if ($ els ) {
333+ return $ els ->item (0 );
334+ }
335+ $ this ->fail ("No node matched CSS or XPath ' $ cssOrXPath' " );
336+ }
337+
338+
291339 protected function structureMatches ($ schema , $ xml )
292340 {
293341 foreach ($ schema ->childNodes as $ node1 ) {
0 commit comments