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;
|
$num = $i + 1;
|
||||||
|
|
||||||
$emptyRange = $num != 1 && $num != $total && (
|
$emptyRange = $num != 1 && $num != $total && (
|
||||||
$num == $left - 1 || $num == $right + 1
|
$num == $left - 1 || $num == $right + 1
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($emptyRange) {
|
if ($emptyRange) {
|
||||||
$result->push(new ArrayData([
|
$result->push(new ArrayData([
|
||||||
|
@ -90,7 +90,7 @@ class PaginatedListTest extends SapphireTest
|
|||||||
$this->assertEquals(1, $list->CurrentPage());
|
$this->assertEquals(1, $list->CurrentPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetIterator()
|
public function testIteration()
|
||||||
{
|
{
|
||||||
$list = new PaginatedList(
|
$list = new PaginatedList(
|
||||||
new ArrayList([
|
new ArrayList([
|
||||||
@ -105,26 +105,23 @@ class PaginatedListTest extends SapphireTest
|
|||||||
|
|
||||||
$this->assertListEquals(
|
$this->assertListEquals(
|
||||||
[['Num' => 1], ['Num' => 2]],
|
[['Num' => 1], ['Num' => 2]],
|
||||||
ArrayList::create($list->getIterator()->getInnerIterator()->getArrayCopy())
|
$list
|
||||||
);
|
);
|
||||||
|
|
||||||
$list->setCurrentPage(2);
|
$list->setCurrentPage(2);
|
||||||
$this->assertListEquals(
|
$this->assertListEquals(
|
||||||
[['Num' => 3], ['Num' => 4]],
|
[['Num' => 3], ['Num' => 4]],
|
||||||
ArrayList::create($list->getIterator()->getInnerIterator()->getArrayCopy())
|
$list
|
||||||
);
|
);
|
||||||
|
|
||||||
$list->setCurrentPage(3);
|
$list->setCurrentPage(3);
|
||||||
$this->assertListEquals(
|
$this->assertListEquals(
|
||||||
[['Num' => 5]],
|
[['Num' => 5]],
|
||||||
ArrayList::create($list->getIterator()->getInnerIterator()->getArrayCopy())
|
$list
|
||||||
);
|
);
|
||||||
|
|
||||||
$list->setCurrentPage(999);
|
$list->setCurrentPage(999);
|
||||||
$this->assertListEquals(
|
$this->assertListEquals([], $list);
|
||||||
[],
|
|
||||||
ArrayList::create($list->getIterator()->getInnerIterator()->getArrayCopy())
|
|
||||||
);
|
|
||||||
|
|
||||||
// Test disabled paging
|
// Test disabled paging
|
||||||
$list->setPageLength(0);
|
$list->setPageLength(0);
|
||||||
@ -137,14 +134,14 @@ class PaginatedListTest extends SapphireTest
|
|||||||
['Num' => 4],
|
['Num' => 4],
|
||||||
['Num' => 5],
|
['Num' => 5],
|
||||||
],
|
],
|
||||||
ArrayList::create($list->getIterator()->getInnerIterator()->getArrayCopy())
|
$list
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test with dataobjectset
|
// Test with dataobjectset
|
||||||
$players = Player::get();
|
$players = Player::get();
|
||||||
$list = new PaginatedList($players);
|
$list = new PaginatedList($players);
|
||||||
$list->setPageLength(1);
|
$list->setPageLength(1);
|
||||||
$list->getIterator();
|
$list;
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
4,
|
4,
|
||||||
$list->getTotalItems(),
|
$list->getTotalItems(),
|
||||||
@ -223,10 +220,10 @@ class PaginatedListTest extends SapphireTest
|
|||||||
$list = new PaginatedList($list);
|
$list = new PaginatedList($list);
|
||||||
|
|
||||||
$list->setCurrentPage(3);
|
$list->setCurrentPage(3);
|
||||||
$this->assertCount(10, $list->getIterator()->getInnerIterator());
|
$this->assertEquals(10, count($list->toArray()));
|
||||||
|
|
||||||
$list->setLimitItems(false);
|
$list->setLimitItems(false);
|
||||||
$this->assertCount(50, $list->getIterator()->getInnerIterator());
|
$this->assertEquals(50, count($list->toArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCurrentPage()
|
public function testCurrentPage()
|
||||||
|
Loading…
Reference in New Issue
Block a user