From 1b1809f1a28f8e8842d53fdf25fbdc54abd3b8f9 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Thu, 2 Jul 2009 07:18:18 +0000 Subject: [PATCH] Merged from branches/2.3 git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@80873 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- api/RestfulService.php | 9 ++++++++- forms/Form.php | 4 +++- templates/Image_iframe.ss | 1 + tests/api/RestfulServiceTest.php | 23 ++++++++++++++++++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/api/RestfulService.php b/api/RestfulService.php index b64d8584e..ffeee986d 100644 --- a/api/RestfulService.php +++ b/api/RestfulService.php @@ -325,7 +325,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; } diff --git a/forms/Form.php b/forms/Form.php index 6d0c7d1ed..e3a23cb57 100755 --- a/forms/Form.php +++ b/forms/Form.php @@ -279,7 +279,9 @@ class Form extends RequestHandler { // Otherwise, try a handler method on the form object } else { - return $this->$funcName($vars, $this, $request); + if($this->hasMethod($funcName)) { + return $this->$funcName($vars, $this, $request); + } } } diff --git a/templates/Image_iframe.ss b/templates/Image_iframe.ss index 50b2d2a6b..d509dae1b 100755 --- a/templates/Image_iframe.ss +++ b/templates/Image_iframe.ss @@ -3,6 +3,7 @@ <% base_tag %> <% _t('TITLE', 'Image Uploading Iframe') %> + diff --git a/tests/api/RestfulServiceTest.php b/tests/api/RestfulServiceTest.php index b38ec5089..638acf997 100644 --- a/tests/api/RestfulServiceTest.php +++ b/tests/api/RestfulServiceTest.php @@ -82,6 +82,14 @@ class RestfulServiceTest extends SapphireTest { $this->assertContains("second run", $responseBody); } + /** + * @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 { @@ -115,6 +123,19 @@ XML; return $this->response; } + + public function invalid() { + ContentNegotiator::disable(); + BasicAuth::disable(); + $out = << + + + +XML; + header('Content-type: text/xml'); + echo $out; + } } /** @@ -180,4 +201,4 @@ class RestfulServiceTest_MockRestfulService extends RestfulService { return $response; } } -?> \ No newline at end of file +?>