mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT: simpleXML() now catches the error if you try to call it on anything other then xml. MINOR: added test to RESTFul Service
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@80340 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
3edc596bdb
commit
bfce550b30
@ -318,7 +318,14 @@ class RestfulService_Response extends HTTPResponse {
|
||||
}
|
||||
|
||||
function simpleXML() {
|
||||
if(!$this->simpleXML) $this->simpleXML = new SimpleXMLElement($this->body);
|
||||
if(!$this->simpleXML) {
|
||||
try {
|
||||
$this->simpleXML = new SimpleXMLElement($this->body);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
user_error("String could not be parsed as XML. " . $e, E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
return $this->simpleXML;
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,14 @@ class RestfulServiceTest extends SapphireTest {
|
||||
$this->assertContains("<post_item name=\"$key\">$value</post_item>", $test1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error
|
||||
*/
|
||||
function testIncorrectData() {
|
||||
$connection = new RestfulService(Director::absoluteBaseURL(), 0);
|
||||
$test1 = $connection->request('RestfulServiceTest_Controller/invalid?usetestmanifest=1&flush=1');
|
||||
$test1->xpath("\\fail");
|
||||
}
|
||||
}
|
||||
|
||||
class RestfulServiceTest_Controller extends Controller {
|
||||
@ -87,6 +95,19 @@ XML;
|
||||
header('Content-type: text/xml');
|
||||
echo $out;
|
||||
}
|
||||
|
||||
public function invalid() {
|
||||
ContentNegotiator::disable();
|
||||
BasicAuth::disable();
|
||||
$out = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<test>
|
||||
<fail><invalid>
|
||||
</test>
|
||||
XML;
|
||||
header('Content-type: text/xml');
|
||||
echo $out;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user