Browse Source

ZF-4151: apply patch to correct OutOfBoundsException conditions

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21150 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 years ago
parent
commit
c0ff2ba125

+ 1 - 1
library/Zend/Paginator/Adapter/Null.php

@@ -58,7 +58,7 @@ class Zend_Paginator_Adapter_Null implements Zend_Paginator_Adapter_Interface
      */
     public function getItems($offset, $itemCountPerPage)
     {
-        if ($offset > $this->count()) {
+        if ($offset >= $this->count()) {
             return array();
         }
 

+ 10 - 0
tests/Zend/Paginator/Adapter/ArrayTest.php

@@ -80,4 +80,14 @@ class Zend_Paginator_Adapter_ArrayTest extends PHPUnit_Framework_TestCase
     {
         $this->assertEquals(101, $this->_adapter->count());
     }
+    
+
+    /**
+     * @group ZF-4151
+     */
+    public function testEmptySet() {
+        $this->_adapter = new Zend_Paginator_Adapter_Array(array());
+        $actual = $this->_adapter->getItems(0, 10);
+        $this->assertEquals(array(), $actual);
+    }
 }

+ 9 - 0
tests/Zend/Paginator/Adapter/IteratorTest.php

@@ -128,4 +128,13 @@ class Zend_Paginator_Adapter_IteratorTest extends PHPUnit_Framework_TestCase
         $this->assertTrue( ($items->getInnerIterator() == $innerIterator), 'getItems has to be serializable to use caching');
     }
 
+    /**
+     * @group ZF-4151
+     */
+    public function testEmptySet() {
+        $iterator = new ArrayIterator(array());
+        $this->_adapter = new Zend_Paginator_Adapter_Iterator($iterator);
+        $actual = $this->_adapter->getItems(0, 10);
+        $this->assertEquals(array(), $actual);
+    }
 }

+ 18 - 0
tests/Zend/Paginator/Adapter/NullTest.php

@@ -101,4 +101,22 @@ class Zend_Paginator_Adapter_NullTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(4, $pages->currentItemCount);
         $this->assertEquals(19, $pages->lastItemNumber);
     }
+
+    /**
+     * @group ZF-4151
+     */
+    public function testEmptySet() {
+        $this->_adapter = new Zend_Paginator_Adapter_Null(0);
+        $actual = $this->_adapter->getItems(0, 10);
+        $this->assertEquals(array(), $actual);
+    }
+    
+    /**
+     * Verify that the fix for ZF-4151 doesn't create an OBO error
+     */
+    public function testSetOfOne() {
+        $this->_adapter = new Zend_Paginator_Adapter_Null(1);
+        $actual = $this->_adapter->getItems(0, 10);
+        $this->assertEquals(array_fill(0, 1, null), $actual);
+    }
 }

BIN
tests/Zend/Paginator/_files/test.sqlite