Reworked AJax action HTTP code and HTTP content. Added new HTTP template to process HTTP code output

This commit is contained in:
Anton Terekhov
2012-11-11 20:42:48 +04:00
parent 618f12224e
commit e1c3da8019
4 changed files with 106 additions and 39 deletions

View File

@ -12,6 +12,9 @@
require_once dirname(__FILE__) . '/Action_TestCase.php';
require_once dirname(__FILE__) . '/../../app/ErrorAction.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
require_once dirname(__FILE__) . '/../../exception/ErrorHTTPException.php';
require_once dirname(__FILE__) . '/../../exception/Error404Exception.php';
class ErrorActionTest extends Action_TestCase
{
@ -24,10 +27,9 @@ class ErrorActionTest extends Action_TestCase
$this->log = ini_get('error_log');
ini_set('error_log', '/dev/null');
set_exit_overload(function()
{
return false;
});
set_exit_overload(function () {
return false;
});
}
/**
@ -96,13 +98,15 @@ class ErrorActionTest extends Action_TestCase
public function testError404WithAjax()
{
$this->setConstants(false);
$exception = $this->getMock('Error404Exception', array('getMessage', 'getFile', 'getLine', 'getTrace'));
$exception->expects($this->once())
->method('getTrace')
->will($this->returnValue(array('one' => array('class' => 'AjaxAction'))));
$exception = new Error404Exception('Some message');
$controller = FrontController::getInstance();
$controller->setView('SomeView');
$action = new ErrorAction($exception);
$action->setAjaxError();
$this->assertSame($exception, $action->exception);
$result = $action->fetch();
$this->assertSame('Some message', $result);
}
/**
@ -111,13 +115,30 @@ class ErrorActionTest extends Action_TestCase
public function testError404NoAjax()
{
$this->setConstants(false);
$exception = $this->getMock('Error404Exception', array('getMessage', 'getFile', 'getLine', 'getTrace'));
$exception->expects($this->once())
->method('getTrace')
->will($this->returnValue(array('one' => array('class' => 'Action'))));
$exception = new Error404Exception('Some message');
$controller = FrontController::getInstance();
$controller->setView('SomeView');
$action = new ErrorAction($exception);
$this->assertSame($exception, $action->exception);
$result = $action->fetch();
$this->assertSame('/actions/404', $result['template']);
}
/**
* @runInSeparateProcess
*/
public function testErrorHTTP()
{
$this->setConstants(false);
$exception = new ErrorHTTPException('Some message', 410);
$controller = FrontController::getInstance();
$controller->setView('SomeView');
$action = new ErrorAction($exception);
$this->assertSame($exception, $action->exception);
$result = $action->fetch();
$this->assertSame('/actions/HTTP', $result['template']);
}
private function setConstants($val = false)