From 05aba7afb6190c04bad9201655bacf6e06509b9b Mon Sep 17 00:00:00 2001 From: Rob McVey Date: Fri, 13 Mar 2015 15:52:22 +0000 Subject: [PATCH] Assert CakeException throw when json_encode fails --- lib/Cake/Test/Case/View/JsonViewTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/Cake/Test/Case/View/JsonViewTest.php b/lib/Cake/Test/Case/View/JsonViewTest.php index 5a661c78b..5fc9ff088 100644 --- a/lib/Cake/Test/Case/View/JsonViewTest.php +++ b/lib/Cake/Test/Case/View/JsonViewTest.php @@ -306,4 +306,25 @@ class JsonViewTest extends CakeTestCase { $this->assertSame($expected, $output); $this->assertSame('application/javascript', $Response->type()); } + +/** + * JsonViewTest::testRenderInvalidJSON() + * + * @expectedException CakeException + * @return void + */ + public function testRenderInvalidJSON() { + $Request = new CakeRequest(); + $Response = new CakeResponse(); + $Controller = new Controller($Request, $Response); + + // non utf-8 stuff + $data = array('data' => array('foo' => 'bar' . chr('0x97'))); + + $Controller->set($data); + $Controller->set('_serialize', 'data'); + $View = new JsonView($Controller); + $output = $View->render(); + } + }