diff --git a/src/ORM/PaginatedList.php b/src/ORM/PaginatedList.php index 2a0d6f07d..1d0554e03 100644 --- a/src/ORM/PaginatedList.php +++ b/src/ORM/PaginatedList.php @@ -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([ diff --git a/tests/php/ORM/PaginatedListTest.php b/tests/php/ORM/PaginatedListTest.php index fb63403d6..e2ade0d48 100644 --- a/tests/php/ORM/PaginatedListTest.php +++ b/tests/php/ORM/PaginatedListTest.php @@ -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()