From c555256890b2cd0993402f775f5165aa04e72ae9 Mon Sep 17 00:00:00 2001 From: Saophalkun Ponlu Date: Sun, 15 Jul 2012 01:02:49 +1200 Subject: [PATCH] BUGFIX: PaginatedList::getIterator() trims the original list to the page lenght when the source list is DataList --- core/PaginatedList.php | 3 ++- tests/model/PaginatedListTest.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/PaginatedList.php b/core/PaginatedList.php index 5886182eb79..0401063ef78 100644 --- a/core/PaginatedList.php +++ b/core/PaginatedList.php @@ -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); diff --git a/tests/model/PaginatedListTest.php b/tests/model/PaginatedListTest.php index 0bed6b70cdb..2ed971a203e 100644 --- a/tests/model/PaginatedListTest.php +++ b/tests/model/PaginatedListTest.php @@ -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() {