public function testSimpleMemberList()
 {
     Restrictable::set_enabled(false);
     $this->logInWithPermission('ADMIN');
     Restrictable::set_enabled(true);
     $user = $this->cache_generatedMembers['ADMIN'];
     $item = new PrivateObject();
     $item->Title = 'testCan item ';
     $item->write();
     Restrictable::set_enabled(false);
     $this->logInWithPermission('OTHERUSER');
     Restrictable::set_enabled(true);
     $otherUser = $this->cache_generatedMembers['OTHERUSER'];
     $can = $item->checkPerm('View');
     $this->assertFalse($can);
     Restrictable::set_enabled(false);
     $this->logInWithPermission('ADMIN');
     Restrictable::set_enabled(true);
     // grant the new list permissions
     $list = SimpleMemberList::create(array('Title' => 'test simple list'));
     $list->write();
     $item->grant('View', $list);
     $list->Members()->add($otherUser);
     $this->logInWithPermission('OTHERUSER');
     $can = $item->checkPerm('View');
     $this->assertTrue($can);
 }
 /**
  * gets the group that this user's friends belong to 
  */
 public function getGroupFor($type)
 {
     $groupType = $type . 'Group';
     $groupTypeID = $type . 'GroupID';
     if ($this->owner->{$groupTypeID}) {
         return $this->owner->{$groupType}();
     }
     $title = $this->owner->Email . ' ' . $type;
     $group = SimpleMemberList::get()->filter(array('Title' => $title))->first();
     if ($group && $group->exists()) {
         $this->owner->{$groupTypeID} = $group->ID;
         return $group;
     } else {
         $group = $this->transactionManager->runAsAdmin(function () use($title) {
             $group = SimpleMemberList::create();
             $group->Title = $title;
             $group->write();
             return $group;
         });
         if ($group) {
             $this->owner->{$groupTypeID} = $group->ID;
         }
         return $group;
     }
 }