mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX SS_Map::keys() and SS_Map::values() are identical, keys() should return the *keys* not the values #6818
This commit is contained in:
parent
1d4ac6842f
commit
591dd4efa9
@ -47,28 +47,29 @@ class SS_Map implements ArrayAccess, Countable, IteratorAggregate {
|
|||||||
}
|
}
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all the keys of this map
|
* Return all the keys of this map
|
||||||
*/
|
*/
|
||||||
function keys() {
|
function keys() {
|
||||||
$array = array();
|
$output = array();
|
||||||
foreach($this as $k => $v) {
|
foreach($this as $k => $v) {
|
||||||
$array[] = $v;
|
$output[] = $k;
|
||||||
}
|
}
|
||||||
return $array;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all the values of this map
|
* Return all the values of this map
|
||||||
*/
|
*/
|
||||||
function values() {
|
function values() {
|
||||||
$array = array();
|
$output = array();
|
||||||
foreach($this as $k => $v) {
|
foreach($this as $k => $v) {
|
||||||
$array[] = $v;
|
$output[] = $v;
|
||||||
}
|
}
|
||||||
return $array;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unshift an item onto the start of the map
|
* Unshift an item onto the start of the map
|
||||||
*/
|
*/
|
||||||
|
@ -57,6 +57,26 @@ class SS_MapTest extends SapphireTest {
|
|||||||
"Phil" => "Phil is a unique guy, and comments on team2"), $map->toArray());
|
"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() {
|
function testUnshift() {
|
||||||
$list = DataList::create("DataObjectTest_TeamComment");
|
$list = DataList::create("DataObjectTest_TeamComment");
|
||||||
$map = new SS_Map($list, 'Name', 'Comment');
|
$map = new SS_Map($list, 'Name', 'Comment');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user