Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUGFIX: PaginatedList::getIterator() trims the original list to the p…

…age lenght when the source list is DataList
  • Loading branch information...
commit c555256890b2cd0993402f775f5165aa04e72ae9 1 parent bf91594
Saophalkun Ponlu phalkunz authored
Showing with 16 additions and 1 deletion.
  1. +2 −1  core/PaginatedList.php
  2. +14 −0 tests/model/PaginatedListTest.php
3  core/PaginatedList.php
View
@@ -172,8 +172,9 @@ public function setLimitItems($limit) {
*/
public function getIterator() {
if($this->limitItems) {
+ $tmptList = clone $this->list;
return new IteratorIterator(
- $this->list->limit($this->pageLength, $this->getPageStart())
+ $tmptList->limit($this->pageLength, $this->getPageStart())
);
} else {
return new IteratorIterator($this->list);
14 tests/model/PaginatedListTest.php
View
@@ -7,6 +7,14 @@
*/
class PaginatedListTest extends SapphireTest {
+ static $fixture_file = 'DataObjectTest.yml';
+
+ protected $extraDataObjects = array(
+ 'DataObjectTest_Team',
+ 'DataObjectTest_SubTeam',
+ 'DataObjectTest_Player'
+ );
+
public function testPageStart() {
$list = new PaginatedList(new ArrayList());
$this->assertEquals(0, $list->getPageStart(), 'The start defaults to 0.');
@@ -84,6 +92,12 @@ public function testGetIterator() {
$list->setCurrentPage(999);
$this->assertDOSEquals(array(), $list->getIterator());
+
+ $players = DataObjectTest_Player::get();
+ $list = new PaginatedList($players);
+ $list->setPageLength(1);
+ $list->getIterator();
+ $this->assertEquals(4, $list->getTotalItems(), 'Getting an iterator should not trim the list to the page length.');
}
public function testPages() {
Please sign in to comment.
Something went wrong with that request. Please try again.