From 1d92172931f66207a8b3fa11969ab40b715c80cb Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 17 Dec 2011 02:32:10 +0100 Subject: [PATCH] BUGFIX Returning 'first last' in ViewableData->FirstLast() if item is both at the same time --- tests/view/ViewableDataTest.php | 16 ++++++++++++++++ view/ViewableData.php | 1 + 2 files changed, 17 insertions(+) diff --git a/tests/view/ViewableDataTest.php b/tests/view/ViewableDataTest.php index bfb3afaba..03d76e901 100644 --- a/tests/view/ViewableDataTest.php +++ b/tests/view/ViewableDataTest.php @@ -112,6 +112,22 @@ class ViewableDataTest extends SapphireTest { } } + function testFirstLast() { + $vd = new ViewableData(); + + $vd->iteratorProperties(0, 3); + $this->assertEquals('first', $vd->FirstLast()); + + $vd->iteratorProperties(1, 3); + $this->assertEquals(null, $vd->FirstLast()); + + $vd->iteratorProperties(2, 3); + $this->assertEquals('last', $vd->FirstLast()); + + $vd->iteratorProperties(0, 1); + $this->assertEquals('first last', $vd->FirstLast()); + } + } /**#@+ diff --git a/view/ViewableData.php b/view/ViewableData.php index 1e357ba2c..8506dd03f 100644 --- a/view/ViewableData.php +++ b/view/ViewableData.php @@ -545,6 +545,7 @@ class ViewableData extends Object implements IteratorAggregate { * @return string|null */ public function FirstLast() { + if($this->First() && $this->Last()) return 'first last'; if($this->First()) return 'first'; if($this->Last()) return 'last'; }