Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1841 from alexispeter/ajax-app-releaseStamp
Browse files Browse the repository at this point in the history
Send app releaseStamp on every ajax request
  • Loading branch information
alexispeter committed Jul 16, 2015
2 parents 0284054 + 2fe3693 commit 0400ad8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions library/CM/Http/Response/View/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
10 changes: 7 additions & 3 deletions tests/helpers/CMTest/library/CMTest/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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']);
}
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 10 additions & 16 deletions tests/library/CM/Http/Response/View/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 0400ad8

Please sign in to comment.