Action and FrontController classes tested
This commit is contained in:
101
tests/app/PagerActionTest.php
Normal file
101
tests/app/PagerActionTest.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage UnitTests
|
||||
* @since 2011-11-1
|
||||
*
|
||||
* Unit tests for PagerAction class
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/Action_TestCase.php';
|
||||
require_once dirname(__FILE__) . '/../../app/PagerAction.php';
|
||||
|
||||
class PagerActionTest extends Action_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testConstructWithParams()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', false);
|
||||
}
|
||||
$action = $this->getMockForAbstractClass('PagerAction');
|
||||
$this->assertEquals(20, $action->getLimit());
|
||||
$action = $this->getMockForAbstractClass('PagerAction', array(50));
|
||||
$this->assertEquals(50, $action->getLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testSetCount()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', false);
|
||||
}
|
||||
$action = $this->getMockForAbstractClass('PagerAction');
|
||||
$action->setCount(50);
|
||||
$this->assertEquals(1, $action->page);
|
||||
$this->assertEquals(0, $action->getOffset());
|
||||
$_GET['p'] = 'last';
|
||||
$action->setCount(50);
|
||||
$this->assertEquals(3, $action->page);
|
||||
$this->assertEquals(40, $action->getOffset());
|
||||
$_GET['p'] = 2;
|
||||
$action->setCount(50);
|
||||
$this->assertEquals(2, $action->page);
|
||||
$this->assertEquals(20, $action->getOffset());
|
||||
$_GET['p'] = -3;
|
||||
$action->setCount(50);
|
||||
$this->assertEquals(1, $action->page);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testGetOffset()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', false);
|
||||
}
|
||||
$action = $this->getMockForAbstractClass('PagerAction');
|
||||
$this->assertEquals(0, $action->getOffset());
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testFetchNoTemplate()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', false);
|
||||
}
|
||||
Env::setParams(array('template' => ''));
|
||||
$controller = FrontController::getInstance();
|
||||
$controller->setView('SomeView');
|
||||
$action = $this->getMockForAbstractClass('PagerAction', array(), 'PagerActionMock');
|
||||
$result = $action->fetch();
|
||||
$this->assertEquals('/actions/PagerActi', $result['template']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testFetchWithTemplate()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', false);
|
||||
}
|
||||
Env::setParams(array('template' => 'SomeTemplate'));
|
||||
$controller = FrontController::getInstance();
|
||||
$controller->setView('SomeView');
|
||||
$action = $this->getMockForAbstractClass('PagerAction');
|
||||
$result = $action->fetch();
|
||||
$this->assertEquals('/actions/SomeTemplate', $result['template']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user