<?php
/**
- * File for the TestContact class
+ * @file
+ * File for the TestContact class.
*
* (PHP 5)
*
protected $_financialTypeId = 1;
/**
- * Test setup for every test
+ * Test setup for every test.
*
- * Connect to the database, truncate the tables that will be used
- * and redirect stdin to a temporary file
+ * Connect to the database, truncate the tables that will be used
+ * and redirect stdin to a temporary file
*/
public function setUp() {
- // Connect to the database
+ // Connect to the database.
parent::setUp();
$this->_apiversion = 3;
$this->_entity = 'contact';
}
/**
- * Test civicrm_contact_create
+ * Test civicrm_contact_create.
*
- * Verify that attempt to create individual contact with only
- * first and last names succeeds
+ * Verify that attempt to create individual contact with only
+ * first and last names succeeds
*/
public function testAddCreateIndividual() {
$oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_contact');
);
$contact = $this->callAPISuccess('contact', 'create', $params);
- $this->assertTrue(is_numeric($contact['id']), "In line " . __LINE__);
- $this->assertTrue($contact['id'] > 0, "In line " . __LINE__);
+ $this->assertTrue(is_numeric($contact['id']));
+ $this->assertTrue($contact['id'] > 0);
$newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_contact');
$this->assertEquals($oldCount + 1, $newCount);
}
/**
- * Test civicrm_contact_create with sub-types
+ * Test civicrm_contact_create with sub-types.
*
- * Verify that sub-types are created successfully and not deleted by subsequent updates
+ * Verify that sub-types are created successfully and not deleted by subsequent updates.
*/
public function testIndividualSubType() {
$params = array(
$contact = $this->callAPISuccess('contact', 'get', $params);
- $this->assertEquals(array('Student', 'Staff'), $contact['values'][$cid]['contact_sub_type'], "In line " . __LINE__);
+ $this->assertEquals(array('Student', 'Staff'), $contact['values'][$cid]['contact_sub_type']);
}
/**
- * Verify that attempt to create contact with empty params fails
+ * Verify that attempt to create contact with empty params fails.
*/
public function testCreateEmptyContact() {
$this->callAPIFailure('contact', 'create', array());
}
/**
- * Verify that attempt to create contact with bad contact type fails
+ * Verify that attempt to create contact with bad contact type fails.
*/
public function testCreateBadTypeContact() {
$params = array(
}
/**
- * Verify that attempt to create individual contact with required
- * fields missing fails
+ * Verify that attempt to create individual contact without required fields fails.
*/
public function testCreateBadRequiredFieldsIndividual() {
$params = array(
}
/**
- * Verify that attempt to create household contact with required
- * fields missing fails
+ * Verify that attempt to create household contact without required fields fails.
*/
public function testCreateBadRequiredFieldsHousehold() {
$params = array(
}
/**
- * Verify that attempt to create organization contact with
- * required fields missing fails
+ * Test required field check.
+ *
+ * Verify that attempt to create organization contact without required fields fails.
*/
public function testCreateBadRequiredFieldsOrganization() {
$params = array(
}
/**
- * Verify that attempt to create individual contact with only an
- * email succeeds
+ * Verify that attempt to create individual contact with only an email succeeds.
*/
public function testCreateEmailIndividual() {
$contact = $this->callAPISuccess('contact', 'create', $params);
- $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
+ $this->assertEquals(1, $contact['id']);
$email = $this->callAPISuccess('email', 'get', array('contact_id' => $contact['id']));
$this->assertEquals(1, $email['count']);
$this->assertEquals('man3@yahoo.com', $email['values'][$email['id']]['email']);
}
/**
- * Verify that attempt to create individual contact with only
- * first and last names succeeds
+ * Test creating individual by name.
+ *
+ * Verify create individual contact with only first and last names succeeds.
*/
public function testCreateNameIndividual() {
$params = array(
}
/**
- * Verify that attempt to create individual contact with
- * first and last names and old key values works
+ * Test old keys still work.
+ *
+ * Verify that attempt to create individual contact with
+ * first and last names and old key values works
*/
public function testCreateNameIndividualOldKeys() {
$params = array(
}
/**
- * Verify that attempt to create individual contact with
- * first and last names and old key values works
+ * Test preferred keys work.
+ *
+ * Verify that attempt to create individual contact with
+ * first and last names and old key values works
*/
- public 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
+ * Test household name is sufficient for create.
+ *
+ * Verify that attempt to create household contact with only
+ * household name succeeds
*/
public function testCreateNameHousehold() {
$params = array(
'contact_type' => 'Household',
);
$contact = $this->callAPISuccess('contact', 'create', $params);
- $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
+ $this->assertEquals(1, $contact['id']);
}
/**
- * Verify that attempt to create organization contact with only
- * organization name succeeds
+ * Test organization name is sufficient for create.
+ *
+ * Verify that attempt to create organization contact with only
+ * organization name succeeds.
*/
public function testCreateNameOrganization() {
$params = array(
}
/**
- * Verify that attempt to create organization contact without organization name fails
+ * Verify that attempt to create organization contact without organization name fails.
*/
public function testCreateNoNameOrganization() {
$params = array(
}
/**
- * Check with complete array + custom field
+ * 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
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
- $description = "/*this demonstrates setting a custom field through the API ";
+ $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(
}
/**
- * CRM-12773 - expectation is that civicrm quietly ignores
- * fields without values
+ * CRM-12773 - expectation is that civicrm quietly ignores fields without values.
*/
public function testCreateWithNULLCustomCRM12773() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$this->customGroupDelete($ids['custom_group_id']);
}
+ /**
+ * CRM-15792 - create/update datetime field for contact.
+ */
+ public function testCreateContactCustomFldDateTime() {
+ $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'datetime_test_group'));
+ $dateTime = CRM_Utils_Date::currentDBDate();
+ //check date custom field is saved along with time when time_format is set
+ $params = array(
+ 'first_name' => 'abc3',
+ 'last_name' => 'xyz3',
+ 'contact_type' => 'Individual',
+ 'email' => 'man3@yahoo.com',
+ 'api.CustomField.create' => array(
+ 'custom_group_id' => $customGroup['id'],
+ 'name' => 'test_datetime',
+ 'label' => 'Demo Date',
+ 'html_type' => 'Select Date',
+ 'data_type' => 'Date',
+ 'time_format' => 2,
+ 'weight' => 4,
+ 'is_required' => 1,
+ 'is_searchable' => 0,
+ 'is_active' => 1,
+ ),
+ );
+
+ $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__);
+ $customFldId = $result['values'][$result['id']]['api.CustomField.create']['id'];
+ $this->assertNotNull($result['id'], 'in line ' . __LINE__);
+ $this->assertNotNull($customFldId, 'in line ' . __LINE__);
+
+ $params = array(
+ 'id' => $result['id'],
+ "custom_{$customFldId}" => $dateTime,
+ 'api.CustomValue.get' => 1,
+ );
+
+ $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__);
+ $this->assertNotNull($result['id'], 'in line ' . __LINE__);
+ $customFldDate = date("YmdHis", strtotime($result['values'][$result['id']]['api.CustomValue.get']['values'][0]['latest']));
+ $this->assertNotNull($customFldDate, 'in line ' . __LINE__);
+ $this->assertEquals($dateTime, $customFldDate);
+ $customValueId = $result['values'][$result['id']]['api.CustomValue.get']['values'][0]['id'];
+ $dateTime = date('Ymd');
+ //date custom field should not contain time part when time_format is null
+ $params = array(
+ 'id' => $result['id'],
+ 'api.CustomField.create' => array(
+ 'id' => $customFldId,
+ 'html_type' => 'Select Date',
+ 'data_type' => 'Date',
+ 'time_format' => '',
+ ),
+ 'api.CustomValue.create' => array(
+ 'id' => $customValueId,
+ 'entity_id' => $result['id'],
+ "custom_{$customFldId}" => $dateTime,
+ ),
+ 'api.CustomValue.get' => 1,
+ );
+ $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__);
+ $this->assertNotNull($result['id'], 'in line ' . __LINE__);
+ $customFldDate = date("Ymd", strtotime($result['values'][$result['id']]['api.CustomValue.get']['values'][0]['latest']));
+ $customFldTime = date("His", strtotime($result['values'][$result['id']]['api.CustomValue.get']['values'][0]['latest']));
+ $this->assertNotNull($customFldDate, 'in line ' . __LINE__);
+ $this->assertEquals($dateTime, $customFldDate);
+ $this->assertEquals(000000, $customFldTime);
+ $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__);
+ }
+
/**
- * Test creating a current employer through API
+ * Test creating a current employer through API.
*/
public function testContactCreateCurrentEmployer() {
- //here we will just do the get for set-up purposes
+ // 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',
}
/**
- * Test creating a current employer through API
- * - check it will re-activate a de-activated employer
+ * Test creating a current employer through API.
+ *
+ * Check it will re-activate a de-activated employer
*/
public function testContactCreateDuplicateCurrentEmployerEnables() {
- //set up - create employer relationship
+ // Set up - create employer relationship.
$employerResult = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array(
'current_employer' => 'new employer org',
)
'return' => 'is_active',
), 0);
- //re-set the current employer - thus enabling the relationshp
+ // Re-set the current employer - thus enabling the relationship.
$this->callAPISuccess('contact', 'create', array_merge($this->_params, array(
'current_employer' => 'new employer org',
'id' => $employerResult['id'],
}
/**
- * Check deceased contacts are not retrieved
- * Note at time of writing the default is to return default. This should possibly be changed & test added
+ * Check deceased contacts are not retrieved.
+ *
+ * Note at time of writing the default is to return default. This should possibly be changed & test added.
*/
public function testGetDeceasedRetrieved() {
$this->callAPISuccess($this->_entity, 'create', $this->_params);
}
/**
- * Test that sort works - old syntax
+ * Test that sort works - old syntax.
*/
public function testGetSort() {
$c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params);
}
/**
- * Test that we can retrieve contacts using
- * 'id' => array('IN' => array('3,4')) syntax
+ * Test that we can retrieve contacts using array syntax.
+ *
+ * I.e 'id' => array('IN' => array('3,4')).
*/
public function testGetINIDArray() {
$c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params);
}
/**
- * Test variants on deleted behaviour
+ * Test variants on deleted behaviour.
*/
public function testGetDeleted() {
$params = $this->_params;
$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__);
- $this->assertEquals(1, $countActive, 'in line ' . __LINE__);
- $this->assertEquals(1, $countTrash, 'in line ' . __LINE__);
- $this->assertEquals(2, $countAll, 'in line ' . __LINE__);
- $this->assertEquals(1, $countDeleted, 'in line ' . __LINE__);
+ $this->assertEquals(1, $countActive);
+ $this->assertEquals(1, $countTrash);
+ $this->assertEquals(2, $countAll);
+ $this->assertEquals(1, $countDeleted);
$this->assertEquals(1, $countDefault, 'Only active by default in line ' . __LINE__);
}
/**
- * Test that sort works - new syntax
+ * Test that sort works - new syntax.
*/
- public function testGetSortNewSYntax() {
+ public function testGetSortNewSyntax() {
$c1 = $this->callAPISuccess($this->_entity, 'create', $this->_params);
$c2 = $this->callAPISuccess($this->_entity, 'create', array(
'first_name' => 'bb',
}
/**
- * Test apostrophe works in get & create
+ * Test sort and limit for chained relationship get.
+ *
+ * https://issues.civicrm.org/jira/browse/CRM-15983
+ */
+ public function testSortLimitChainedRelationshipGetCRM15983() {
+ // Some contact
+ $create_result_1 = $this->callAPISuccess('contact', 'create', array(
+ 'first_name' => 'Jules',
+ 'last_name' => 'Smos',
+ 'contact_type' => 'Individual',
+ ));
+
+ // Create another contact with two relationships.
+ $create_params = array(
+ 'first_name' => 'Jos',
+ 'last_name' => 'Smos',
+ 'contact_type' => 'Individual',
+ 'api.relationship.create' => array(
+ array(
+ 'contact_id_a' => '$value.id',
+ 'contact_id_b' => $create_result_1['id'],
+ // spouse of:
+ 'relationship_type_id' => 2,
+ 'start_date' => '2005-01-12',
+ 'end_date' => '2006-01-11',
+ 'description' => 'old',
+ ),
+ array(
+ 'contact_id_a' => '$value.id',
+ 'contact_id_b' => $create_result_1['id'],
+ // spouse of (was married twice :))
+ 'relationship_type_id' => 2,
+ 'start_date' => '2006-07-01',
+ 'end_date' => '2010-07-01',
+ 'description' => 'new',
+ ),
+ ),
+ );
+ $create_result = $this->callAPISuccess('contact', 'create', $create_params);
+
+ // Try to retrieve the contact and the most recent relationship.
+ $get_params = array(
+ 'sequential' => 1,
+ 'id' => $create_result['id'],
+ 'api.relationship.get' => array(
+ 'contact_id_a' => '$value.id',
+ 'options' => array(
+ 'limit' => '1',
+ 'sort' => 'start_date DESC',
+ )),
+ );
+ $get_result = $this->callAPISuccess('contact', 'getsingle', $get_params);
+
+ // Clean up.
+ $this->callAPISuccess('contact', 'delete', array(
+ 'id' => $create_result['id'],
+ ));
+
+ // Assert.
+ $this->assertEquals(1, $get_result['api.relationship.get']['count']);
+ $this->assertEquals('new', $get_result['api.relationship.get']['values'][0]['description']);
+ }
+
+ /**
+ * Test apostrophe works in get & create.
*/
public function testGetApostropheCRM10857() {
$params = array_merge($this->_params, array('last_name' => "O'Connor"));
}
/**
- * Check with complete array + custom field
+ * 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
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
- $description = "/*this demonstrates setting a custom field through the API ";
+ $description = "This demonstrates setting a custom field through the API.";
$subfile = "CustomFieldGet";
$result = $this->callAPISuccess($this->_entity, 'create', $params);
}
/**
- * Check with complete array + custom field
+ * 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
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
- $description = "/*this demonstrates setting a custom field through the API ";
+ $description = "This demonstrates setting a custom field through the API.";
$subfile = "CustomFieldGetReturnSyntaxVariation";
$result = $this->callAPISuccess($this->_entity, 'create', $params);
$params = array('return' => 'custom_' . $ids['custom_field_id'], 'id' => $result['id']);
}
/**
- * Check that address name is returned if required
+ * Check that address name is returned if required.
*/
public function testGetReturnAddressName() {
$contactID = $this->individualCreate();
public function testGetGroupIDFromContact() {
$groupId = $this->groupCreate();
- $description = "Get all from group and display contacts";
+ $description = "Get all from group and display contacts.";
$subFile = "GroupFilterUsingContactAPI";
$params = array(
'email' => 'man2@yahoo.com',
}
/**
- * Verify that attempt to create individual contact with two chained websites succeeds
+ * Verify that attempt to create individual contact with two chained websites succeeds.
*/
public function testCreateIndividualWithContributionDottedSyntax() {
- $description = "test demonstrates the syntax to create 2 chained entities";
+ $description = "This demonstrates the syntax to create 2 chained entities.";
$subFile = "ChainTwoWebsites";
$params = array(
'first_name' => 'abc3',
$result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__, $description, $subFile);
- $this->assertEquals(1, $result['id'], "In line " . __LINE__);
+ $this->assertEquals(1, $result['id']);
// checking child function result not covered in callAPIAndDocument
$this->assertAPISuccess($result['values'][$result['id']]['api.website.create']);
- $this->assertEquals("http://chained.org", $result['values'][$result['id']]['api.website.create.2']['values'][0]['url'], "In line " . __LINE__);
- $this->assertEquals("http://civicrm.org", $result['values'][$result['id']]['api.website.create']['values'][0]['url'], "In line " . __LINE__);
+ $this->assertEquals("http://chained.org", $result['values'][$result['id']]['api.website.create.2']['values'][0]['url']);
+ $this->assertEquals("http://civicrm.org", $result['values'][$result['id']]['api.website.create']['values'][0]['url']);
// delete the contact
$this->callAPISuccess('contact', 'delete', $result);
}
/**
- * Verify that attempt to create individual contact with chained contribution and website succeeds
+ * Verify that attempt to create individual contact with chained contribution and website succeeds.
*/
public function testCreateIndividualWithContributionChainedArrays() {
$params = array(
),
);
- $description = "demonstrates creating two websites as an array";
+ $description = "Demonstrates creating two websites as an array.";
$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
- $this->assertEquals(0, $result['values'][$result['id']]['api.website.create'][0]['is_error'], "In line " . __LINE__);
- $this->assertEquals("http://chained.org", $result['values'][$result['id']]['api.website.create'][1]['values'][0]['url'], "In line " . __LINE__);
- $this->assertEquals("http://civicrm.org", $result['values'][$result['id']]['api.website.create'][0]['values'][0]['url'], "In line " . __LINE__);
+ $this->assertEquals(0, $result['values'][$result['id']]['api.website.create'][0]['is_error']);
+ $this->assertEquals("http://chained.org", $result['values'][$result['id']]['api.website.create'][1]['values'][0]['url']);
+ $this->assertEquals("http://civicrm.org", $result['values'][$result['id']]['api.website.create'][0]['values'][0]['url']);
$this->callAPISuccess('contact', 'delete', $result);
}
/**
- * Verify that attempt to create individual contact with first
- * and last names and email succeeds
+ * Test for direction when chaining relationships.
+ *
+ * https://issues.civicrm.org/jira/browse/CRM-16084
+ */
+ public function testDirectionChainingRelationshipsCRM16084() {
+ // Some contact, called Jules.
+ $create_result_1 = $this->callAPISuccess('contact', 'create', array(
+ 'first_name' => 'Jules',
+ 'last_name' => 'Smos',
+ 'contact_type' => 'Individual',
+ ));
+
+ // Another contact: Jos, child of Jules.
+ $create_params = array(
+ 'first_name' => 'Jos',
+ 'last_name' => 'Smos',
+ 'contact_type' => 'Individual',
+ 'api.relationship.create' => array(
+ array(
+ 'contact_id_a' => '$value.id',
+ 'contact_id_b' => $create_result_1['id'],
+ // child of
+ 'relationship_type_id' => 1,
+ ),
+ ),
+ );
+ $create_result_2 = $this->callAPISuccess('contact', 'create', $create_params);
+
+ // Mia is the child of Jos.
+ $create_params = array(
+ 'first_name' => 'Mia',
+ 'last_name' => 'Smos',
+ 'contact_type' => 'Individual',
+ 'api.relationship.create' => array(
+ array(
+ 'contact_id_a' => '$value.id',
+ 'contact_id_b' => $create_result_2['id'],
+ // child of
+ 'relationship_type_id' => 1,
+ ),
+ ),
+ );
+ $create_result_3 = $this->callAPISuccess('contact', 'create', $create_params);
+
+ // Get Jos and his children.
+ $get_params = array(
+ 'sequential' => 1,
+ 'id' => $create_result_2['id'],
+ 'api.relationship.get' => array(
+ 'contact_id_b' => '$value.id',
+ 'relationship_type_id' => 1,
+ ),
+ );
+ $get_result = $this->callAPISuccess('contact', 'getsingle', $get_params);
+
+ // Clean up first.
+ $this->callAPISuccess('contact', 'delete', array(
+ 'id' => $create_result_1['id'],
+ ));
+ $this->callAPISuccess('contact', 'delete', array(
+ 'id' => $create_result_2['id'],
+ ));
+ $this->callAPISuccess('contact', 'delete', array(
+ 'id' => $create_result_2['id'],
+ ));
+
+ // Assert.
+ $this->assertEquals(1, $get_result['api.relationship.get']['count']);
+ $this->assertEquals($create_result_3['id'], $get_result['api.relationship.get']['values'][0]['contact_id_a']);
+ }
+
+ /**
+ * Verify that attempt to create individual contact with first, and last names and email succeeds.
*/
public function testCreateIndividualWithNameEmail() {
$params = array(
);
$contact = $this->callAPISuccess('contact', 'create', $params);
- $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
+ $this->assertEquals(1, $contact['id']);
- // delete the contact
$this->callAPISuccess('contact', 'delete', $contact);
}
/**
- * Verify that attempt to create individual contact with no data fails
+ * Verify that attempt to create individual contact with no data fails.
*/
public function testCreateIndividualWithOutNameEmail() {
$params = array(
}
/**
- * Verify that attempt to create individual contact with first
- * and last names, email and location type succeeds
+ * Test create individual contact with first &last names, email and location type succeeds.
*/
public function testCreateIndividualWithNameEmailLocationType() {
$params = array(
);
$result = $this->callAPISuccess('contact', 'create', $params);
- $this->assertEquals(1, $result['id'], "In line " . __LINE__);
+ $this->assertEquals(1, $result['id']);
$this->callAPISuccess('contact', 'delete', array('id' => $result['id']));
}
/**
- * Verify that when changing employers
- * the old employer relationship becomes inactive
+ * Verify that when changing employers the old employer relationship becomes inactive.
*/
public function testCreateIndividualWithEmployer() {
$employer = $this->organizationCreate();
}
/**
- * Verify that attempt to create household contact with details
- * succeeds
+ * Verify that attempt to create household contact with details succeeds.
*/
public function testCreateHouseholdDetails() {
$params = array(
$contact = $this->callAPISuccess('contact', 'create', $params);
- $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
+ $this->assertEquals(1, $contact['id']);
$this->callAPISuccess('contact', 'delete', $contact);
}
/**
- * Verify that attempt to create household contact with inadequate details
- * fails
+ * Verify that attempt to create household contact with inadequate details fails.
*/
public function testCreateHouseholdInadequateDetails() {
$params = array(
}
/**
- * Verify successful update of individual contact
+ * Verify successful update of individual contact.
*/
public function testUpdateIndividualWithAll() {
- // Insert a row in civicrm_contact creating individual contact
+ // Insert a row in civicrm_contact creating individual contact.
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
$this->createXMLDataSet(
foreach ($params as $key => $value) {
$this->assertEquals($value, $getResult['values'][23][$key]);
}
- // Check updated civicrm_contact against expected
+ // Check updated civicrm_contact against expected.
$expected = $this->createXMLDataSet(
dirname(__FILE__) . '/dataset/contact_ind_upd.xml'
);
}
/**
- * Verify successful update of organization contact
+ * Verify successful update of organization contact.
*/
public function testUpdateOrganizationWithAll() {
- // Insert a row in civicrm_contact creating organization contact
+ // Insert a row in civicrm_contact creating organization contact
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
$this->createXMLDataSet(
$this->callAPISuccess('Contact', 'Update', $params);
- // Check updated civicrm_contact against expected
+ // Check updated civicrm_contact against expected.
$expected = $this->createXMLDataSet(
dirname(__FILE__) . '/dataset/contact_org_upd.xml'
);
}
/**
- * Verify successful update of household contact
+ * Verify successful update of household contact.
*/
- public function testUpdateHouseholdwithAll() {
- // Insert a row in civicrm_contact creating household contact
+ public function testUpdateHouseholdWithAll() {
+ // Insert a row in civicrm_contact creating household contact
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
$this->createXMLDataSet(
}
/**
- * Test civicrm_update() Deliberately exclude contact_type as it should still
- * cope using civicrm_api CRM-7645
+ * Test civicrm_update() without contact type.
+ *
+ * Deliberately exclude contact_type as it should still cope using civicrm_api.
+ *
+ * CRM-7645.
*/
public function testUpdateCreateWithID() {
- // Insert a row in civicrm_contact creating individual contact
+ // Insert a row in civicrm_contact creating individual contact.
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
$this->createXMLDataSet(
}
/**
- * Test civicrm_contact_delete() with no contact ID
+ * Test civicrm_contact_delete() with no contact ID.
*/
public function testContactDeleteNoID() {
$params = array(
}
/**
- * Test civicrm_contact_delete() with error
+ * Test civicrm_contact_delete() with error.
*/
public function testContactDeleteError() {
$params = array('contact_id' => 999);
}
/**
- * Test civicrm_contact_delete()
+ * Test civicrm_contact_delete().
*/
public function testContactDelete() {
$contactID = $this->individualCreate();
}
/**
- * Test civicrm_contact_get() return only first name
+ * Test civicrm_contact_get() return only first name.
*/
public function testContactGetRetFirst() {
$contact = $this->callAPISuccess('contact', 'create', $this->_params);
}
/**
- * Test civicrm_contact_get() return only first name & last name
- * Use comma separated string return with a space
+ * Test civicrm_contact_get() return only first name & last name.
+ *
+ * Use comma separated string return with a space.
*/
- public function testContactGetRetFirstLast() {
+ public function testContactGetReturnFirstLast() {
$contact = $this->callAPISuccess('contact', 'create', $this->_params);
$params = array(
'contact_id' => $contact['id'],
}
/**
- * Test civicrm_contact_get() return only first name & last name
- * Use comma separated string return without a space
+ * Test civicrm_contact_get() return only first name & last name.
+ *
+ * Use comma separated string return without a space
*/
- public function testContactGetRetFirstLastNoComma() {
+ public function testContactGetReturnFirstLastNoComma() {
$contact = $this->callAPISuccess('contact', 'create', $this->_params);
$params = array(
'contact_id' => $contact['id'],
}
/**
- * Test civicrm_contact_get() with default return properties
+ * Test civicrm_contact_get() with default return properties.
*/
public function testContactGetRetDefault() {
$contactID = $this->individualCreate();
}
/**
- * Test civicrm_contact_getquick() with empty name param
+ * Test civicrm_contact_getquick() with empty name param.
*/
public function testContactGetQuick() {
- // Insert a row in civicrm_contact creating individual contact
+ // Insert a row in civicrm_contact creating individual contact.
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
$this->createXMLDataSet(
);
$result = $this->callAPISuccess('contact', 'getquick', $params);
- $this->assertEquals(17, $result['values'][0]['id'], 'in line ' . __LINE__);
+ $this->assertEquals(17, $result['values'][0]['id']);
}
/**
- * Test civicrm_contact_get) with empty params
+ * Test civicrm_contact_get) with empty params.
*/
public function testContactGetEmptyParams() {
$this->callAPISuccess('contact', 'get', array());
}
/**
- * Test civicrm_contact_get(,true) with no matches
+ * Test civicrm_contact_get(,true) with no matches.
*/
public function testContactGetOldParamsNoMatches() {
- // Insert a row in civicrm_contact creating contact 17
+ // Insert a row in civicrm_contact creating contact 17.
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
$this->createXMLDataSet(
'first_name' => 'Fred',
);
$result = $this->callAPISuccess('contact', 'get', $params);
- $this->assertEquals(0, $result['count'], 'in line ' . __LINE__);
+ $this->assertEquals(0, $result['count']);
}
/**
- * Test civicrm_contact_get(,true) with one match
+ * Test civicrm_contact_get(,true) with one match.
*/
public function testContactGetOldParamsOneMatch() {
- // Insert a row in civicrm_contact creating contact 17
+ // Insert a row in civicrm_contact creating contact 17
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
$this->createXMLDataSet(dirname(__FILE__) . '/dataset/contact_17.xml'
'first_name' => 'Test',
);
$result = $this->callAPISuccess('contact', 'get', $params);
- $this->assertEquals(17, $result['values'][17]['contact_id'], 'in line ' . __LINE__);
- $this->assertEquals(17, $result['id'], 'in line ' . __LINE__);
+ $this->assertEquals(17, $result['values'][17]['contact_id']);
+ $this->assertEquals(17, $result['id']);
}
/**
- * Test civicrm_contact_search_count()
+ * Test civicrm_contact_search_count().
*/
public function testContactGetEmail() {
$params = array(
}
/**
- * Test birth date params incl value, array & birth_date_high, birth_date_low
- * && deceased
+ * Test birth date parameters.
+ *
+ * These include value, array & birth_date_high, birth_date_low
+ * && deceased.
*/
public function testContactGetBirthDate() {
$contact1 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array('birth_date' => 'first day of next month - 2 years')));
}
/**
- * Test Deceaseddate params incl value, array & Deceased_date_high, Deceaseddate_low
- * && deceased
+ * Test Deceased date parameters.
+ *
+ * These include value, array & Deceased_date_high, Deceased date_low
+ * && deceased.
*/
public function testContactGetDeceasedDate() {
$contact1 = $this->callAPISuccess('contact', 'create', array_merge($this->_params, array('deceased_date' => 'first day of next month - 2 years')));
}
/**
- * Test for Contact.get id=@user:username
+ * Test for Contact.get id=@user:username.
*/
public function testContactGetByUsername() {
- // setup - create contact with a uf-match
+ // Setup - create contact with a uf-match.
$cid = $this->individualCreate(array(
'contact_type' => 'Individual',
'first_name' => 'testGetByUsername',
}
/**
- * Test to check return works OK
+ * Test to check return works OK.
*/
public function testContactGetReturnValues() {
$extraParams = array('nick_name' => 'Bob', 'phone' => '456', 'email' => 'e@mail.com');
}
/**
- * Test for Contact.get id=@user:username (with an invalid username)
+ * Test for Contact.get id=@user:username (with an invalid username).
*/
public function testContactGetByUnknownUsername() {
// setup - mock the calls to CRM_Utils_System_*::getUfId
}
/**
- * Verify attempt to create individual with chained arrays
+ * Verify attempt to create individual with chained arrays.
*/
public function testGetIndividualWithChainedArrays() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params['custom_' . $ids['custom_field_id']] = "custom string";
- $moreids = $this->CustomGroupMultipleCreateWithFields();
- $description = "/*this demonstrates the usage of chained api functions. In this case no notes or custom fields have been created ";
+ $moreIDs = $this->CustomGroupMultipleCreateWithFields();
+ $description = "This demonstrates the usage of chained api functions.\nIn this case no notes or custom fields have been created.";
$subfile = "APIChainedArray";
$params = array(
'first_name' => 'abc3',
// delete the contact
$this->callAPISuccess('contact', 'delete', $result);
$this->customGroupDelete($ids['custom_group_id']);
- $this->customGroupDelete($moreids['custom_group_id']);
+ $this->customGroupDelete($moreIDs['custom_group_id']);
$this->assertEquals(1, $result['id']);
$this->assertEquals(0, $result['values'][$result['id']]['api.website.get']['is_error']);
$this->assertEquals("http://civicrm.org", $result['values'][$result['id']]['api.website.get']['values'][0]['url']);
}
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";
+ $description = "This demonstrates the usage of chained api functions.\nIn this case no notes or custom fields have been created.";
$subfile = "APIChainedArrayFormats";
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params['custom_' . $ids['custom_field_id']] = "custom string";
- $moreids = $this->CustomGroupMultipleCreateWithFields();
+ $moreIDs = $this->CustomGroupMultipleCreateWithFields();
$params = array(
'first_name' => 'abc3',
'last_name' => 'xyz3',
$this->callAPISuccess('contact', 'delete', $result);
$this->customGroupDelete($ids['custom_group_id']);
- $this->customGroupDelete($moreids['custom_group_id']);
+ $this->customGroupDelete($moreIDs['custom_group_id']);
}
+ /**
+ * Test complex chaining.
+ */
public function testGetIndividualWithChainedArraysAndMultipleCustom() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params['custom_' . $ids['custom_field_id']] = "custom string";
- $moreids = $this->CustomGroupMultipleCreateWithFields();
- $andmoreids = $this->CustomGroupMultipleCreateWithFields(array(
+ $moreIDs = $this->CustomGroupMultipleCreateWithFields();
+ $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";
+ $description = "This demonstrates the usage of chained api functions with multiple custom fields.";
$subfile = "APIChainedArrayMultipleCustom";
$params = array(
'first_name' => 'abc3',
),
),
'custom_' . $ids['custom_field_id'] => "value 1",
- 'custom_' . $moreids['custom_field_id'][0] => "value 2",
- 'custom_' . $moreids['custom_field_id'][1] => "warm beer",
- 'custom_' . $andmoreids['custom_field_id'][1] => "vegemite",
+ 'custom_' . $moreIDs['custom_field_id'][0] => "value 2",
+ 'custom_' . $moreIDs['custom_field_id'][1] => "warm beer",
+ 'custom_' . $andMoreIDs['custom_field_id'][1] => "vegemite",
);
$result = $this->callAPISuccess('Contact', 'create', $params);
'contact_type' => 'Individual',
'id' => $result['id'],
'custom_' .
- $moreids['custom_field_id'][0] => "value 3",
+ $moreIDs['custom_field_id'][0] => "value 3",
'custom_' .
$ids['custom_field_id'] => "value 4",
));
$result = $this->callAPIAndDocument('Contact', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
$this->customGroupDelete($ids['custom_group_id']);
- $this->customGroupDelete($moreids['custom_group_id']);
- $this->customGroupDelete($andmoreids['custom_group_id']);
+ $this->customGroupDelete($moreIDs['custom_group_id']);
+ $this->customGroupDelete($andMoreIDs['custom_group_id']);
$this->assertEquals(1, $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
+ * Test checks usage of $values to pick & choose inputs.
*/
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). ";
+ $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',
}
/**
- * test TrueFalse format - I couldn't come up with an easy way to get an error on Get
+ * Test TrueFalse format - I couldn't come up with an easy way to get an error on Get.
*/
public function testContactGetFormatIsSuccessTrue() {
$this->createContactFromXML();
}
/**
- * test TrueFalse format
+ * Test TrueFalse format.
*/
public function testContactCreateFormatIsSuccessFalse() {
}
/**
- * test Single Entity format
+ * Test Single Entity format.
*/
- public function testContactGetSingle_entity_array() {
+ public function testContactGetSingleEntityArray() {
$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";
+ 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);
}
/**
- * test Single Entity format
+ * Test Single Entity format.
*/
- public function testContactGetFormatcount_only() {
+ public function testContactGetFormatCountOnly() {
$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";
+ $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);
+ $result = $this->callAPIAndDocument('Contact', 'GetCount', $params, __FUNCTION__, __FILE__, $description,
+ $subfile, 'getcount');
$this->assertEquals('1', $result);
$this->callAPISuccess('Contact', 'Delete', $params);
}
/**
- * Test id only format
+ * Test id only format.
*/
- public function testContactGetFormatID_only() {
+ public function testContactGetFormatIDOnly() {
$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";
+ 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);
}
/**
- * Test id only format
+ * Test id only format.
*/
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";
+ 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');
+ $result = $this->callAPIAndDocument('Contact', 'getvalue', $params, __FUNCTION__, __FILE__, $description, $subFile);
$this->assertEquals('Test Contact', $result);
$this->callAPISuccess('Contact', 'Delete', $params);
}
/**
- * Test that permissions are respected when creating contacts
+ * Test that permissions are respected when creating contacts.
*/
public function testContactCreationPermissions() {
$params = array(
$config = CRM_Core_Config::singleton();
$config->userPermissionClass->permissions = array('access CiviCRM');
$result = $this->callAPIFailure('contact', 'create', $params);
- $this->assertEquals('API permission check failed for contact/create call; insufficient permission: require access CiviCRM and add contacts', $result['error_message'], 'lacking permissions should not be enough to create a contact');
+ $this->assertEquals('API permission check failed for Contact/create call; insufficient permission: require access CiviCRM and add contacts', $result['error_message'], 'lacking permissions should not be enough to create a contact');
$config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'import contacts');
$this->callAPISuccess('contact', 'create', $params, NULL, 'overfluous permissions should be enough to create a contact');
}
+ /**
+ * Test update with check permissions set.
+ */
public function testContactUpdatePermissions() {
$params = array(
'contact_type' => 'Individual',
$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');
+ $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',
$this->callAPISuccess('contact', 'update', $params, NULL, 'overfluous permissions should be enough to update a contact');
}
+ /**
+ * Set up helper to create a contact.
+ */
public function createContactFromXML() {
- // Insert a row in civicrm_contact creating contact 17
+ // Insert a row in civicrm_contact creating contact 17.
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
$this->createXMLDataSet(
);
}
+ /**
+ * Test contact proximity api.
+ */
public function testContactProximity() {
// first create a contact with a SF location with a specific
// geocode
}
/**
- * Test that Ajax API permission is sufficient to access getquick api
+ * Test that Ajax API permission is sufficient to access getquick api.
+ *
* (note that getquick api is required for autocomplete & has ACL permissions applied)
*/
- public function testGetquickPermission_CRM_13744() {
+ public function testGetquickPermissionCRM13744() {
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
+ * Test get ref api - gets a list of references to an entity.
*/
public function testGetReferenceCounts() {
$result = $this->callAPISuccess('Contact', 'create', array(
}
/**
- * CRM-14743 - test api respects search operators
+ * CRM-14743 - test api respects search operators.
*/
public function testGetModifiedDateByOperators() {
$preExistingContactCount = CRM_Core_DAO::singleValueQuery('select count(*) FROM civicrm_contact');
}
/**
- * CRM-14743 - test api respects search operators
+ * CRM-14743 - test api respects search operators.
*/
public function testGetCreatedDateByOperators() {
$preExistingContactCount = CRM_Core_DAO::singleValueQuery('select count(*) FROM civicrm_contact');
}
/**
- * CRM-14263 check that API is not affected by search profile related bug
+ * CRM-14263 check that API is not affected by search profile related bug.
*/
public function testReturnCityProfile() {
$contactID = $this->individualCreate();
public function testGetlistExcludeConditions() {
$name = md5(time());
$contact = $this->individualCreate(array('last_name' => $name));
- $deceasedContact = $this->individualCreate(array('last_name' => $name, 'is_deceased' => 1));
- $deletedContact = $this->individualCreate(array('last_name' => $name, 'is_deleted' => 1));
- // We should get all but the deleted contact
+ $this->individualCreate(array('last_name' => $name, 'is_deceased' => 1));
+ $this->individualCreate(array('last_name' => $name, 'is_deleted' => 1));
+ // We should get all but the deleted contact.
$result = $this->callAPISuccess('contact', 'getlist', array('input' => $name));
$this->assertEquals(2, $result['count'], 'In line ' . __LINE__);
- // Force-exclude the deceased contact
+ // Force-exclude the deceased contact.
$result = $this->callAPISuccess('contact', 'getlist', array(
'input' => $name,
'params' => array('is_deceased' => 0),
}
/**
- * Test contact.getactions
+ * Test contact getactions.
*/
public function testGetActions() {
$description = "Getting the available actions for an entity.";