public function testMemberGroupRelationForm()
 {
     Session::set('loggedInAs', $this->idFromFixture('GroupTest_Member', 'admin'));
     $adminGroup = $this->objFromFixture('Group', 'admingroup');
     $parentGroup = $this->objFromFixture('Group', 'parentgroup');
     $childGroup = $this->objFromFixture('Group', 'childgroup');
     // Test single group relation through checkboxsetfield
     $form = new GroupTest_MemberForm($this, 'Form');
     $member = $this->objFromFixture('GroupTest_Member', 'admin');
     $form->loadDataFrom($member);
     $checkboxSetField = $form->Fields()->fieldByName('Groups');
     $checkboxSetField->setValue(array($adminGroup->ID => $adminGroup->ID, $parentGroup->ID => $parentGroup->ID));
     $form->saveInto($member);
     $updatedGroups = $member->Groups();
     $this->assertEquals(2, count($updatedGroups->column()), "Adding a toplevel group works");
     $this->assertContains($adminGroup->ID, $updatedGroups->column('ID'));
     $this->assertContains($parentGroup->ID, $updatedGroups->column('ID'));
     // Test unsetting relationship
     $form->loadDataFrom($member);
     $checkboxSetField = $form->Fields()->fieldByName('Groups');
     $checkboxSetField->setValue(array($adminGroup->ID => $adminGroup->ID));
     $form->saveInto($member);
     $member->flushCache();
     $updatedGroups = $member->Groups();
     $this->assertEquals(1, count($updatedGroups->column()), "Removing a previously added toplevel group works");
     $this->assertContains($adminGroup->ID, $updatedGroups->column('ID'));
     // Test adding child group
 }
Beispiel #2
0
	function testMemberGroupRelationForm() {
	      $adminGroup = $this->fixture->objFromFixture('Group', 'admingroup');
	      $parentGroup = $this->fixture->objFromFixture('Group', 'parentgroup');
	      $childGroup = $this->fixture->objFromFixture('Group', 'childgroup');

	      // Test single group relation through checkboxsetfield
	      $form = new GroupTest_MemberForm($this, 'Form');
	      $member = $this->fixture->objFromFixture('GroupTest_Member', 'admin');
	      $form->loadDataFrom($member);
	      $checkboxSetField = $form->Fields()->fieldByName('Groups');
	      $checkboxSetField->setValue(array(
	         $adminGroup->ID => $adminGroup->ID, // keep existing relation
	         $parentGroup->ID => $parentGroup->ID, // add new relation
	      ));
	      $form->saveInto($member);
	      $updatedGroups = $member->Groups();
	      $controlGroups = new Member_GroupSet(
	         $adminGroup,
	         $parentGroup
	      );
	      $this->assertEquals(
	         $updatedGroups->Map('ID','ID'),
	         $controlGroups->Map('ID','ID'),
	         "Adding a toplevel group works"
	      );

	      // Test unsetting relationship
	      $form->loadDataFrom($member);
	      $checkboxSetField = $form->Fields()->fieldByName('Groups');
	      $checkboxSetField->setValue(array(
	         $adminGroup->ID => $adminGroup->ID, // keep existing relation
	         //$parentGroup->ID => $parentGroup->ID, // remove previously set relation
	      ));
	      $form->saveInto($member);
	      $member->flushCache();
	      $updatedGroups = $member->Groups();
	      $controlGroups = new Member_GroupSet(
	         $adminGroup
	      );
	      $this->assertEquals(
	         $updatedGroups->Map('ID','ID'),
	         $controlGroups->Map('ID','ID'),
	         "Removing a previously added toplevel group works"
	      );

	      // Test adding child group

	   }