diff --git a/library/CM/Http/Response/View/Abstract.php b/library/CM/Http/Response/View/Abstract.php index 8c993a6e2..604d6dc49 100644 --- a/library/CM/Http/Response/View/Abstract.php +++ b/library/CM/Http/Response/View/Abstract.php @@ -160,6 +160,7 @@ protected function _process() { }, function (CM_Exception $e, array $errorOptions) use (&$output) { $output['error'] = array('type' => get_class($e), 'msg' => $e->getMessagePublic($this->getRender()), 'isPublic' => $e->isPublic()); }); + $output['deployVersion'] = CM_App::getInstance()->getDeployVersion(); $this->setHeader('Content-Type', 'application/json'); $this->_setContent(json_encode($output)); diff --git a/tests/helpers/CMTest/library/CMTest/TestCase.php b/tests/helpers/CMTest/library/CMTest/TestCase.php index f598a7017..78191ba10 100644 --- a/tests/helpers/CMTest/library/CMTest/TestCase.php +++ b/tests/helpers/CMTest/library/CMTest/TestCase.php @@ -356,8 +356,9 @@ public static function assertViewResponseSuccess(CM_Http_Response_View_Abstract * @param CM_Http_Response_View_Abstract $response * @param string|null $type * @param string|null $message + * @param boolean|null $isPublic */ - public static function assertViewResponseError(CM_Http_Response_View_Abstract $response, $type = null, $message = null) { + public static function assertViewResponseError(CM_Http_Response_View_Abstract $response, $type = null, $message = null, $isPublic = null) { $responseContent = json_decode($response->getContent(), true); self::assertArrayHasKey('error', $responseContent, 'View response successful'); if (null !== $type) { @@ -366,6 +367,9 @@ public static function assertViewResponseError(CM_Http_Response_View_Abstract $r if (null !== $message) { self::assertSame($message, $responseContent['error']['msg']); } + if (null !== $isPublic) { + self::assertSame($isPublic, $responseContent['error']['isPublic']); + } } /** @@ -430,7 +434,7 @@ public function assertComponentNotRenderable(CM_Component_Abstract $component, C if (null === $expectedExceptionClass) { $expectedExceptionClass = 'CM_Exception'; } - $exception = $this->catchException(function() use ($component, $viewer) { + $exception = $this->catchException(function () use ($component, $viewer) { $this->_renderComponent($component, $viewer); }); $this->assertInstanceOf($expectedExceptionClass, $exception); @@ -599,7 +603,7 @@ public function assertPageNotRenderable(CM_Page_Abstract $page, $expectedExcepti $expectedExceptionClass = 'CM_Exception'; } - $exception = $this->catchException(function() use ($page, $viewer) { + $exception = $this->catchException(function () use ($page, $viewer) { $this->_renderPage($page, $viewer); }); $this->assertInstanceOf($expectedExceptionClass, $exception); diff --git a/tests/library/CM/Http/Response/View/AbstractTest.php b/tests/library/CM/Http/Response/View/AbstractTest.php index 0595619ac..f0129d1d6 100644 --- a/tests/library/CM/Http/Response/View/AbstractTest.php +++ b/tests/library/CM/Http/Response/View/AbstractTest.php @@ -33,28 +33,22 @@ public function testProcessExceptionCatching() { $response->mockMethod('getRender')->set(new CM_Frontend_Render()); /** @var CM_Http_Response_View_Abstract $response */ CMTest_TH::callProtectedMethod($response, '_process'); - $responseData = CM_Params::jsonDecode($response->getContent()); - $this->assertSame( - ['error' => - ['type' => 'CM_Exception_Invalid', - 'msg' => 'bar', - 'isPublic' => true - ] - ], $responseData); + $this->assertViewResponseError($response, 'CM_Exception_Invalid', 'bar', true); + $response->mockMethod('_processView')->set(function () { throw new CM_Exception_Nonexistent('foo'); }); CMTest_TH::callProtectedMethod($response, '_process'); - $responseData = CM_Params::jsonDecode($response->getContent()); - $this->assertSame( - ['error' => - ['type' => 'CM_Exception_Nonexistent', - 'msg' => 'Internal server error', - 'isPublic' => false - ] - ], $responseData); + $this->assertViewResponseError($response, 'CM_Exception_Nonexistent', 'Internal server error', false); + } + + public function testProcessReturnDeployVersion() { + $response = $this->getResponseAjax(new CM_Page_View_Ajax_Test_Mock(), 'loadPage', ['path' => CM_Page_View_Ajax_Test_MockRedirect::getPath()]); + $responseDecoded = CM_Params::jsonDecode($response->getContent()); + $this->assertArrayHasKey('deployVersion', $responseDecoded); + $this->assertSame(CM_App::getInstance()->getDeployVersion(), $responseDecoded['deployVersion']); } public function testLoadPageRedirectExternal() {