NullTest.php 3.2 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-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
  24. */
  25. require_once 'Zend/Paginator.php';
  26. /**
  27. * @see Zend_Paginator_Adapter_Null
  28. */
  29. require_once 'Zend/Paginator/Adapter/Null.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-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_Adapter_NullTest extends PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * @var Zend_Paginator_Adapter_Array
  46. */
  47. private $_adapter;
  48. /**
  49. * Prepares the environment before running a test.
  50. */
  51. protected function setUp ()
  52. {
  53. parent::setUp();
  54. $this->_adapter = new Zend_Paginator_Adapter_Null(101);
  55. }
  56. /**
  57. * Cleans up the environment after running a test.
  58. */
  59. protected function tearDown()
  60. {
  61. $this->_adapter = null;
  62. parent::tearDown();
  63. }
  64. public function testGetsItems()
  65. {
  66. $actual = $this->_adapter->getItems(0, 10);
  67. $this->assertEquals(array_fill(0, 10, null), $actual);
  68. }
  69. public function testReturnsCorrectCount()
  70. {
  71. $this->assertEquals(101, $this->_adapter->count());
  72. }
  73. /**
  74. * @group ZF-3873
  75. */
  76. public function testAdapterReturnsCorrectValues()
  77. {
  78. $paginator = Zend_Paginator::factory(2);
  79. $paginator->setCurrentPageNumber(1);
  80. $paginator->setItemCountPerPage(5);
  81. $pages = $paginator->getPages();
  82. $this->assertEquals(2, $pages->currentItemCount);
  83. $this->assertEquals(2, $pages->lastItemNumber);
  84. $paginator = Zend_Paginator::factory(19);
  85. $paginator->setCurrentPageNumber(4);
  86. $paginator->setItemCountPerPage(5);
  87. $pages = $paginator->getPages();
  88. $this->assertEquals(4, $pages->currentItemCount);
  89. $this->assertEquals(19, $pages->lastItemNumber);
  90. }
  91. /**
  92. * @group ZF-4151
  93. */
  94. public function testEmptySet() {
  95. $this->_adapter = new Zend_Paginator_Adapter_Null(0);
  96. $actual = $this->_adapter->getItems(0, 10);
  97. $this->assertEquals(array(), $actual);
  98. }
  99. /**
  100. * Verify that the fix for ZF-4151 doesn't create an OBO error
  101. */
  102. public function testSetOfOne() {
  103. $this->_adapter = new Zend_Paginator_Adapter_Null(1);
  104. $actual = $this->_adapter->getItems(0, 10);
  105. $this->assertEquals(array_fill(0, 1, null), $actual);
  106. }
  107. }