Skip to content
This repository
Browse code

BUGFIX: PaginatedList::getIterator() trims the original list to the p…

…age lenght when the source list is DataList
  • Loading branch information...
commit c555256890b2cd0993402f775f5165aa04e72ae9 1 parent bf91594
Saophalkun Ponlu authored July 15, 2012
3  core/PaginatedList.php
@@ -172,8 +172,9 @@ public function setLimitItems($limit) {
172 172
 	 */
173 173
 	public function getIterator() {
174 174
 		if($this->limitItems) {
  175
+			$tmptList = clone $this->list;
175 176
 			return new IteratorIterator(
176  
-				$this->list->limit($this->pageLength, $this->getPageStart())
  177
+				$tmptList->limit($this->pageLength, $this->getPageStart())
177 178
 			);
178 179
 		} else {
179 180
 			return new IteratorIterator($this->list);
14  tests/model/PaginatedListTest.php
@@ -7,6 +7,14 @@
7 7
  */
8 8
 class PaginatedListTest extends SapphireTest {
9 9
 
  10
+	static $fixture_file = 'DataObjectTest.yml';
  11
+
  12
+	protected $extraDataObjects = array(
  13
+		'DataObjectTest_Team',		
  14
+		'DataObjectTest_SubTeam',
  15
+		'DataObjectTest_Player'
  16
+	);
  17
+
10 18
 	public function testPageStart() {
11 19
 		$list = new PaginatedList(new ArrayList());
12 20
 		$this->assertEquals(0, $list->getPageStart(), 'The start defaults to 0.');
@@ -84,6 +92,12 @@ public function testGetIterator() {
84 92
 
85 93
 		$list->setCurrentPage(999);
86 94
 		$this->assertDOSEquals(array(), $list->getIterator());
  95
+
  96
+		$players = DataObjectTest_Player::get();
  97
+		$list = new PaginatedList($players);
  98
+		$list->setPageLength(1);
  99
+		$list->getIterator();
  100
+		$this->assertEquals(4, $list->getTotalItems(), 'Getting an iterator should not trim the list to the page length.');
87 101
 	}
88 102
 
89 103
 	public function testPages() {

0 notes on commit c555256

Please sign in to comment.
Something went wrong with that request. Please try again.