Skip to content

Instantly share code, notes, and snippets.

@kriswallsmith
Created October 20, 2009 19:09
Show Gist options
  • Save kriswallsmith/214520 to your computer and use it in GitHub Desktop.
Save kriswallsmith/214520 to your computer and use it in GitHub Desktop.
<?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