Skip to content

Commit

Permalink
BUGFIX: PaginatedList::getIterator() trims the original list to the p…
Browse files Browse the repository at this point in the history
…age lenght when the source list is DataList
  • Loading branch information
phalkunz committed Jul 14, 2012
1 parent bf91594 commit c555256
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/PaginatedList.php
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions tests/model/PaginatedListTest.php
Expand Up @@ -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.');
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit c555256

Please sign in to comment.