NullTest.php 3.2 KB

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