Merged revisions 52224 via svnmerge from

http://svn.silverstripe.com/open/modules/sapphire/branches/2.2.2

........
  r52224 | sminnee | 2008-04-07 11:45:23 +1200 (Mon, 07 Apr 2008) | 1 line
  
  #2314 - Fixed SQLMap implementation so that Group::map() returns appropriate data, and the group dropdown on the access tab works.
........


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@53508 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-04-26 06:44:06 +00:00
parent 2069e33bea
commit 88d79d1b62
3 changed files with 65 additions and 5 deletions

View File

@ -48,12 +48,9 @@ class SQLMap extends Object implements IteratorAggregate {
}
}
/*
* Iterator - necessary for foreach to work
*/
public function getIterator() {
$this->genItems();
return $this->items->getIterator();
return new SQLMap_Iterator($this->items->getIterator());
}
/**
@ -87,4 +84,37 @@ class SQLMap extends Object implements IteratorAggregate {
}
}
class SQLMap_Iterator extends Object implements Iterator {
protected $items;
function __construct(Iterator $items) {
$this->items = $items;
}
/*
* Iterator functions - necessary for foreach to work
*/
public function rewind() {
return $this->items->rewind() ? $this->items->rewind()->Title : null;
}
public function current() {
return $this->items->current()->Title;
}
public function key() {
return $this->items->current()->ID;
}
public function next() {
$next = $this->items->next();
return isset($next->Title) ? $next->Title : null;
}
public function valid() {
return $this->items->valid();
}
}
?>

View File

@ -0,0 +1,25 @@
<?php
class GroupTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/security/GroupTest.yml';
/**
* Test the Group::map() function
*/
function testGroupMap() {
/* Group::map() returns an SQLMap object implementing iterator. You can use foreach to get ID-Title pairs. */
// We will iterate over the map and build mapOuput to more easily call assertions on the result.
$map = Group::map();
foreach($map as $k => $v) {
$mapOutput[$k] = $v;
}
$group1 = $this->objFromFixture('Group', 'group1');
$group2 = $this->objFromFixture('Group', 'group2');
/* We have added 2 groups to our fixture. They should both appear in $mapOutput. */
$this->assertEquals($mapOutput[$group1->ID], $group1->Title);
$this->assertEquals($mapOutput[$group2->ID], $group2->Title);
}
}

View File

@ -0,0 +1,5 @@
Group:
group1:
Title: Group 1
group2:
Title: Group 2