BUGFIX SS_Map::keys() and SS_Map::values() are identical, keys() should return the *keys* not the values #6818

This commit is contained in:
Sean Harvey 2012-02-11 11:44:04 +13:00
parent 1d4ac6842f
commit 591dd4efa9
2 changed files with 29 additions and 8 deletions

View File

@ -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
*/

View File

@ -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');