JumpingTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Paginator
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Paginator
  24. */
  25. require_once 'Zend/Paginator.php';
  26. /**
  27. * @see Zend_Paginator_ScrollingStyle_Jumping
  28. */
  29. require_once 'Zend/Paginator/ScrollingStyle/Jumping.php';
  30. /**
  31. * @see PHPUnit_Framework_TestCase
  32. */
  33. /**
  34. * @category Zend
  35. * @package Zend_Paginator
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. * @group Zend_Paginator
  40. */
  41. class Zend_Paginator_ScrollingStyle_JumpingTest extends PHPUnit_Framework_TestCase
  42. {
  43. /**
  44. * @var Zend_Paginator_ScrollingStyle_Jumping
  45. */
  46. private $_scrollingStyle;
  47. /**
  48. * @var Zend_Paginator
  49. */
  50. private $_paginator;
  51. private $_expectedRange;
  52. /**
  53. * Prepares the environment before running a test.
  54. */
  55. protected function setUp()
  56. {
  57. parent::setUp();
  58. $this->_scrollingStyle = new Zend_Paginator_ScrollingStyle_Jumping();
  59. $this->_paginator = Zend_Paginator::factory(range(1, 101));
  60. $this->_paginator->setItemCountPerPage(10);
  61. $this->_paginator->setPageRange(10);
  62. $this->_expectedRange = array_combine(range(1, 10), range(1, 10));
  63. }
  64. /**
  65. * Cleans up the environment after running a test.
  66. */
  67. protected function tearDown()
  68. {
  69. $this->_scrollingStyle = null;
  70. $this->_paginator = null;
  71. parent::tearDown();
  72. }
  73. public function testGetsPagesInRangeForFirstPage()
  74. {
  75. $this->_paginator->setCurrentPageNumber(1);
  76. $actual = $this->_scrollingStyle->getPages($this->_paginator);
  77. $this->assertEquals($this->_expectedRange, $actual);
  78. }
  79. public function testGetsPagesInRangeForSecondPage()
  80. {
  81. $this->_paginator->setCurrentPageNumber(2);
  82. $actual = $this->_scrollingStyle->getPages($this->_paginator);
  83. $this->assertEquals($this->_expectedRange, $actual);
  84. }
  85. public function testGetsPagesInRangeForSecondLastPage()
  86. {
  87. $this->_paginator->setCurrentPageNumber(10);
  88. $actual = $this->_scrollingStyle->getPages($this->_paginator);
  89. $this->assertEquals($this->_expectedRange, $actual);
  90. }
  91. public function testGetsPagesInRangeForLastPage()
  92. {
  93. $this->_paginator->setCurrentPageNumber(11);
  94. $actual = $this->_scrollingStyle->getPages($this->_paginator);
  95. $expected = array(11 => 11);
  96. $this->assertEquals($expected, $actual);
  97. }
  98. public function testGetsNextAndPreviousPageForFirstPage()
  99. {
  100. $this->_paginator->setCurrentPageNumber(1);
  101. $pages = $this->_paginator->getPages('Jumping');
  102. $this->assertEquals(2, $pages->next);
  103. }
  104. public function testGetsNextAndPreviousPageForSecondPage()
  105. {
  106. $this->_paginator->setCurrentPageNumber(2);
  107. $pages = $this->_paginator->getPages('Jumping');
  108. $this->assertEquals(1, $pages->previous);
  109. $this->assertEquals(3, $pages->next);
  110. }
  111. public function testGetsNextAndPreviousPageForMiddlePage()
  112. {
  113. $this->_paginator->setCurrentPageNumber(6);
  114. $pages = $this->_paginator->getPages('Jumping');
  115. $this->assertEquals(5, $pages->previous);
  116. $this->assertEquals(7, $pages->next);
  117. }
  118. public function testGetsNextAndPreviousPageForSecondLastPage()
  119. {
  120. $this->_paginator->setCurrentPageNumber(10);
  121. $pages = $this->_paginator->getPages('Jumping');
  122. $this->assertEquals(9, $pages->previous);
  123. $this->assertEquals(11, $pages->next);
  124. }
  125. public function testGetsNextAndPreviousPageForLastPage()
  126. {
  127. $this->_paginator->setCurrentPageNumber(11);
  128. $pages = $this->_paginator->getPages('Jumping');
  129. $this->assertEquals(10, $pages->previous);
  130. }
  131. }