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.

95 lines
2.6 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. Config::set('DEBUG', 0);
  21. $action = $this->getMockForAbstractClass('PagerAction');
  22. $this->assertSame(20, $action->getLimit());
  23. $action = $this->getMockForAbstractClass('PagerAction', array(50));
  24. $this->assertSame(50, $action->getLimit());
  25. }
  26. /**
  27. * @runInSeparateProcess
  28. */
  29. public function testSetCount()
  30. {
  31. Config::set('DEBUG', 0);
  32. $action = $this->getMockForAbstractClass('PagerAction');
  33. $action->setCount(50);
  34. $this->assertSame(1, $action->page);
  35. $this->assertSame(0, $action->getOffset());
  36. $_GET['p'] = 'last';
  37. $action->setCount(50);
  38. $this->assertSame(3.0, $action->page);
  39. $this->assertSame(40, $action->getOffset());
  40. $_GET['p'] = 2;
  41. $action->setCount(50);
  42. $this->assertSame(2, $action->page);
  43. $this->assertSame(20, $action->getOffset());
  44. $_GET['p'] = -3;
  45. $action->setCount(50);
  46. $this->assertSame(1, $action->page);
  47. }
  48. /**
  49. * @runInSeparateProcess
  50. */
  51. public function testGetOffset()
  52. {
  53. Config::set('DEBUG', 0);
  54. $action = $this->getMockForAbstractClass('PagerAction');
  55. $this->assertSame(0, $action->getOffset());
  56. }
  57. /**
  58. * @runInSeparateProcess
  59. */
  60. public function testFetchNoTemplate()
  61. {
  62. Config::set('DEBUG', 0);
  63. Env::setParams(array('template' => ''));
  64. $controller = FrontController::getInstance();
  65. $controller->setView('SomeView');
  66. $action = $this->getMockForAbstractClass('PagerAction', array(), 'PagerActionMock');
  67. $result = $action->fetch();
  68. $this->assertSame('/actions/PagerActi', $result['template']);
  69. }
  70. /**
  71. * @runInSeparateProcess
  72. */
  73. public function testFetchWithTemplate()
  74. {
  75. Config::set('DEBUG', 0);
  76. Env::setParams(array('template' => 'SomeTemplate'));
  77. $controller = FrontController::getInstance();
  78. $controller->setView('SomeView');
  79. $action = $this->getMockForAbstractClass('PagerAction');
  80. $result = $action->fetch();
  81. $this->assertSame('/actions/SomeTemplate', $result['template']);
  82. }
  83. }