Created
October 20, 2009 19:09
-
-
Save kriswallsmith/214520 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Validates the response. | |
* | |
* @return sfTestFunctionalBase|sfTester | |
*/ | |
public function isValid() | |
{ | |
if (preg_match('/(x|ht)ml/i', $this->response->getContentType(), $matches)) | |
{ | |
$revert = libxml_use_internal_errors(true); | |
$dom = new DOMDocument('1.0', $this->response->getCharset()); | |
if ($dom->loadXML($this->response->getContent())) | |
{ | |
$this->tester->pass(sprintf('response validates as "%s"', $dom->doctype->name ? $dom->doctype->name : 'xml')); | |
} | |
else | |
{ | |
$this->tester->fail(sprintf('response validates as "%s"', $dom->doctype->name ? $dom->doctype->name : 'xml')); | |
foreach (libxml_get_errors() as $error) | |
{ | |
$this->tester->diag(' '.trim($error->message)); | |
} | |
} | |
libxml_use_internal_errors($revert); | |
} | |
else | |
{ | |
throw new LogicException(sprintf('Unable to validate responses of content type "%s"', $this->response->getContentType())); | |
} | |
return $this->getObjectToReturn(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment