'Group Contact Create', 'description' => 'Test all Group Contact Create API methods.', 'group' => 'CiviCRM API Tests', ); } /** * Set up for group contact tests * * @todo set up calls function that doesn't work @ the moment */ function setUp() { parent::setUp(); $this->_contactId = $this->individualCreate(); $this->_groupId1 = $this->groupCreate(); $params = array( 'contact_id' => $this->_contactId, 'group_id' => $this->_groupId1, ); $result = $this->callAPISuccess('group_contact', 'create', $params); $group = array( 'name' => 'Test Group 2', 'domain_id' => 1, 'title' => 'New Test Group2 Created', 'description' => 'New Test Group2 Created', 'is_active' => 1, 'visibility' => 'User and User Admin Only', ); $this->_groupId2 = $this->groupCreate($group); $this->_group = array( $this->_groupId1 => array('title' => 'New Test Group Created', 'visibility' => 'Public Pages', 'in_method' => 'API', ), $this->_groupId2 => array( 'title' => 'New Test Group2 Created', 'visibility' => 'User and User Admin Only', 'in_method' => 'API', ), ); } function tearDown() { $tablesToTruncate = array( 'civicrm_contact', 'civicrm_group', ); $this->quickCleanup($tablesToTruncate); } ///////////////// civicrm_group_contact_get methods function testGet() { $params = array( 'contact_id' => $this->_contactId, ); $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__); foreach ($result['values'] as $v) { $this->assertEquals($v['title'], $this->_group[$v['group_id']]['title']); $this->assertEquals($v['visibility'], $this->_group[$v['group_id']]['visibility']); $this->assertEquals($v['in_method'], $this->_group[$v['group_id']]['in_method']); } } function testGetGroupID() { $description = "Get all from group and display contacts"; $subfile = "GetWithGroupID"; $params = array( 'group_id' => $this->_groupId1, 'api.group.get' => 1, 'sequential' => 1, ); $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); foreach ($result['values'][0]['api.group.get']['values'] as $values) { $key = $values['id']; $this->assertEquals($values['title'], $this->_group[$key]['title']); $this->assertEquals($values['visibility'], $this->_group[$key]['visibility']); } } function testCreateWithEmptyParams() { $params = array(); $groups = $this->callAPIFailure('group_contact', 'create', $params); $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id, contact_id' ); } function testCreateWithoutGroupIdParams() { $params = array( 'contact_id' => $this->_contactId, ); $groups = $this->callAPIFailure('group_contact', 'create', $params); $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id'); } function testCreateWithoutContactIdParams() { $params = array( 'group_id' => $this->_groupId1, ); $groups = $this->callAPIFailure('group_contact', 'create', $params); $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id'); } function testCreate() { $cont = array( 'first_name' => 'Amiteshwar', 'middle_name' => 'L.', 'last_name' => 'Prasad', 'prefix_id' => 3, 'suffix_id' => 3, 'email' => 'amiteshwar.prasad@civicrm.org', 'contact_type' => 'Individual', ); $this->_contactId1 = $this->individualCreate($cont); $params = array( 'contact_id' => $this->_contactId, 'contact_id.2' => $this->_contactId1, 'group_id' => $this->_groupId1, ); $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['not_added'], 1, "in line " . __LINE__); $this->assertEquals($result['added'], 1, "in line " . __LINE__); $this->assertEquals($result['total_count'], 2, "in line " . __LINE__); } ///////////////// civicrm_group_contact_remove methods function testDelete() { $params = array( 'contact_id' => $this->_contactId, 'group_id' => 1, ); $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['removed'], 1, "in line " . __LINE__); $this->assertEquals($result['total_count'], 1, "in line " . __LINE__); } function testDeletePermanent() { $result = $this->callAPISuccess('group_contact', 'get', array('contact_id' => $this->_contactId)); $params = array( 'id' => $result['id'], 'skip_undelete' => TRUE, ); $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); $result = $this->callAPISuccess('group_contact', 'get', $params); $this->assertEquals(0, $result['count'], "in line " . __LINE__); $this->assertArrayNotHasKey('id', $result, "in line " . __LINE__); } }