FIX: Don’t call PaginatedList::getIterator() directly.

It’s best for foreach() to call this for us.
This commit is contained in:
Sam Minnee 2017-01-17 15:23:30 +13:00 committed by Guy Sartorelli
parent 1efe2b46ff
commit d8735633a7
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A
2 changed files with 11 additions and 14 deletions

View File

@ -359,8 +359,8 @@ class PaginatedList extends ListDecorator
$num = $i + 1;
$emptyRange = $num != 1 && $num != $total && (
$num == $left - 1 || $num == $right + 1
);
$num == $left - 1 || $num == $right + 1
);
if ($emptyRange) {
$result->push(new ArrayData([

View File

@ -90,7 +90,7 @@ class PaginatedListTest extends SapphireTest
$this->assertEquals(1, $list->CurrentPage());
}
public function testGetIterator()
public function testIteration()
{
$list = new PaginatedList(
new ArrayList([
@ -105,26 +105,23 @@ class PaginatedListTest extends SapphireTest
$this->assertListEquals(
[['Num' => 1], ['Num' => 2]],
ArrayList::create($list->getIterator()->getInnerIterator()->getArrayCopy())
$list
);
$list->setCurrentPage(2);
$this->assertListEquals(
[['Num' => 3], ['Num' => 4]],
ArrayList::create($list->getIterator()->getInnerIterator()->getArrayCopy())
$list
);
$list->setCurrentPage(3);
$this->assertListEquals(
[['Num' => 5]],
ArrayList::create($list->getIterator()->getInnerIterator()->getArrayCopy())
$list
);
$list->setCurrentPage(999);
$this->assertListEquals(
[],
ArrayList::create($list->getIterator()->getInnerIterator()->getArrayCopy())
);
$this->assertListEquals([], $list);
// Test disabled paging
$list->setPageLength(0);
@ -137,14 +134,14 @@ class PaginatedListTest extends SapphireTest
['Num' => 4],
['Num' => 5],
],
ArrayList::create($list->getIterator()->getInnerIterator()->getArrayCopy())
$list
);
// Test with dataobjectset
$players = Player::get();
$list = new PaginatedList($players);
$list->setPageLength(1);
$list->getIterator();
$list;
$this->assertEquals(
4,
$list->getTotalItems(),
@ -223,10 +220,10 @@ class PaginatedListTest extends SapphireTest
$list = new PaginatedList($list);
$list->setCurrentPage(3);
$this->assertCount(10, $list->getIterator()->getInnerIterator());
$this->assertEquals(10, count($list->toArray()));
$list->setLimitItems(false);
$this->assertCount(50, $list->getIterator()->getInnerIterator());
$this->assertEquals(50, count($list->toArray()));
}
public function testCurrentPage()