Merge remote-tracking branch 'origin/3.2' into 3

This commit is contained in:
Damian Mooyman 2015-12-22 17:05:07 +13:00
commit 19b10044ec
2 changed files with 23 additions and 0 deletions

View File

@ -263,6 +263,10 @@ class Group extends DataObject {
// First get direct members as a base result
$result = $this->DirectMembers();
// Unsaved group cannot have child groups because its ID is still 0.
if(!$this->exists()) return $result;
// Remove the default foreign key filter in prep for re-applying a filter containing all children groups.
// Filters are conjunctive in DataQuery by default, so this filter would otherwise overrule any less specific
// ones.
@ -288,9 +292,14 @@ class Group extends DataObject {
/**
* Return a set of this record's "family" of IDs - the IDs of
* this record and all its descendants.
*
* @return array
*/
public function collateFamilyIDs() {
if (!$this->exists()) {
throw new \InvalidArgumentException("Cannot call collateFamilyIDs on unsaved Group.");
}
$familyIDs = array();
$chunkToAdd = array($this->ID);

View File

@ -69,6 +69,20 @@ class GroupTest extends FunctionalTest {
}
public function testUnsavedGroups() {
$member = $this->objFromFixture('GroupTest_Member', 'admin');
$group = new Group();
// Can save user to unsaved group
$group->Members()->add($member);
$this->assertEquals(array($member->ID), array_values($group->Members()->getIDList()));
// Persists after writing to DB
$group->write();
$group = Group::get()->byID($group->ID);
$this->assertEquals(array($member->ID), array_values($group->Members()->getIDList()));
}
public function testCollateAncestorIDs() {
$parentGroup = $this->objFromFixture('Group', 'parentgroup');
$childGroup = $this->objFromFixture('Group', 'childgroup');