Пример #1
0
 /**
  * Test remove from relation
  */
 public function testRemove()
 {
     $this->createUsers(5);
     $users_in_afiveone = $this->accounts->usersBelongingTo(1);
     $users_in_afiveone->add(1, 2, 3, 5);
     $this->assertEquals([1, 2, 3, 5], $users_in_afiveone->get());
     $users_in_afiveone->remove(2);
     $users_in_afiveone->remove(3);
     $this->assertEquals([1, 5], $users_in_afiveone->get());
     $users_in_afiveone->clear();
     $this->assertEquals([], $users_in_afiveone->get());
 }
Пример #2
0
 /**
  * Test if member and client counts are properly refreshed as users are added and removed from the list
  */
 public function testMembersAndClientsCount()
 {
     $afiveone_id = $this->accounts->insert(['subdomain' => 'afiveone', 'url' => 'https://afiveone.activecollab.com', 'license_key' => '123'])[0];
     $this->assertEquals(1, $this->accounts->count());
     $this->assertEquals(1, $afiveone_id);
     list($owner_id, $member_id, $subcontractor_id, $client1_id, $client2_id) = $this->users->insert(['acid' => 1001, 'email' => '*****@*****.**', 'role' => 'Owner'], ['acid' => 1002, 'email' => '*****@*****.**', 'role' => 'Member'], ['acid' => 1003, 'email' => '*****@*****.**', 'role' => 'Subcontractor'], ['acid' => 1004, 'email' => '*****@*****.**', 'role' => 'Client'], ['acid' => 1005, 'email' => '*****@*****.**', 'role' => 'Client']);
     $this->assertEquals(1, $owner_id);
     $this->assertEquals(2, $member_id);
     $this->assertEquals(3, $subcontractor_id);
     $this->assertEquals(4, $client1_id);
     $this->assertEquals(5, $client2_id);
     $afiveone_users = $this->accounts->usersBelongingTo(1);
     $this->assertInstanceOf('ActiveCollab\\Resistance\\Storage\\Relationship\\BelongingTo', $afiveone_users);
     $this->assertEquals(0, $this->accounts->getFieldValue(1, 'members_count'));
     $this->assertEquals(0, $this->accounts->getFieldValue(1, 'clients_count'));
     // ---------------------------------------------------
     //  Add members
     // ---------------------------------------------------
     $afiveone_users->add($owner_id, $member_id, $subcontractor_id);
     $this->assertEquals(3, $this->accounts->getFieldValue(1, 'members_count'));
     $this->assertEquals(0, $this->accounts->getFieldValue(1, 'clients_count'));
     // ---------------------------------------------------
     //  Add clients
     // ---------------------------------------------------
     $afiveone_users->add($client1_id, $client2_id);
     $this->assertEquals(3, $this->accounts->getFieldValue(1, 'members_count'));
     $this->assertEquals(2, $this->accounts->getFieldValue(1, 'clients_count'));
     // ---------------------------------------------------
     //  Remove one member and one client
     // ---------------------------------------------------
     $afiveone_users->remove($subcontractor_id);
     $afiveone_users->remove($client1_id);
     $this->assertEquals(2, $this->accounts->getFieldValue(1, 'members_count'));
     $this->assertEquals(1, $this->accounts->getFieldValue(1, 'clients_count'));
     // ---------------------------------------------------
     //  Clear
     // ---------------------------------------------------
     $afiveone_users->clear();
     $this->assertEquals(0, $this->accounts->getFieldValue(1, 'members_count'));
     $this->assertEquals(0, $this->accounts->getFieldValue(1, 'clients_count'));
 }