SlidingTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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-2010 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_ScrollingStyle_Sliding
  24. */
  25. require_once 'Zend/Paginator/ScrollingStyle/Sliding.php';
  26. /**
  27. * @see PHPUnit_Framework_TestCase
  28. */
  29. require_once 'PHPUnit/Framework/TestCase.php';
  30. /**
  31. * @see Zend_Paginator
  32. */
  33. require_once 'Zend/Paginator.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Paginator
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_Paginator
  41. */
  42. class Zend_Paginator_ScrollingStyle_SlidingTest extends PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * @var Zend_Paginator_ScrollingStyle_Sliding
  46. */
  47. private $_scrollingStyle;
  48. /**
  49. * @var Zend_Paginator
  50. */
  51. private $_paginator;
  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_Sliding();
  59. $this->_paginator = Zend_Paginator::factory(range(1, 101));
  60. $this->_paginator->setItemCountPerPage(10);
  61. $this->_paginator->setPageRange(5);
  62. }
  63. /**
  64. * Cleans up the environment after running a test.
  65. */
  66. protected function tearDown()
  67. {
  68. $this->_scrollingStyle = null;
  69. $this->_paginator = null;
  70. parent::tearDown();
  71. }
  72. public function testGetsPagesInRangeForFirstPage()
  73. {
  74. $this->_paginator->setCurrentPageNumber(1);
  75. $actual = $this->_scrollingStyle->getPages($this->_paginator);
  76. $expected = array_combine(range(1, 5), range(1, 5));
  77. $this->assertEquals($expected, $actual);
  78. }
  79. public function testGetsPagesInRangeForSecondPage()
  80. {
  81. $this->_paginator->setCurrentPageNumber(2);
  82. $actual = $this->_scrollingStyle->getPages($this->_paginator);
  83. $expected = array_combine(range(1, 5), range(1, 5));
  84. $this->assertEquals($expected, $actual);
  85. }
  86. public function testGetsPagesInRangeForFifthPage()
  87. {
  88. $this->_paginator->setCurrentPageNumber(5);
  89. $actual = $this->_scrollingStyle->getPages($this->_paginator);
  90. $expected = array_combine(range(3, 7), range(3, 7));
  91. $this->assertEquals($expected, $actual);
  92. }
  93. public function testGetsPagesInRangeForLastPage()
  94. {
  95. $this->_paginator->setCurrentPageNumber(11);
  96. $actual = $this->_scrollingStyle->getPages($this->_paginator);
  97. $expected = array_combine(range(7, 11), range(7, 11));
  98. $this->assertEquals($expected, $actual);
  99. }
  100. public function testGetsNextAndPreviousPageForFirstPage()
  101. {
  102. $this->_paginator->setCurrentPageNumber(1);
  103. $pages = $this->_paginator->getPages('Sliding');
  104. $this->assertEquals(2, $pages->next);
  105. }
  106. public function testGetsNextAndPreviousPageForSecondPage()
  107. {
  108. $this->_paginator->setCurrentPageNumber(2);
  109. $pages = $this->_paginator->getPages('Sliding');
  110. $this->assertEquals(1, $pages->previous);
  111. $this->assertEquals(3, $pages->next);
  112. }
  113. public function testGetsNextAndPreviousPageForMiddlePage()
  114. {
  115. $this->_paginator->setCurrentPageNumber(6);
  116. $pages = $this->_paginator->getPages('Sliding');
  117. $this->assertEquals(5, $pages->previous);
  118. $this->assertEquals(7, $pages->next);
  119. }
  120. public function testGetsNextAndPreviousPageForSecondLastPage()
  121. {
  122. $this->_paginator->setCurrentPageNumber(10);
  123. $pages = $this->_paginator->getPages('Sliding');
  124. $this->assertEquals(9, $pages->previous);
  125. $this->assertEquals(11, $pages->next);
  126. }
  127. public function testGetsNextAndPreviousPageForLastPage()
  128. {
  129. $this->_paginator->setCurrentPageNumber(11);
  130. $pages = $this->_paginator->getPages('Sliding');
  131. $this->assertEquals(10, $pages->previous);
  132. }
  133. public function testAcceptsPageRangeLargerThanPageCount()
  134. {
  135. $this->_paginator->setPageRange(100);
  136. $pages = $this->_paginator->getPages();
  137. $this->assertEquals(11, $pages->last);
  138. }
  139. }