You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.8 KiB

  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-11-1
  8. *
  9. * Unit tests for PagerAction class
  10. */
  11. require_once dirname(__FILE__) . '/Action_TestCase.php';
  12. require_once dirname(__FILE__) . '/../../app/PagerAction.php';
  13. class PagerActionTest extends Action_TestCase
  14. {
  15. /**
  16. * @runInSeparateProcess
  17. */
  18. public function testConstructWithParams()
  19. {
  20. if (!defined('DEBUG')) {
  21. define('DEBUG', false);
  22. }
  23. $action = $this->getMockForAbstractClass('PagerAction');
  24. $this->assertSame(20, $action->getLimit());
  25. $action = $this->getMockForAbstractClass('PagerAction', array(50));
  26. $this->assertSame(50, $action->getLimit());
  27. }
  28. /**
  29. * @runInSeparateProcess
  30. */
  31. public function testSetCount()
  32. {
  33. if (!defined('DEBUG')) {
  34. define('DEBUG', false);
  35. }
  36. $action = $this->getMockForAbstractClass('PagerAction');
  37. $action->setCount(50);
  38. $this->assertSame(1, $action->page);
  39. $this->assertSame(0, $action->getOffset());
  40. $_GET['p'] = 'last';
  41. $action->setCount(50);
  42. $this->assertSame(3, $action->page);
  43. $this->assertSame(40, $action->getOffset());
  44. $_GET['p'] = 2;
  45. $action->setCount(50);
  46. $this->assertSame(2, $action->page);
  47. $this->assertSame(20, $action->getOffset());
  48. $_GET['p'] = -3;
  49. $action->setCount(50);
  50. $this->assertSame(1, $action->page);
  51. }
  52. /**
  53. * @runInSeparateProcess
  54. */
  55. public function testGetOffset()
  56. {
  57. if (!defined('DEBUG')) {
  58. define('DEBUG', false);
  59. }
  60. $action = $this->getMockForAbstractClass('PagerAction');
  61. $this->assertSame(0, $action->getOffset());
  62. }
  63. /**
  64. * @runInSeparateProcess
  65. */
  66. public function testFetchNoTemplate()
  67. {
  68. if (!defined('DEBUG')) {
  69. define('DEBUG', false);
  70. }
  71. Env::setParams(array('template' => ''));
  72. $controller = FrontController::getInstance();
  73. $controller->setView('SomeView');
  74. $action = $this->getMockForAbstractClass('PagerAction', array(), 'PagerActionMock');
  75. $result = $action->fetch();
  76. $this->assertSame('/actions/PagerActi', $result['template']);
  77. }
  78. /**
  79. * @runInSeparateProcess
  80. */
  81. public function testFetchWithTemplate()
  82. {
  83. if (!defined('DEBUG')) {
  84. define('DEBUG', false);
  85. }
  86. Env::setParams(array('template' => 'SomeTemplate'));
  87. $controller = FrontController::getInstance();
  88. $controller->setView('SomeView');
  89. $action = $this->getMockForAbstractClass('PagerAction');
  90. $result = $action->fetch();
  91. $this->assertSame('/actions/SomeTemplate', $result['template']);
  92. }
  93. }