AllTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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-2009 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_All
  28. */
  29. require_once 'Zend/Paginator/ScrollingStyle/All.php';
  30. /**
  31. * @see PHPUnit_Framework_TestCase
  32. */
  33. require_once 'PHPUnit/Framework/TestCase.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Paginator
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2009 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_AllTest extends PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * @var Zend_Paginator_ScrollingStyle_All
  46. */
  47. private $_scrollingStyle = null;
  48. private $_paginator = null;
  49. /**
  50. * Prepares the environment before running a test.
  51. */
  52. protected function setUp()
  53. {
  54. parent::setUp();
  55. $this->_scrollingStyle = new Zend_Paginator_ScrollingStyle_All();
  56. $this->_paginator = Zend_Paginator::factory(range(1, 101));
  57. $this->_paginator->setItemCountPerPage(10);
  58. }
  59. /**
  60. * Cleans up the environment after running a test.
  61. */
  62. protected function tearDown ()
  63. {
  64. $this->_scrollingStyle = null;
  65. $this->_paginator = null;
  66. parent::tearDown();
  67. }
  68. /**
  69. * Tests Zend_Paginator_ScrollingStyle_All->getPages()
  70. */
  71. public function testGetsPages()
  72. {
  73. $expected = array_combine(range(1, 11), range(1, 11));
  74. $pages = $this->_scrollingStyle->getPages($this->_paginator);
  75. $this->assertEquals($expected, $pages);
  76. }
  77. public function testGetsNextAndPreviousPageForFirstPage()
  78. {
  79. $this->_paginator->setCurrentPageNumber(1);
  80. $pages = $this->_paginator->getPages('All');
  81. $this->assertEquals(2, $pages->next);
  82. }
  83. public function testGetsNextAndPreviousPageForSecondPage()
  84. {
  85. $this->_paginator->setCurrentPageNumber(2);
  86. $pages = $this->_paginator->getPages('All');
  87. $this->assertEquals(1, $pages->previous);
  88. $this->assertEquals(3, $pages->next);
  89. }
  90. public function testGetsNextAndPreviousPageForMiddlePage()
  91. {
  92. $this->_paginator->setCurrentPageNumber(6);
  93. $pages = $this->_paginator->getPages('All');
  94. $this->assertEquals(5, $pages->previous);
  95. $this->assertEquals(7, $pages->next);
  96. }
  97. public function testGetsNextAndPreviousPageForSecondLastPage()
  98. {
  99. $this->_paginator->setCurrentPageNumber(10);
  100. $pages = $this->_paginator->getPages('All');
  101. $this->assertEquals(9, $pages->previous);
  102. $this->assertEquals(11, $pages->next);
  103. }
  104. public function testGetsNextAndPreviousPageForLastPage()
  105. {
  106. $this->_paginator->setCurrentPageNumber(11);
  107. $pages = $this->_paginator->getPages('All');
  108. $this->assertEquals(10, $pages->previous);
  109. }
  110. }