mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Don’t call PaginatedList::getIterator() directly.
It’s best for foreach() to call this for us.
This commit is contained in:
parent
1efe2b46ff
commit
d8735633a7
@ -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([
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user