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)

View File

@ -26,10 +26,9 @@ require_once dirname(__FILE__) . '/../../app/FrontController.php';
require_once dirname(__FILE__) . '/../../app/Action.php';
require_once dirname(__FILE__) . '/../../app/AjaxAction.php';
class FrontControllerTest extends PHPUnit_Framework_TestCase
{
public function run(PHPUnit_Framework_TestResult $result = NULL)
{
$this->setPreserveGlobalState(false);
@ -133,6 +132,8 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
{
$this->setConstants(false);
$controller = FrontController::getInstance();
$result = $controller->execute();
$controller = FrontController::getInstance();
$this->assertNull($controller->execute());
}
@ -193,6 +194,24 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
$result = $controller->execute();
$this->assertNull($result);
}
/**
* @runInSeparateProcess
*/
public function testExecuteWithLayoutProfiler()
{
Config::set('PROFILER', true);
$this->getMock('userAction');
$this->getMock('DefaultLayout', array('fetch'), array(), 'DefaultLayoutMock');
$_SERVER['REQUEST_URI'] = '/user/account/213';
$this->setConstants(true);
$controller = FrontController::getInstance();
$router = $controller->getRouter();
$router->add('user', 'user/account/:id', 'user');
$result = $controller->execute();
$this->assertNull($result);
}
/**
* @runInSeparateProcess
*/
@ -209,6 +228,23 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
$this->assertNull($result);
}
/**
* @runInSeparateProcess
*/
public function testExecuteWithAjaxActionProfiler()
{
Config::set('PROFILER', true);
$this->getMock('userAction');
$this->getMock('DefaultLayout', array('fetch'), array(), 'DefaultLayoutMock');
$_SERVER['REQUEST_URI'] = '/user/account/213';
$this->setConstants(true);
$controller = FrontController::getInstance();
$router = $controller->getRouter();
$router->add('user', 'user/account/:id', 'NewAjax');
$result = $controller->execute();
$this->assertNull($result);
}
private function setConstants($val = false)
{
@ -237,6 +273,9 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
}
}
/**
* Used in testExecuteWithAjaxAction
*/
class NewAjaxAction extends AjaxAction{
protected function execute() {}
}