From 591dd4efa9b81939f28bcb5915ef2f0e32da6d73 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Sat, 11 Feb 2012 11:44:04 +1300 Subject: [PATCH] BUGFIX SS_Map::keys() and SS_Map::values() are identical, keys() should return the *keys* not the values #6818 --- model/Map.php | 17 +++++++++-------- tests/model/MapTest.php | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/model/Map.php b/model/Map.php index cf8c18536..086e82baa 100644 --- a/model/Map.php +++ b/model/Map.php @@ -47,28 +47,29 @@ class SS_Map implements ArrayAccess, Countable, IteratorAggregate { } return $array; } - + /** * Return all the keys of this map */ function keys() { - $array = array(); + $output = array(); foreach($this as $k => $v) { - $array[] = $v; + $output[] = $k; } - return $array; + return $output; } + /** * Return all the values of this map */ function values() { - $array = array(); + $output = array(); foreach($this as $k => $v) { - $array[] = $v; + $output[] = $v; } - return $array; + return $output; } - + /** * Unshift an item onto the start of the map */ diff --git a/tests/model/MapTest.php b/tests/model/MapTest.php index 1f94f746b..df5ee6061 100755 --- a/tests/model/MapTest.php +++ b/tests/model/MapTest.php @@ -57,6 +57,26 @@ class SS_MapTest extends SapphireTest { "Phil" => "Phil is a unique guy, and comments on team2"), $map->toArray()); } + function testKeys() { + $list = DataList::create('DataObjectTest_TeamComment'); + $map = new SS_Map($list, 'Name', 'Comment'); + $this->assertEquals(array( + 'Joe', + 'Bob', + 'Phil' + ), $map->keys()); + } + + function testValues() { + $list = DataList::create('DataObjectTest_TeamComment'); + $map = new SS_Map($list, 'Name', 'Comment'); + $this->assertEquals(array( + 'This is a team comment by Joe', + 'This is a team comment by Bob', + 'Phil is a unique guy, and comments on team2' + ), $map->values()); + } + function testUnshift() { $list = DataList::create("DataObjectTest_TeamComment"); $map = new SS_Map($list, 'Name', 'Comment');