<?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
*/
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');
}
/**
- * 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(
}
/**
- * 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() {
}
/**
- * 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
+ * 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() {
}
/**
- * Verify that attempt to create individual contact with
+ * 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
+ * Test household name is sufficient for create.
+ *
+ * Verify that attempt to create household contact with only
* household name succeeds
*/
public function testCreateNameHousehold() {
}
/**
- * 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
}
/**
- * 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__);
/**
- * 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;
}
/**
- * 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 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
}
/**
- * 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
}
/**
- * Check that address name is returned if required
+ * Check that address name is returned if required.
*/
public function testGetReturnAddressName() {
$contactID = $this->individualCreate();
}
/**
- * 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";
$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__);
}
/**
- * 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(
}
/**
- * Verify that attempt to create individual contact with first
+ * Verify that attempt to create individual contact with first
* and last names and email succeeds
*/
public function testCreateIndividualWithNameEmail() {
}
/**
- * 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
+ * Verify that attempt to create individual contact with first
* and last names, email and location type succeeds
*/
public function testCreateIndividualWithNameEmailLocationType() {
}
/**
- * Verify that attempt to create household contact with details
+ * Verify that attempt to create household contact with details
* succeeds
*/
public function testCreateHouseholdDetails() {
}
/**
- * 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
+ * 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
}
/**
- * 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
}
/**
- * 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
}
/**
- * 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
+ * Test birth date params incl value, array & birth_date_high, birth_date_low
* && deceased
*/
public function testContactGetBirthDate() {
}
/**
- * Test Deceaseddate params incl value, array & Deceased_date_high, Deceaseddate_low
- * && deceased
+ * Test Deceased date params incl 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')));
}
/**
- * 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();
+ $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(
// 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']);
$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',
));
),
),
'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' &
}
/**
- * 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 Single Entity format
+ * Test Single Entity format.
*/
- public 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";
+ $description = "This demonstrates use of the 'getCount' action.\n"
+ . " *\n"
+ . " * 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() {
$this->createContactFromXML();
}
/**
- * Test id only format
+ * Test id only format.
*/
public function testContactGetFormatSingleValue() {
$this->createContactFromXML();
}
/**
- * Test that permissions are respected when creating contacts
+ * Test that permissions are respected when creating contacts.
*/
public function testContactCreationPermissions() {
$params = array(
$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',
$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() {
}
/**
- * 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(
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),