コード例 #1
0
ファイル: ManyToManyTest.php プロジェクト: twocore/framework
 /**
  *
  */
 public function testSynchronizeUsingArrayOfIds()
 {
     $user = ManyToManyUser::get(3);
     $group1 = ManyToManyGroup::get(1);
     $group2 = ManyToManyGroup::get(2);
     $group3 = ManyToManyGroup::get(4);
     $this->assertEquals(1, count($user->groups()->all()));
     $user->groups()->synchronize([$group1->id, $group2->id, $group3->id]);
     $this->assertEquals(3, count($user->groups()->all()));
     $user->groups()->synchronize([$group2->id]);
     $this->assertEquals(1, count($user->groups()->all()));
 }
コード例 #2
0
 /**
  *
  */
 public function testLinkAndUnlink()
 {
     $user = ManyToManyUser::get(3);
     $group = ManyToManyGroup::get(1);
     $this->assertEquals(1, count($user->groups()->all()));
     $this->assertEquals(1, count($group->users()->all()));
     // Link and unlink using object
     $user->groups()->link($group);
     $this->assertEquals(2, count($user->groups()->all()));
     $this->assertEquals(2, count($group->users()->all()));
     $user->groups()->unlink($group);
     $this->assertEquals(1, count($user->groups()->all()));
     $this->assertEquals(1, count($group->users()->all()));
     // Link and unlink using id
     $user->groups()->link($group->id);
     $this->assertEquals(2, count($user->groups()->all()));
     $this->assertEquals(2, count($group->users()->all()));
     $user->groups()->unlink($group->id);
     $this->assertEquals(1, count($user->groups()->all()));
     $this->assertEquals(1, count($group->users()->all()));
     // Link and unlink using object
     $group->users()->link($user);
     $this->assertEquals(2, count($user->groups()->all()));
     $this->assertEquals(2, count($group->users()->all()));
     $group->users()->unlink($user);
     $this->assertEquals(1, count($user->groups()->all()));
     $this->assertEquals(1, count($group->users()->all()));
     // Link and unlink using id
     $group->users()->link($user->id);
     $this->assertEquals(2, count($user->groups()->all()));
     $this->assertEquals(2, count($group->users()->all()));
     $group->users()->unlink($user->id);
     $this->assertEquals(1, count($user->groups()->all()));
     $this->assertEquals(1, count($group->users()->all()));
 }