*
* (PHP 5)
*
- * @author Walt Haas <walt@dharmatech.org> (801) 534-1262
- * @copyright Copyright CiviCRM LLC (C) 2009
- * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html
+ * @author Walt Haas <walt@dharmatech.org> (801) 534-1262
+ * @copyright Copyright CiviCRM LLC (C) 2009
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html
* GNU Affero General Public License version 3
- * @version $Id: ContactTest.php 31254 2010-12-15 10:09:29Z eileen $
- * @package CiviCRM
+ * @version $Id: ContactTest.php 31254 2010-12-15 10:09:29Z eileen $
+ * @package CiviCRM
*
* This file is part of CiviCRM
*
/**
* Test APIv3 civicrm_contact* functions
*
- * @package CiviCRM_APIv3
- * @subpackage API_Contact
+ * @package CiviCRM_APIv3
+ * @subpackage API_Contact
*/
-
class api_v3_ContactTest extends CiviUnitTestCase {
public $DBResetRequired = FALSE;
protected $_apiversion;
protected $_params;
protected $_contactID;
- protected $_financialTypeId =1;
+ protected $_financialTypeId = 1;
/**
* Test setup for every test
);
}
- function tearDown() {
+ public function tearDown() {
// truncate a few tables
$tablesToTruncate = array(
'civicrm_contact',
* Verify that attempt to create individual contact with only
* first and last names succeeds
*/
- function testAddCreateIndividual() {
+ public function testAddCreateIndividual() {
$oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_contact');
$params = array(
'first_name' => 'abc1',
$this->assertTrue(is_numeric($contact['id']), "In line " . __LINE__);
$this->assertTrue($contact['id'] > 0, "In line " . __LINE__);
$newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_contact');
- $this->assertEquals($oldCount+1, $newCount);
+ $this->assertEquals($oldCount + 1, $newCount);
$this->assertDBState('CRM_Contact_DAO_Contact',
$contact['id'],
*
* Verify that sub-types are created successfully and not deleted by subsequent updates
*/
- function testIndividualSubType() {
+ public function testIndividualSubType() {
$params = array(
'first_name' => 'test abc',
'contact_type' => 'Individual',
'last_name' => 'test xyz',
'contact_sub_type' => array('Student', 'Staff'),
- );
+ );
$contact = $this->callAPISuccess('contact', 'create', $params);
$cid = $contact['id'];
/**
* Verify that attempt to create contact with empty params fails
*/
- function testCreateEmptyContact() {
+ public function testCreateEmptyContact() {
$this->callAPIFailure('contact', 'create', array());
}
/**
* Verify that attempt to create contact with bad contact type fails
*/
- function testCreateBadTypeContact() {
+ public function testCreateBadTypeContact() {
$params = array(
'email' => 'man1@yahoo.com',
'contact_type' => 'Does not Exist',
);
- $this->callAPIFailure('contact', 'create', $params,"'Does not Exist' is not a valid option for field contact_type");
+ $this->callAPIFailure('contact', 'create', $params, "'Does not Exist' is not a valid option for field contact_type");
}
/**
* Verify that attempt to create individual contact with required
* fields missing fails
*/
- function testCreateBadRequiredFieldsIndividual() {
+ public function testCreateBadRequiredFieldsIndividual() {
$params = array(
'middle_name' => 'This field is not required',
'contact_type' => 'Individual',
* Verify that attempt to create household contact with required
* fields missing fails
*/
- function testCreateBadRequiredFieldsHousehold() {
+ public function testCreateBadRequiredFieldsHousehold() {
$params = array(
'middle_name' => 'This field is not required',
'contact_type' => 'Household',
* Verify that attempt to create organization contact with
* required fields missing fails
*/
- function testCreateBadRequiredFieldsOrganization() {
+ public function testCreateBadRequiredFieldsOrganization() {
$params = array(
'middle_name' => 'This field is not required',
'contact_type' => 'Organization',
* Verify that attempt to create individual contact with only an
* email succeeds
*/
- function testCreateEmailIndividual() {
+ public function testCreateEmailIndividual() {
$params = array(
'email' => 'man3@yahoo.com',
* Verify that attempt to create individual contact with only
* first and last names succeeds
*/
- function testCreateNameIndividual() {
+ public function testCreateNameIndividual() {
$params = array(
'first_name' => 'abc1',
'contact_type' => 'Individual',
* Verify that attempt to create individual contact with
* first and last names and old key values works
*/
- function testCreateNameIndividualOldKeys() {
+ public function testCreateNameIndividualOldKeys() {
$params = array(
'individual_prefix' => 'Dr.',
'first_name' => 'abc1',
* Verify that attempt to create individual contact with
* first and last names and old key values works
*/
- function testCreateNameIndividualrecommendedKeys2() {
+ public function testCreateNameIndividualrecommendedKeys2() {
$params = array(
'prefix_id' => 'Dr.',
'first_name' => 'abc1',
* Verify that attempt to create household contact with only
* household name succeeds
*/
- function testCreateNameHousehold() {
+ public function testCreateNameHousehold() {
$params = array(
'household_name' => 'The abc Household',
'contact_type' => 'Household',
* Verify that attempt to create organization contact with only
* organization name succeeds
*/
- function testCreateNameOrganization() {
+ public function testCreateNameOrganization() {
$params = array(
'organization_name' => 'The abc Organization',
'contact_type' => 'Organization',
$contact = $this->callAPISuccess('contact', 'create', $params);
$this->assertEquals(1, $contact['id']);
}
+
/**
* Verify that attempt to create organization contact without organization name fails
*/
- function testCreateNoNameOrganization() {
+ public function testCreateNoNameOrganization() {
$params = array(
'first_name' => 'The abc Organization',
'contact_type' => 'Organization',
);
$this->callAPIFailure('contact', 'create', $params);
}
+
/**
* Check with complete array + custom field
* Note that the test is written on purpose without any
* variables specific to participant so it can be replicated into other entities
* and / or moved to the automated test suite
*/
- function testCreateWithCustom() {
+ public function testCreateWithCustom() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
$description = "/*this demonstrates setting a custom field through the API ";
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description);
- $check = $this->callAPISuccess($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id']));
+ $check = $this->callAPISuccess($this->_entity, 'get', array(
+ 'return.custom_' . $ids['custom_field_id'] => 1,
+ 'id' => $result['id'],
+ ));
$this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]);
$this->customFieldDelete($ids['custom_field_id']);
* CRM-12773 - expectation is that civicrm quietly ignores
* fields without values
*/
- function testCreateWithNULLCustomCRM12773() {
+ public function testCreateWithNULLCustomCRM12773() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = NULL;
}
- /*
+ /**
* Test creating a current employer through API
*/
- function testContactCreateCurrentEmployer(){
+ public function testContactCreateCurrentEmployer() {
//here we will just do the get for set-up purposes
$count = $this->callAPISuccess('contact', 'getcount', array(
'organization_name' => 'new employer org',
- 'contact_type' => 'Organization'
+ 'contact_type' => 'Organization',
));
$this->assertEquals(0, $count);
$employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array(
- 'current_employer' => 'new employer org',)
+ 'current_employer' => 'new employer org',
+ )
));
// do it again as an update to check it doesn't cause an error
$employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array(
- 'current_employer' => 'new employer org', 'id' => $employerResult['id'])
+ 'current_employer' => 'new employer org',
+ 'id' => $employerResult['id'],
+ )
));
$expectedCount = 1;
$this->callAPISuccess('contact', 'getcount', array(
- 'organization_name' => 'new employer org',
- 'contact_type' => 'Organization'
- ),
- $expectedCount);
+ 'organization_name' => 'new employer org',
+ 'contact_type' => 'Organization',
+ ),
+ $expectedCount);
$result = $this->callAPISuccess('contact', 'getsingle', array(
'id' => $employerResult['id'],
$this->assertEquals('new employer org', $result['current_employer']);
}
- /*
+
+ /**
* Test creating a current employer through API
* - check it will re-activate a de-activated employer
- */
- function testContactCreateDuplicateCurrentEmployerEnables(){
+ */
+ public function testContactCreateDuplicateCurrentEmployerEnables() {
//set up - create employer relationship
$employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array(
- 'current_employer' => 'new employer org',)
+ 'current_employer' => 'new employer org',
+ )
));
- $relationship = $this->callAPISuccess('relationship','get', array(
+ $relationship = $this->callAPISuccess('relationship', 'get', array(
'contact_id_a' => $employerResult['id'],
- ));
+ ));
//disable & check it is disabled
$this->callAPISuccess('relationship', 'create', array('id' => $relationship['id'], 'is_active' => 0));
- $this->callAPISuccess('relationship','getvalue', array(
+ $this->callAPISuccess('relationship', 'getvalue', array(
'id' => $relationship['id'],
- 'return' => 'is_active'
+ 'return' => 'is_active',
), 0);
//re-set the current employer - thus enabling the relationshp
$this->callAPISuccess('contact', 'create', array_merge($this->_params, array(
- 'current_employer' => 'new employer org', 'id' => $employerResult['id'])
+ 'current_employer' => 'new employer org',
+ 'id' => $employerResult['id'],
+ )
));
//check is_active is now 1
- $relationship = $this->callAPISuccess('relationship','getsingle', array(
- 'return' => 'is_active',));
- $this->assertEquals(1, $relationship['is_active']);
+ $relationship = $this->callAPISuccess('relationship', 'getsingle', array(
+ 'return' => 'is_active',
+ ));
+ $this->assertEquals(1, $relationship['is_active']);
}
/**
* Check deceased contacts are not retrieved
* Note at time of writing the default is to return default. This should possibly be changed & test added
*/
- function testGetDeceasedRetrieved() {
+ public function testGetDeceasedRetrieved() {
$this->callAPISuccess($this->_entity, 'create', $this->_params);
- $c2 = $this->callAPISuccess($this->_entity, 'create', array('first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual', 'is_deceased' => 1));
+ $c2 = $this->callAPISuccess($this->_entity, 'create', array(
+ 'first_name' => 'bb',
+ 'last_name' => 'ccc',
+ 'contact_type' => 'Individual',
+ 'is_deceased' => 1,
+ ));
$result = $this->callAPISuccess($this->_entity, 'get', array('is_deceased' => 0));
$this->assertFalse(array_key_exists($c2['id'], $result['values']));
}
/**
* Test that sort works - old syntax
*/
- function testGetSort() {
+ public function testGetSort() {
$c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $c2 = $this->callAPISuccess($this->_entity, 'create', array('first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual'));
+ $c2 = $this->callAPISuccess($this->_entity, 'create', array(
+ 'first_name' => 'bb',
+ 'last_name' => 'ccc',
+ 'contact_type' => 'Individual',
+ ));
$result = $this->callAPISuccess($this->_entity, 'get', array(
- 'sort' => 'first_name ASC',
- 'return.first_name' => 1,
- 'sequential' => 1,
- 'rowCount' => 1,
- ));
+ 'sort' => 'first_name ASC',
+ 'return.first_name' => 1,
+ 'sequential' => 1,
+ 'rowCount' => 1,
+ ));
$this->assertEquals('abc1', $result['values'][0]['first_name']);
$result = $this->callAPISuccess($this->_entity, 'get', array(
$this->callAPISuccess($this->_entity, 'delete', array('id' => $c1['id']));
$this->callAPISuccess($this->_entity, 'delete', array('id' => $c2['id']));
}
- /*
+
+ /**
* Test that we can retrieve contacts using
* 'id' => array('IN' => array('3,4')) syntax
- */
- function testGetINIDArray() {
+ */
+ public function testGetINIDArray() {
$c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $c2 = $this->callAPISuccess($this->_entity, 'create', array('first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual'));
- $c3 = $this->callAPISuccess($this->_entity, 'create', array('first_name' => 'hh', 'last_name' => 'll', 'contact_type' => 'Individual'));
+ $c2 = $this->callAPISuccess($this->_entity, 'create', array(
+ 'first_name' => 'bb',
+ 'last_name' => 'ccc',
+ 'contact_type' => 'Individual',
+ ));
+ $c3 = $this->callAPISuccess($this->_entity, 'create', array(
+ 'first_name' => 'hh',
+ 'last_name' => 'll',
+ 'contact_type' => 'Individual',
+ ));
$result = $this->callAPISuccess($this->_entity, 'get', array('id' => array('IN' => array($c1['id'], $c3['id']))));
$this->assertEquals(2, $result['count']);
$this->assertEquals(array($c1['id'], $c3['id']), array_keys($result['values']));
$this->callAPISuccess($this->_entity, 'delete', array('id' => $c2['id']));
$this->callAPISuccess($this->_entity, 'delete', array('id' => $c3['id']));
}
- /*
+
+ /**
* Test variants on deleted behaviour
*/
- function testGetDeleted() {
+ public function testGetDeleted() {
$params = $this->_params;
$contact1 = $this->callAPISuccess('contact', 'create', $params);
$params['is_deleted'] = 1;
$countDefault = $this->callAPISuccess('contact', 'getcount', array());
$countDeleted = $this->callAPISuccess('contact', 'getcount', array(
'contact_is_deleted' => 1,
- ));
+ ));
$countNotDeleted = $this->callAPISuccess('contact', 'getcount', array(
'contact_is_deleted' => 0,
- ));
+ ));
$this->callAPISuccess('contact', 'delete', array('id' => $contact1['id']));
$this->callAPISuccess('contact', 'delete', array('id' => $contact2['id']));
$this->assertEquals(1, $countNotDeleted, 'contact_is_deleted => 0 is respected in line ' . __LINE__);
/**
* Test that sort works - new syntax
*/
- function testGetSortNewSYntax() {
- $c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params);
- $c2 = $this->callAPISuccess($this->_entity, 'create', array('first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual'));
+ public function testGetSortNewSYntax() {
+ $c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+ $c2 = $this->callAPISuccess($this->_entity, 'create', array(
+ 'first_name' => 'bb',
+ 'last_name' => 'ccc',
+ 'contact_type' => 'Individual',
+ ));
$result = $this->callAPISuccess($this->_entity, 'getvalue', array(
'return' => 'first_name',
- 'options' => array(
- 'limit' => 1,
- 'sort' => 'first_name',
- ),
- ));
+ 'options' => array(
+ 'limit' => 1,
+ 'sort' => 'first_name',
+ ),
+ ));
$this->assertEquals('abc1', $result, 'in line' . __LINE__);
$result = $this->callAPISuccess($this->_entity, 'getvalue', array(
- 'return' => 'first_name',
- 'options' => array(
- 'limit' => 1,
- 'sort' => 'first_name DESC',
- ),
- ));
+ 'return' => 'first_name',
+ 'options' => array(
+ 'limit' => 1,
+ 'sort' => 'first_name DESC',
+ ),
+ ));
$this->assertEquals('bb', $result);
$this->callAPISuccess($this->_entity, 'delete', array('id' => $c1['id']));
/**
* Test apostrophe works in get & create
*/
- function testGetApostropheCRM10857() {
+ public function testGetApostropheCRM10857() {
$params = array_merge($this->_params, array('last_name' => "O'Connor"));
$this->callAPISuccess($this->_entity, 'create', $params);
$result = $this->callAPISuccess($this->_entity, 'getsingle', array(
* variables specific to participant so it can be replicated into other entities
* and / or moved to the automated test suite
*/
- function testGetWithCustom() {
+ public function testGetWithCustom() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
$subfile = "CustomFieldGet";
$result = $this->callAPISuccess($this->_entity, 'create', $params);
- $check = $this->callAPIAndDocument($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'id' => $result['id']), __FUNCTION__, __FILE__, $description, $subfile);
+ $check = $this->callAPIAndDocument($this->_entity, 'get', array(
+ 'return.custom_' . $ids['custom_field_id'] => 1,
+ 'id' => $result['id'],
+ ), __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']]);
$fields = ($this->callAPISuccess('contact', 'getfields', $params));
* variables specific to participant so it can be replicated into other entities
* and / or moved to the automated test suite
*/
- function testGetWithCustomReturnSyntax() {
+ public function testGetWithCustomReturnSyntax() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
/**
* Check that address name is returned if required
*/
- function testGetReturnAddressName () {
+ public function testGetReturnAddressName() {
$contactID = $this->individualCreate();
- $this->callAPISuccess('address', 'create', array('contact_id' => $contactID, 'address_name' => 'My house', 'location_type_id' => 'Home', 'street_address' => '1 my road'));
- $result = $this->callAPISuccessGetSingle('contact', array('return' => 'address_name, street_address', 'id' => $contactID));
+ $this->callAPISuccess('address', 'create', array(
+ 'contact_id' => $contactID,
+ 'address_name' => 'My house',
+ 'location_type_id' => 'Home',
+ 'street_address' => '1 my road',
+ ));
+ $result = $this->callAPISuccessGetSingle('contact', array(
+ 'return' => 'address_name, street_address',
+ 'id' => $contactID,
+ ));
$this->assertEquals('1 my road', $result['street_address']);
$this->assertEquals('My house', $result['address_name']);
}
- function testGetGroupIDFromContact() {
- $groupId = $this->groupCreate();
+ public function testGetGroupIDFromContact() {
+ $groupId = $this->groupCreate();
$description = "Get all from group and display contacts";
- $subFile = "GroupFilterUsingContactAPI";
- $params = array(
+ $subFile = "GroupFilterUsingContactAPI";
+ $params = array(
'email' => 'man2@yahoo.com',
'contact_type' => 'Individual',
'location_type_id' => 1,
$this->callAPISuccess('contact', 'get', $params);
// testing as string
- $params = array('filter.group_id' => array($groupId, 26),
+ $params = array(
+ 'filter.group_id' => array($groupId, 26),
'contact_type' => 'Individual',
);
$result = $this->callAPIAndDocument('contact', 'get', $params, __FUNCTION__, __FILE__, $description, $subFile);
$this->assertEquals(1, $result['count']);
//test in conjunction with other criteria
- $params = array('filter.group_id' => array($groupId, 26),
+ $params = array(
+ 'filter.group_id' => array($groupId, 26),
'contact_type' => 'Organization',
);
- $this->callAPISuccess('contact', 'get', $params);
- $params = array('filter.group_id' => array(26, 27),
+ $this->callAPISuccess('contact', 'get', $params);
+ $params = array(
+ 'filter.group_id' => array(26, 27),
'contact_type' => 'Individual',
);
$result = $this->callAPISuccess('contact', 'get', $params);
/**
* Verify that attempt to create individual contact with two chained websites succeeds
*/
- function testCreateIndividualWithContributionDottedSyntax() {
+ public function testCreateIndividualWithContributionDottedSyntax() {
$description = "test demonstrates the syntax to create 2 chained entities";
- $subFile = "ChainTwoWebsites";
- $params = array(
+ $subFile = "ChainTwoWebsites";
+ $params = array(
'first_name' => 'abc3',
'last_name' => 'xyz3',
'contact_type' => 'Individual',
'api.contribution.create' => array(
'receive_date' => '2010-01-01',
'total_amount' => 100.00,
- 'financial_type_id' => $this->_financialTypeId,
+ 'financial_type_id' => $this->_financialTypeId,
'payment_instrument_id' => 1,
'non_deductible_amount' => 10.00,
'fee_amount' => 50.00,
/**
* Verify that attempt to create individual contact with chained contribution and website succeeds
*/
- function testCreateIndividualWithContributionChainedArrays() {
+ public function testCreateIndividualWithContributionChainedArrays() {
$params = array(
'first_name' => 'abc3',
'last_name' => 'xyz3',
'api.contribution.create' => array(
'receive_date' => '2010-01-01',
'total_amount' => 100.00,
- 'financial_type_id' => $this->_financialTypeId,
+ 'financial_type_id' => $this->_financialTypeId,
'payment_instrument_id' => 1,
'non_deductible_amount' => 10.00,
'fee_amount' => 50.00,
);
$description = "demonstrates creating two websites as an array";
- $subfile = "ChainTwoWebsitesSyntax2";
- $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
+ $subfile = "ChainTwoWebsitesSyntax2";
+ $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(1, $result['id']);
// the callAndDocument doesn't check the chained call
* Verify that attempt to create individual contact with first
* and last names and email succeeds
*/
- function testCreateIndividualWithNameEmail() {
+ public function testCreateIndividualWithNameEmail() {
$params = array(
'first_name' => 'abc3',
'last_name' => 'xyz3',
// delete the contact
$this->callAPISuccess('contact', 'delete', $contact);
}
+
/**
* Verify that attempt to create individual contact with no data fails
*/
- function testCreateIndividualWithOutNameEmail() {
+ public function testCreateIndividualWithOutNameEmail() {
$params = array(
'contact_type' => 'Individual',
);
$this->callAPIFailure('contact', 'create', $params);
}
+
/**
* Verify that attempt to create individual contact with first
* and last names, email and location type succeeds
*/
- function testCreateIndividualWithNameEmailLocationType() {
+ public function testCreateIndividualWithNameEmailLocationType() {
$params = array(
'first_name' => 'abc4',
'last_name' => 'xyz4',
* Verify that when changing employers
* the old employer relationship becomes inactive
*/
- function testCreateIndividualWithEmployer() {
+ public function testCreateIndividualWithEmployer() {
$employer = $this->organizationCreate();
$employer2 = $this->organizationCreate();
$params = array(
- 'email' => 'man4@yahoo.com',
- 'contact_type' => 'Individual',
- 'employer_id' => $employer,
+ 'email' => 'man4@yahoo.com',
+ 'contact_type' => 'Individual',
+ 'employer_id' => $employer,
);
$result = $this->callAPISuccess('contact', 'create', $params);
'is_active' => 1,
'relationship_type_id' => $relTypeId,
));
- }
+ }
// Add second employer
$params['employer_id'] = $employer2;
* Verify that attempt to create household contact with details
* succeeds
*/
- function testCreateHouseholdDetails() {
+ public function testCreateHouseholdDetails() {
$params = array(
'household_name' => 'abc8\'s House',
'nick_name' => 'x House',
$this->callAPISuccess('contact', 'delete', $contact);
}
+
/**
* Verify that attempt to create household contact with inadequate details
* fails
*/
- function testCreateHouseholdInadequateDetails() {
+ public function testCreateHouseholdInadequateDetails() {
$params = array(
'nick_name' => 'x House',
'email' => 'man8@yahoo.com',
/**
* Verify successful update of individual contact
*/
- function testUpdateIndividualWithAll() {
+ public function testUpdateIndividualWithAll() {
// Insert a row in civicrm_contact creating individual contact
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
/**
* Verify successful update of organization contact
*/
- function testUpdateOrganizationWithAll() {
+ public function testUpdateOrganizationWithAll() {
// Insert a row in civicrm_contact creating organization contact
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
/**
* Verify successful update of household contact
*/
- function testUpdateHouseholdwithAll() {
+ public function testUpdateHouseholdwithAll() {
// Insert a row in civicrm_contact creating household contact
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
)
);
-
-
$params = array(
'id' => 23,
'first_name' => 'abcd',
/**
* Test civicrm_contact_delete() with no contact ID
*/
- function testContactDeleteNoID() {
+ public function testContactDeleteNoID() {
$params = array(
'foo' => 'bar',
);
/**
* Test civicrm_contact_delete() with error
*/
- function testContactDeleteError() {
+ public function testContactDeleteError() {
$params = array('contact_id' => 999);
$this->callAPIFailure('contact', 'delete', $params);
}
/**
* Test civicrm_contact_delete()
*/
- function testContactDelete() {
+ public function testContactDelete() {
$contactID = $this->individualCreate();
$params = array(
- 'id' => $contactID ,
+ 'id' => $contactID,
);
$this->callAPIAndDocument('contact', 'delete', $params, __FUNCTION__, __FILE__);
}
$result = $this->callAPISuccess('contact', 'get', array('birth_date_high' => date('Y-m-d', strtotime('-6 years'))));
$this->assertEquals(1, $result['count']);
$this->assertEquals(date('Y-m-d', strtotime('first day of next month -20 years')), $result['values'][$contact3['id']]['birth_date']);
- $result = $this->callAPISuccess('contact', 'get', array('birth_date_low' => date('Y-m-d', strtotime('-6 years')), 'birth_date_high' => date('Y-m-d', strtotime('- 3 years'))));
+ $result = $this->callAPISuccess('contact', 'get', array(
+ 'birth_date_low' => date('Y-m-d', strtotime('-6 years')),
+ 'birth_date_high' => date('Y-m-d', strtotime('- 3 years')),
+ ));
$this->assertEquals(1, $result['count']);
$this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['birth_date']);
- $result = $this->callAPISuccess('contact', 'get', array('birth_date_low' => '-6 years', 'birth_date_high' => '- 3 years'));
+ $result = $this->callAPISuccess('contact', 'get', array(
+ 'birth_date_low' => '-6 years',
+ 'birth_date_high' => '- 3 years',
+ ));
$this->assertEquals(1, $result['count']);
$this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['birth_date']);
}
$result = $this->callAPISuccess('contact', 'get', array('deceased_date_high' => date('Y-m-d', strtotime('-6 years'))));
$this->assertEquals(1, $result['count']);
$this->assertEquals(date('Y-m-d', strtotime('first day of next month -20 years')), $result['values'][$contact3['id']]['deceased_date']);
- $result = $this->callAPISuccess('contact', 'get', array('deceased_date_low' => '-6 years', 'deceased_date_high' => date('Y-m-d', strtotime('- 3 years'))));
+ $result = $this->callAPISuccess('contact', 'get', array(
+ 'deceased_date_low' => '-6 years',
+ 'deceased_date_high' => date('Y-m-d', strtotime('- 3 years')),
+ ));
$this->assertEquals(1, $result['count']);
$this->assertEquals(date('Y-m-d', strtotime('first day of next month -5 years')), $result['values'][$contact2['id']]['deceased_date']);
}
/**
* Test for Contact.get id=@user:username
*/
- function testContactGetByUsername() {
+ public function testContactGetByUsername() {
// setup - create contact with a uf-match
$cid = $this->individualCreate(array(
'contact_type' => 'Individual',
/**
* Test to check return works OK
*/
- function testContactGetReturnValues() {
+ public function testContactGetReturnValues() {
$extraParams = array('nick_name' => 'Bob', 'phone' => '456', 'email' => 'e@mail.com');
$contactID = $this->individualCreate($extraParams);
//actually it turns out the above doesn't create a phone
- $this->callAPISuccess('phone', 'create', array('contact_id' => $contactID, 'phone' => '456',));
+ $this->callAPISuccess('phone', 'create', array('contact_id' => $contactID, 'phone' => '456'));
$result = $this->callAPISuccess('contact', 'getsingle', array('id' => $contactID));
foreach ($extraParams as $key => $value) {
$this->assertEquals($result[$key], $value);
}
//now we check they are still returned with 'return' key
- $result = $this->callAPISuccess('contact', 'getsingle', array('id' => $contactID, 'return' => array_keys($extraParams)));
+ $result = $this->callAPISuccess('contact', 'getsingle', array(
+ 'id' => $contactID,
+ 'return' => array_keys($extraParams),
+ ));
foreach ($extraParams as $key => $value) {
$this->assertEquals($result[$key], $value);
}
}
- function testCRM13252MultipleChainedPhones() {
+ public function testCRM13252MultipleChainedPhones() {
$contactID = $this->householdCreate();
$this->callAPISuccessGetCount('phone', array('contact_id' => $contactID), 0);
$params = array(
- 'contact_id' => $contactID,
- 'household_name' => 'Household 1',
- 'contact_type' => 'Household',
- 'api.phone.create' => array(
+ 'contact_id' => $contactID,
+ 'household_name' => 'Household 1',
+ 'contact_type' => 'Household',
+ 'api.phone.create' => array(
0 => array(
'phone' => '111-111-1111',
'location_type_id' => 1,
'phone' => '222-222-2222',
'location_type_id' => 1,
'phone_type_id' => 2,
- )
- )
+ ),
+ ),
);
$this->callAPISuccess('contact', 'create', $params);
$this->callAPISuccessGetCount('phone', array('contact_id' => $contactID), 2);
}
+
/**
* Test for Contact.get id=@user:username (with an invalid username)
*/
- function testContactGetByUnknownUsername() {
+ public function testContactGetByUnknownUsername() {
// setup - mock the calls to CRM_Utils_System_*::getUfId
$userSystem = $this->getMock('CRM_Utils_System_UnitTests', array('getUfId'));
$userSystem->expects($this->once())
/**
* Verify attempt to create individual with chained arrays
*/
- function testGetIndividualWithChainedArrays() {
+ public function testGetIndividualWithChainedArrays() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params['custom_' . $ids['custom_field_id']] = "custom string";
- $moreids = $this->CustomGroupMultipleCreateWithFields();
+ $moreids = $this->CustomGroupMultipleCreateWithFields();
$description = "/*this demonstrates the usage of chained api functions. In this case no notes or custom fields have been created ";
- $subfile = "APIChainedArray";
- $params = array(
+ $subfile = "APIChainedArray";
+ $params = array(
'first_name' => 'abc3',
'last_name' => 'xyz3',
'contact_type' => 'Individual',
'api.contribution.create.1' => array(
'receive_date' => '2011-01-01',
'total_amount' => 120.00,
- 'financial_type_id' => $this->_financialTypeId =1,
+ 'financial_type_id' => $this->_financialTypeId = 1,
'payment_instrument_id' => 1,
'non_deductible_amount' => 10.00,
'fee_amount' => 50.00,
'api.website.get' => array(),
'api.Contribution.get' => array(
'total_amount' => '120.00',
- ), 'api.CustomValue.get' => 1,
+ ),
+ 'api.CustomValue.get' => 1,
'api.Note.get' => 1,
);
$result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals("http://civicrm.org", $result['values'][$result['id']]['api.website.get']['values'][0]['url']);
}
- function testGetIndividualWithChainedArraysFormats() {
+ public function testGetIndividualWithChainedArraysFormats() {
$description = "/*this demonstrates the usage of chained api functions. A variety of return formats are used. Note that no notes
*custom fields or memberships exist";
$subfile = "APIChainedArrayFormats";
),
);
-
$result = $this->callAPISuccess('Contact', 'create', $params);
$params = array(
'id' => $result['id'],
$this->customGroupDelete($moreids['custom_group_id']);
}
- function testGetIndividualWithChainedArraysAndMultipleCustom() {
+ public function testGetIndividualWithChainedArraysAndMultipleCustom() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params['custom_' . $ids['custom_field_id']] = "custom string";
$moreids = $this->CustomGroupMultipleCreateWithFields();
- $andmoreids = $this->CustomGroupMultipleCreateWithFields(array('title' => "another group", 'name' => 'another name'));
+ $andmoreids = $this->CustomGroupMultipleCreateWithFields(array(
+ 'title' => "another group",
+ 'name' => 'another name',
+ ));
$description = "/*this demonstrates the usage of chained api functions. A variety of techniques are used";
$subfile = "APIChainedArrayMultipleCustom";
$params = array(
'api.contribution.create' => array(
'receive_date' => '2010-01-01',
'total_amount' => 100.00,
- 'financial_type_id' => 1,
+ 'financial_type_id' => 1,
'payment_instrument_id' => 1,
'non_deductible_amount' => 10.00,
'fee_amount' => 50.00,
'api.contribution.create.1' => array(
'receive_date' => '2011-01-01',
'total_amount' => 120.00,
- 'financial_type_id' => 1,
+ 'financial_type_id' => 1,
'payment_instrument_id' => 1,
'non_deductible_amount' => 10.00,
'fee_amount' => 50.00,
'custom_' . $andmoreids['custom_field_id'][1] => "vegemite",
);
-
$result = $this->callAPISuccess('Contact', 'create', $params);
$result = $this->callAPISuccess('Contact', 'create', array(
- 'contact_type' => 'Individual', 'id' => $result['id'], 'custom_' . $moreids['custom_field_id'][0] => "value 3", 'custom_' . $ids['custom_field_id'] => "value 4",
- ));
+ 'contact_type' => 'Individual',
+ 'id' => $result['id'],
+ 'custom_' .
+ $moreids['custom_field_id'][0] => "value 3",
+ 'custom_' .
+ $ids['custom_field_id'] => "value 4",
+ ));
$params = array(
'id' => $result['id'],
$this->assertEquals(0, $result['values'][$result['id']]['api.CustomValue.get']['is_error']);
$this->assertEquals('http://civicrm.org', $result['values'][$result['id']]['api.website.getValue']);
}
- /*
+
+ /**
* Test checks siusage of $values to pick & choose inputs
*/
- function testChainingValuesCreate() {
+ public function testChainingValuesCreate() {
$description = "/*this demonstrates the usage of chained api functions. Specifically it has one 'parent function' &
2 child functions - one receives values from the parent (Contact) and the other child (Tag). ";
$subfile = "APIChainedArrayValuesFromSiblingFunction";
$params = array(
- 'display_name' => 'batman', 'contact_type' => 'Individual',
+ 'display_name' => 'batman',
+ 'contact_type' => 'Individual',
'api.tag.create' => array('name' => '$value.id', 'description' => '$value.display_name', 'format.only_id' => 1),
'api.entity_tag.create' => array('tag_id' => '$value.api.tag.create'),
);
$this->quickCleanup($tablesToTruncate, TRUE);
}
- /*
+ /**
* test TrueFalse format - I couldn't come up with an easy way to get an error on Get
*/
- function testContactGetFormatIsSuccessTrue() {
+ public function testContactGetFormatIsSuccessTrue() {
$this->createContactFromXML();
$description = "This demonstrates use of the 'format.is_success' param.
This param causes only the success or otherwise of the function to be returned as BOOLEAN";
$subfile = "FormatIsSuccess_True";
- $params = array('id' => 17, 'format.is_success' => 1);
- $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
+ $params = array('id' => 17, 'format.is_success' => 1);
+ $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(1, $result);
$this->callAPISuccess('Contact', 'Delete', $params);
}
- /*
+
+ /**
* test TrueFalse format
*/
- function testContactCreateFormatIsSuccessFalse() {
+ public function testContactCreateFormatIsSuccessFalse() {
$description = "This demonstrates use of the 'format.is_success' param.
This param causes only the success or otherwise of the function to be returned as BOOLEAN";
$subfile = "FormatIsSuccess_Fail";
- $params = array('id' => 500, 'format.is_success' => 1);
- $result = $this->callAPIAndDocument('Contact', 'Create', $params, __FUNCTION__, __FILE__, $description, $subfile);
+ $params = array('id' => 500, 'format.is_success' => 1);
+ $result = $this->callAPIAndDocument('Contact', 'Create', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals(0, $result);
}
- /*
+
+ /**
* test Single Entity format
*/
- function testContactGetSingle_entity_array() {
+ public function testContactGetSingle_entity_array() {
$this->createContactFromXML();
$description = "This demonstrates use of the 'format.single_entity_array' param.
/* This param causes the only contact to be returned as an array without the other levels.
/* it will be ignored if there is not exactly 1 result";
$subfile = "GetSingleContact";
- $params = array('id' => 17);
- $result = $this->callAPIAndDocument('Contact', 'GetSingle', $params, __FUNCTION__, __FILE__, $description, $subfile);
+ $params = array('id' => 17);
+ $result = $this->callAPIAndDocument('Contact', 'GetSingle', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals('Test Contact', $result['display_name']);
$this->callAPISuccess('Contact', 'Delete', $params);
}
- /*
+ /**
* test Single Entity format
*/
- function testContactGetFormatcount_only() {
+ public function testContactGetFormatcount_only() {
$this->createContactFromXML();
$description = "/*This demonstrates use of the 'getCount' action
/* This param causes the count of the only function to be returned as an integer";
$subfile = "GetCountContact";
- $params = array('id' => 17);
- $result = $this->callAPIAndDocument('Contact', 'GetCount', $params, __FUNCTION__, __FILE__, $description, $subfile);
+ $params = array('id' => 17);
+ $result = $this->callAPIAndDocument('Contact', 'GetCount', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals('1', $result);
$this->callAPISuccess('Contact', 'Delete', $params);
}
- /*
+
+ /**
* Test id only format
*/
- function testContactGetFormatID_only() {
+ public function testContactGetFormatID_only() {
$this->createContactFromXML();
$description = "This demonstrates use of the 'format.id_only' param.
/* This param causes the id of the only entity to be returned as an integer.
/* it will be ignored if there is not exactly 1 result";
$subfile = "FormatOnlyID";
- $params = array('id' => 17, 'format.only_id' => 1);
- $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
+ $params = array('id' => 17, 'format.only_id' => 1);
+ $result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->assertEquals('17', $result);
$this->callAPISuccess('Contact', 'Delete', $params);
}
- /*
+ /**
* Test id only format
*/
- function testContactGetFormatSingleValue() {
+ public function testContactGetFormatSingleValue() {
$this->createContactFromXML();
$description = "This demonstrates use of the 'format.single_value' param.
/* This param causes only a single value of the only entity to be returned as an string.
/* it will be ignored if there is not exactly 1 result";
$subFile = "FormatSingleValue";
- $params = array('id' => 17, 'return' => 'display_name');
- $result = $this->callAPIAndDocument('Contact', 'getvalue', $params, __FUNCTION__, __FILE__, $description, $subFile,'getvalue');
+ $params = array('id' => 17, 'return' => 'display_name');
+ $result = $this->callAPIAndDocument('Contact', 'getvalue', $params, __FUNCTION__, __FILE__, $description, $subFile, 'getvalue');
$this->assertEquals('Test Contact', $result);
$this->callAPISuccess('Contact', 'Delete', $params);
}
/**
* Test that permissions are respected when creating contacts
*/
- function testContactCreationPermissions() {
+ public function testContactCreationPermissions() {
$params = array(
- 'contact_type' => 'Individual', 'first_name' => 'Foo',
+ 'contact_type' => 'Individual',
+ 'first_name' => 'Foo',
'last_name' => 'Bear',
'check_permissions' => TRUE,
);
$this->callAPISuccess('contact', 'create', $params, NULL, 'overfluous permissions should be enough to create a contact');
}
- function testContactUpdatePermissions() {
- $params = array('contact_type' => 'Individual', 'first_name' => 'Foo', 'last_name' => 'Bear', 'check_permissions' => TRUE,);
+ public function testContactUpdatePermissions() {
+ $params = array(
+ 'contact_type' => 'Individual',
+ 'first_name' => 'Foo',
+ 'last_name' => 'Bear',
+ 'check_permissions' => TRUE,
+ );
$result = $this->callAPISuccess('contact', 'create', $params);
$config = CRM_Core_Config::singleton();
- $params = array('id' => $result['id'], 'contact_type' => 'Individual', 'last_name' => 'Bar', 'check_permissions' => TRUE,);
+ $params = array(
+ 'id' => $result['id'],
+ 'contact_type' => 'Individual',
+ 'last_name' => 'Bar',
+ 'check_permissions' => TRUE,
+ );
$config->userPermissionClass->permissions = array('access CiviCRM');
$result = $this->callAPIFailure('contact', 'update', $params);
$this->assertEquals('API permission check failed for contact/update call; insufficient permission: require access CiviCRM and edit all contacts', $result['error_message'], 'lacking permissions should not be enough to update a contact');
- $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'view all contacts', 'edit all contacts', 'import contacts');
+ $config->userPermissionClass->permissions = array(
+ 'access CiviCRM',
+ 'add contacts',
+ 'view all contacts',
+ 'edit all contacts',
+ 'import contacts',
+ );
$this->callAPISuccess('contact', 'update', $params, NULL, 'overfluous permissions should be enough to update a contact');
}
- function createContactFromXML() {
+ public function createContactFromXML() {
// Insert a row in civicrm_contact creating contact 17
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
);
}
- function testContactProximity() {
+ public function testContactProximity() {
// first create a contact with a SF location with a specific
// geocode
$contactID = $this->organizationCreate();
* Test that Ajax API permission is sufficient to access getquick api
* (note that getquick api is required for autocomplete & has ACL permissions applied)
*/
- function testGetquickPermission_CRM_13744() {
+ public function testGetquickPermission_CRM_13744() {
CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviEvent');
$this->callAPIFailure('contact', 'getquick', array('name' => 'b', 'check_permissions' => TRUE));
CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
/**
* Test get ref api - gets a list of references to an entity
*/
- function testGetReferenceCounts() {
+ public function testGetReferenceCounts() {
$result = $this->callAPISuccess('Contact', 'create', array(
'first_name' => 'Testily',
'last_name' => 'McHaste',
'email' => 'spam@dev.null',
'is_primary' => 0,
'location_type_id' => 1,
- )
+ ),
),
),
'api.Phone.replace' => array(
//$refCountsIdx = CRM_Utils_Array::index(array('name'), $refCounts);
$refCounts = $this->callAPISuccess('Contact', 'getrefcount', array(
- 'id' => $result['id']
+ 'id' => $result['id'],
));
$refCountsIdx = CRM_Utils_Array::index(array('name'), $refCounts['values']);
$this->assertTrue(!isset($refCountsIdx['sql:civicrm_address:contact_id']));
}
- function testSQLOperatorsOnContactAPI() {
+ public function testSQLOperatorsOnContactAPI() {
$this->individualCreate();
$this->organizationCreate();
$this->householdCreate();
/**
* CRM-14743 - test api respects search operators
*/
- function testGetModifiedDateByOperators() {
+ public function testGetModifiedDateByOperators() {
$preExistingContactCount = CRM_Core_DAO::singleValueQuery('select count(*) FROM civicrm_contact');
$contact1 = $this->individualCreate();
$sql = "UPDATE civicrm_contact SET created_date = '2012-01-01', modified_date = '2013-01-01' WHERE id = " . $contact1;
/**
* CRM-14743 - test api respects search operators
*/
- function testGetCreatedDateByOperators() {
+ public function testGetCreatedDateByOperators() {
$preExistingContactCount = CRM_Core_DAO::singleValueQuery('select count(*) FROM civicrm_contact');
$contact1 = $this->individualCreate();
$sql = "UPDATE civicrm_contact SET created_date = '2012-01-01' WHERE id = " . $contact1;
/**
* CRM-14263 check that API is not affected by search profile related bug
*/
- function testReturnCityProfile () {
+ public function testReturnCityProfile() {
$contactID = $this->individualCreate();
CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
- $this->callAPISuccess('address', 'create', array('contact_id' => $contactID, 'city' => 'Cool City', 'location_type_id' => 1,));
+ $this->callAPISuccess('address', 'create', array(
+ 'contact_id' => $contactID,
+ 'city' => 'Cool City',
+ 'location_type_id' => 1,
+ ));
$result = $this->callAPISuccess('contact', 'get', array('city' => 'Cool City', 'return' => 'contact_type'));
$this->assertEquals(1, $result['count']);
}
/**
* CRM-15443 - ensure getlist api does not return deleted contacts
*/
- function testGetlistExcludeConditions() {
+ public function testGetlistExcludeConditions() {
$name = md5(time());
$contact = $this->individualCreate(array('last_name' => $name));
$deceasedContact = $this->individualCreate(array('last_name' => $name, 'is_deceased' => 1));
$result = $this->callAPISuccess('contact', 'getlist', array('input' => $name));
$this->assertEquals(2, $result['count'], 'In line ' . __LINE__);
// Force-exclude the deceased contact
- $result = $this->callAPISuccess('contact', 'getlist', array('input' => $name, 'params' => array('is_deceased' => 0)));
+ $result = $this->callAPISuccess('contact', 'getlist', array(
+ 'input' => $name,
+ 'params' => array('is_deceased' => 0),
+ ));
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->assertEquals($contact, $result['values'][0]['id'], 'In line ' . __LINE__);
}
/**
* Test contact.getactions
*/
- function testGetActions() {
+ public function testGetActions() {
$description = "Getting the available actions for an entity.";
$result = $this->callAPIAndDocument($this->_entity, 'getactions', array(), __FUNCTION__, __FILE__, $description);
$expected = array(