useTransaction(TRUE); $this->_individualID = $this->individualCreate(); $this->_tag = $this->tagCreate(); $this->_tagID = $this->_tag['id']; $this->_householdID = $this->houseHoldCreate(); $this->_organizationID = $this->organizationCreate(); } public function testAddEmptyParams() { $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params = array(), 'contact_id is a required field' ); } public function testAddWithoutTagID() { $params = array( 'contact_id' => $this->_individualID, ); $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params, 'tag_id is a required field' ); } public function testAddWithoutContactID() { $params = array( 'tag_id' => $this->_tagID, ); $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params, 'contact_id is a required field'); } public function testContactEntityTagCreate() { $params = array( 'contact_id' => $this->_individualID, 'tag_id' => $this->_tagID, ); $result = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['added'], 1); } public function testAddDouble() { $individualId = $this->_individualID; $organizationId = $this->_organizationID; $tagID = $this->_tagID; $params = array( 'contact_id' => $individualId, 'tag_id' => $tagID, ); $result = $this->callAPISuccess('entity_tag', 'create', $params); $this->assertEquals($result['added'], 1); $params = array( 'contact_id_i' => $individualId, 'contact_id_o' => $organizationId, 'tag_id' => $tagID, ); $result = $this->callAPISuccess('entity_tag', 'create', $params); $this->assertEquals($result['added'], 1); $this->assertEquals($result['not_added'], 1); } ///////////////// civicrm_entity_tag_get methods public function testGetNoEntityID() { $ContactId = $this->_individualID; $tagID = $this->_tagID; $params = array( 'contact_id' => $ContactId, 'tag_id' => $tagID, ); $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params); $this->assertEquals($individualEntity['added'], 1); $result = $this->callAPISuccess($this->_entity, 'get', array('sequential' => 1, 'tag_id' => $tagID)); $this->assertEquals($ContactId, $result['values'][0]['entity_id']); } public function testIndividualEntityTagGet() { $contactId = $this->_individualID; $tagID = $this->_tagID; $params = array( 'contact_id' => $contactId, 'tag_id' => $tagID, ); $individualEntity = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($individualEntity['added'], 1); $paramsEntity = array( 'contact_id' => $contactId, ); $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity); } public function testHouseholdEntityGet() { $ContactId = $this->_householdID; $tagID = $this->_tagID; $params = array( 'contact_id' => $ContactId, 'tag_id' => $tagID, ); $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params); $this->assertEquals($householdEntity['added'], 1); } public function testOrganizationEntityGet() { $ContactId = $this->_organizationID; $tagID = $this->_tagID; $params = array( 'contact_id' => $ContactId, 'tag_id' => $tagID, ); $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params); $this->assertEquals($organizationEntity['added'], 1); $paramsEntity = array('contact_id' => $ContactId); $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity); } ///////////////// civicrm_entity_tag_Delete methods public function testEntityTagDeleteNoTagId() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, ); $this->entityTagAdd($entityTagParams); $params = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, ); $result = $this->callAPIFailure('entity_tag', 'delete', $params, 'tag_id is a required field' ); } public function testEntityTagDeleteINDHH() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, ); $this->entityTagAdd($entityTagParams); $params = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, ); $result = $this->callAPISuccess('entity_tag', 'delete', $params); $this->assertEquals($result['removed'], 2); } public function testEntityTagDeleteHH() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, ); $this->entityTagAdd($entityTagParams); $params = array( 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, ); $result = $this->callAPIAndDocument('entity_tag', 'delete', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['removed'], 1); } public function testEntityTagDeleteHHORG() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, ); $this->entityTagAdd($entityTagParams); $params = array( 'contact_id_h' => $this->_householdID, 'contact_id_o' => $this->_organizationID, 'tag_id' => $this->_tagID, ); $result = $this->callAPISuccess('entity_tag', 'delete', $params); $this->assertEquals($result['removed'], 1); $this->assertEquals($result['not_removed'], 1); } ///////////////// civicrm_tag_entities_get methods public function testCommonContactEntityTagAdd() { $params = array( 'contact_id' => $this->_individualID, 'tag_id' => $this->_tagID, ); $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params); $this->assertEquals($individualEntity['added'], 1); } public function testEntityTagCommonDeleteINDHH() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, ); $this->entityTagAdd($entityTagParams); $params = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, ); $result = $this->callAPISuccess('entity_tag', 'delete', $params); $this->assertEquals($result['removed'], 2); } public function testEntityTagCommonDeleteHH() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, ); $this->entityTagAdd($entityTagParams); $params = array( 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, ); $result = $this->callAPISuccess('entity_tag', 'delete', $params); $this->assertEquals($result['removed'], 1); } public function testEntityTagCommonDeleteHHORG() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, 'tag_id' => $this->_tagID, ); $this->entityTagAdd($entityTagParams); $params = array( 'contact_id_h' => $this->_householdID, 'contact_id_o' => $this->_organizationID, 'tag_id' => $this->_tagID, ); $result = $this->callAPISuccess('entity_tag', 'delete', $params); $this->assertEquals($result['removed'], 1); $this->assertEquals($result['not_removed'], 1); } }