/*
+--------------------------------------------------------------------+
-| CiviCRM version 4.5 |
+| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
/**
* Test APIv3 civicrm_profile_* functions
*
- * @package CiviCRM
+ * @package CiviCRM
*/
class api_v3_ProfileTest extends CiviUnitTestCase {
protected $_apiversion;
protected $_membershipTypeID;
protected $_contactID;
- /**
- * @return array
- */
- function get_info() {
- return array(
- 'name' => 'Profile Test',
- 'description' => 'Test all profile API methods.',
- 'group' => 'CiviCRM API Tests',
- );
- }
-
- function setUp() {
+ public function setUp() {
$this->_apiversion = 3;
parent::setUp();
$config = CRM_Core_Config::singleton();
$this->_membershipTypeID = $this->membershipTypeCreate();
}
- function tearDown() {
+ public function tearDown() {
$this->quickCleanup(array(
'civicrm_contact',
/**
* Check Without ProfileId
*/
- function testProfileGetWithoutProfileId() {
+ public function testProfileGetWithoutProfileId() {
$params = array(
'contact_id' => 1,
);
/**
* Check with no invalid profile Id
*/
- function testProfileGetInvalidProfileId() {
+ public function testProfileGetInvalidProfileId() {
$params = array(
'contact_id' => 1,
'profile_id' => 1000,
/**
* Check with success
*/
- function testProfileGet() {
+ public function testProfileGet() {
$pofileFieldValues = $this->_createIndividualContact();
- $expected = current($pofileFieldValues);
- $contactId = key($pofileFieldValues);
- $params = array(
+ $expected = current($pofileFieldValues);
+ $contactId = key($pofileFieldValues);
+ $params = array(
'profile_id' => $this->_profileID,
'contact_id' => $contactId,
);
}
}
- function testProfileGetMultiple() {
+ public function testProfileGetMultiple() {
$pofileFieldValues = $this->_createIndividualContact();
- $expected = current($pofileFieldValues);
- $contactId = key($pofileFieldValues);
- $params = array(
+ $expected = current($pofileFieldValues);
+ $contactId = key($pofileFieldValues);
+ $params = array(
'profile_id' => array($this->_profileID, 1, 'Billing'),
'contact_id' => $contactId,
);
));
}
- function testProfileGetBillingUseIsBillingLocation() {
+ public function testProfileGetBillingUseIsBillingLocation() {
$individual = $this->_createIndividualContact();
- $contactId = key($individual);
+ $contactId = key($individual);
$this->callAPISuccess('address', 'create', array(
'is_billing' => 1,
'street_address' => 'is billing st',
), $result['values']['Billing']);
}
- function testProfileGetMultipleHasBillingLocation() {
+ public function testProfileGetMultipleHasBillingLocation() {
$individual = $this->_createIndividualContact();
- $contactId = key($individual);
- $this->callAPISuccess('address', 'create', array('contact_id' => $contactId , 'street_address' => '25 Big Street', 'city' => 'big city', 'location_type_id' => 5));
- $this->callAPISuccess('email', 'create', array('contact_id' => $contactId , 'email' => 'big@once.com', 'location_type_id' => 2, 'is_billing' => 1));
+ $contactId = key($individual);
+ $this->callAPISuccess('address', 'create', array(
+ 'contact_id' => $contactId,
+ 'street_address' => '25 Big Street',
+ 'city' => 'big city',
+ 'location_type_id' => 5
+ ));
+ $this->callAPISuccess('email', 'create', array(
+ 'contact_id' => $contactId,
+ 'email' => 'big@once.com',
+ 'location_type_id' => 2,
+ 'is_billing' => 1
+ ));
$expected = current($individual);
/**
* Get Billing empty contact - this will return generic defaults
*/
- function testProfileGetBillingEmptyContact() {
+ public function testProfileGetBillingEmptyContact() {
$params = array(
'profile_id' => array('Billing'),
/**
* Check contact activity profile without activity id
*/
- function testContactActivityGetWithoutActivityId() {
+ public function testContactActivityGetWithoutActivityId() {
list($params, $expected) = $this->_createContactWithActivity();
unset($params['activity_id']);
/**
* Check contact activity profile wrong activity id
*/
- function testContactActivityGetWrongActivityId() {
+ public function testContactActivityGetWrongActivityId() {
list($params, $expected) = $this->_createContactWithActivity();
$params['activity_id'] = 100001;
/**
* Check contact activity profile with wrong activity type
*/
- function testContactActivityGetWrongActivityType() {
+ public function testContactActivityGetWrongActivityType() {
//flush cache by calling with reset
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
/**
* Check contact activity profile with success
*/
- function testContactActivityGetSuccess() {
+ public function testContactActivityGetSuccess() {
list($params, $expected) = $this->_createContactWithActivity();
$result = $this->callAPISuccess('profile', 'get', $params);
/**
* Check getfields works & gives us our fields
*/
- function testGetFields() {
+ public function testGetFields() {
$this->_createIndividualProfile();
$this->_addCustomFieldToProfile($this->_profileID);
- $result = $this->callAPIAndDocument('profile', 'getfields', array('action' => 'submit', 'profile_id' => $this->_profileID), __FUNCTION__, __FILE__,
+ $result = $this->callAPIAndDocument('profile', 'getfields', array(
+ 'action' => 'submit',
+ 'profile_id' => $this->_profileID
+ ), __FUNCTION__, __FILE__,
'demonstrates retrieving profile fields passing in an id');
$this->assertArrayKeyExists('first_name', $result['values']);
$this->assertEquals('2', $result['values']['first_name']['type']);
/**
* Check getfields works & gives us our fields - partipant profile
*/
- function testGetFieldsParticipantProfile() {
+ public function testGetFieldsParticipantProfile() {
$result = $this->callAPISuccess('profile', 'getfields', array(
- 'action' => 'submit',
- 'profile_id' => 'participant_status',
- 'get_options' => 'all')
+ 'action' => 'submit',
+ 'profile_id' => 'participant_status',
+ 'get_options' => 'all'
+ )
);
$this->assertTrue(array_key_exists('participant_status_id', $result['values']));
$this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]);
* Check getfields works & gives us our fields - membership_batch_entry
* (getting to the end with no e-notices is pretty good evidence it's working)
*/
- function testGetFieldsMembershipBatchProfile() {
+ public function testGetFieldsMembershipBatchProfile() {
$result = $this->callAPISuccess('profile', 'getfields', array(
- 'action' => 'submit',
- 'profile_id' => 'membership_batch_entry',
- 'get_options' => 'all')
+ 'action' => 'submit',
+ 'profile_id' => 'membership_batch_entry',
+ 'get_options' => 'all'
+ )
);
$this->assertTrue(array_key_exists('total_amount', $result['values']));
$this->assertTrue(array_key_exists('financial_type_id', $result['values']));
- $this->assertEquals(array('contribution_type_id', 'contribution_type', 'financial_type'), $result['values']['financial_type_id']['api.aliases']);
+ $this->assertEquals(array(
+ 'contribution_type_id',
+ 'contribution_type',
+ 'financial_type'
+ ), $result['values']['financial_type_id']['api.aliases']);
$this->assertTrue(!array_key_exists('financial_type', $result['values']));
$this->assertEquals(12, $result['values']['receive_date']['type']);
}
* Check getfields works & gives us our fields - do them all
* (getting to the end with no e-notices is pretty good evidence it's working)
*/
- function testGetFieldsAllProfiles() {
+ public function testGetFieldsAllProfiles() {
$result = $this->callAPISuccess('uf_group', 'get', array('return' => 'id'));
$profileIDs = array_keys($result['values']);
foreach ($profileIDs as $profileID) {
$result = $this->callAPISuccess('profile', 'getfields', array(
- 'action' => 'submit',
- 'profile_id' => $profileID,
- 'get_options' => 'all')
+ 'action' => 'submit',
+ 'profile_id' => $profileID,
+ 'get_options' => 'all'
+ )
);
}
}
/**
* Check Without ProfileId
*/
- function testProfileSubmitWithoutProfileId() {
+ public function testProfileSubmitWithoutProfileId() {
$params = array(
'contact_id' => 1,
);
/**
* Check with no invalid profile Id
*/
- function testProfileSubmitInvalidProfileId() {
+ public function testProfileSubmitInvalidProfileId() {
$params = array(
'contact_id' => 1,
'profile_id' => 1000,
/**
* Check with missing required field in profile
*/
- function testProfileSubmitCheckProfileRequired() {
+ public function testProfileSubmitCheckProfileRequired() {
$pofileFieldValues = $this->_createIndividualContact();
current($pofileFieldValues);
$contactId = key($pofileFieldValues);
/**
* Check with success
*/
- function testProfileSubmit() {
+ public function testProfileSubmit() {
$pofileFieldValues = $this->_createIndividualContact();
current($pofileFieldValues);
$contactId = key($pofileFieldValues);
}
unset($params['email-primary']);
$params['email-Primary'] = 'my@mail.com';
- $this->callAPISuccess('profile', 'submit', $params);
+ $this->callAPISuccess('profile', 'submit', $params);
$profileDetails = $this->callAPISuccess('profile', 'get', $getParams);
$this->assertEquals('my@mail.com', $profileDetails['values']['email-Primary']);
}
* Ensure caches are being cleared so we don't get into a debugging trap because of cached metadata
* First we delete & create to increment the version & then check for caching probs
*/
- function testProfileSubmitCheckCaching() {
+ public function testProfileSubmitCheckCaching() {
$this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID));
$this->_membershipTypeID = $this->membershipTypeCreate();
$membershipTypes = $this->callAPISuccess('membership_type', 'get', array());
- $profileFields = $this->callAPISuccess('profile', 'getfields', array('get_options' => 'all', 'action' => 'submit', 'profile_id' => 'membership_batch_entry'));
- $getoptions = $this->callAPISuccess('membership', 'getoptions', array('field' => 'membership_type', 'context' => 'validate'));
+ $profileFields = $this->callAPISuccess('profile', 'getfields', array(
+ 'get_options' => 'all',
+ 'action' => 'submit',
+ 'profile_id' => 'membership_batch_entry'
+ ));
+ $getoptions = $this->callAPISuccess('membership', 'getoptions', array(
+ 'field' => 'membership_type',
+ 'context' => 'validate'
+ ));
$this->assertEquals(array_keys($membershipTypes['values']), array_keys($getoptions['values']));
$this->assertEquals(array_keys($membershipTypes['values']), array_keys($profileFields['values']['membership_type_id']['options']));
-}
+ }
/**
* Test that the fields are returned in the right order despite the faffing around that goes on
*/
- function testMembershipGetFieldsOrder() {
- $result = $this->callAPISuccess('profile', 'getfields', array('action' => 'submit', 'profile_id' => 'membership_batch_entry'));
+ public function testMembershipGetFieldsOrder() {
+ $result = $this->callAPISuccess('profile', 'getfields', array(
+ 'action' => 'submit',
+ 'profile_id' => 'membership_batch_entry'
+ ));
$weight = 1;
- foreach($result['values'] as $fieldName => $field) {
- if($fieldName == 'profile_id') {
+ foreach ($result['values'] as $fieldName => $field) {
+ if ($fieldName == 'profile_id') {
continue;
}
$this->assertEquals($field['weight'], $weight);
$weight++;
}
}
+
/**
* Check we can submit membership batch profiles (create mode)
*/
- function testProfileSubmitMembershipBatch() {
+ public function testProfileSubmitMembershipBatch() {
$this->_contactID = $this->individualCreate();
$this->callAPISuccess('profile', 'submit', array(
- 'profile_id' => 'membership_batch_entry',
- 'financial_type_id' => 1,
- 'membership_type' => $this->_membershipTypeID,
- 'join_date' => 'now',
- 'total_amount' => 10,
- 'contribution_status_id' => 1,
- 'receive_date' => 'now',
- 'contact_id' => $this->_contactID,
+ 'profile_id' => 'membership_batch_entry',
+ 'financial_type_id' => 1,
+ 'membership_type' => $this->_membershipTypeID,
+ 'join_date' => 'now',
+ 'total_amount' => 10,
+ 'contribution_status_id' => 1,
+ 'receive_date' => 'now',
+ 'contact_id' => $this->_contactID,
));
}
+
/**
* Set is deprecated but we need to ensure it still works
*/
- function testLegacySet() {
+ public function testLegacySet() {
$pofileFieldValues = $this->_createIndividualContact();
current($pofileFieldValues);
$contactId = key($pofileFieldValues);
/**
* Check contact activity profile without activity id
*/
- function testContactActivitySubmitWithoutActivityId() {
+ public function testContactActivitySubmitWithoutActivityId() {
list($params, $expected) = $this->_createContactWithActivity();
$params = array_merge($params, $expected);
/**
* Check contact activity profile wrong activity id
*/
- function testContactActivitySubmitWrongActivityId() {
+ public function testContactActivitySubmitWrongActivityId() {
list($params, $expected) = $this->_createContactWithActivity();
$params = array_merge($params, $expected);
$params['activity_id'] = 100001;
/**
* Check contact activity profile with wrong activity type
*/
- function testContactActivitySubmitWrongActivityType() {
+ public function testContactActivitySubmitWrongActivityType() {
//flush cache by calling with reset
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
/**
* Check contact activity profile with success
*/
- function testContactActivitySubmitSuccess() {
+ public function testContactActivitySubmitSuccess() {
list($params, $expected) = $this->_createContactWithActivity();
$updateParams = array(
/**
* Check profile apply Without ProfileId
*/
- function testProfileApplyWithoutProfileId() {
+ public function testProfileApplyWithoutProfileId() {
$params = array(
'contact_id' => 1,
);
/**
* Check profile apply with no invalid profile Id
*/
- function testProfileApplyInvalidProfileId() {
+ public function testProfileApplyInvalidProfileId() {
$params = array(
'contact_id' => 1,
'profile_id' => 1000,
/**
* Check with success
*/
- function testProfileApply() {
+ public function testProfileApply() {
$pofileFieldValues = $this->_createIndividualContact();
current($pofileFieldValues);
$contactId = key($pofileFieldValues);
}
foreach (array(
- 'email', 'phone', 'address') as $fieldType) {
+ 'email',
+ 'phone',
+ 'address'
+ ) as $fieldType) {
$typeValues = array_pop($result['values'][$fieldType]);
foreach ($expected[$fieldType] as $field => $value) {
$this->assertEquals($value, CRM_Utils_Array::value($field, $typeValues), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$field} ({$fieldType})"
*
* @return mixed
*/
- function _createIndividualContact($params = array()) {
+ public function _createIndividualContact($params = array()) {
$contactParams = array_merge(array(
- 'first_name' => 'abc1',
- 'last_name' => 'xyz1',
- 'email' => 'abc1.xyz1@yahoo.com',
- 'api.address.create' => array(
- 'location_type_id' => 1,
- 'is_primary' => 1,
- 'street_address' => '5 Saint Helier St',
- 'county' => 'Marin',
- 'country' => 'United States',
- 'state_province' => 'Michigan',
- 'supplemental_address_1' => 'Hallmark Ct',
- 'supplemental_address_2' => 'Jersey Village',
- 'postal_code' => '90210',
- 'city' => 'Gotham City',
- 'is_billing' => 0,
- ),
- 'api.phone.create' => array(
- 'location_type_id' => '1',
- 'phone' => '021 512 755',
- 'phone_type_id' => '1',
- 'is_primary' => '1',
- ),
- ), $params
+ 'first_name' => 'abc1',
+ 'last_name' => 'xyz1',
+ 'email' => 'abc1.xyz1@yahoo.com',
+ 'api.address.create' => array(
+ 'location_type_id' => 1,
+ 'is_primary' => 1,
+ 'street_address' => '5 Saint Helier St',
+ 'county' => 'Marin',
+ 'country' => 'United States',
+ 'state_province' => 'Michigan',
+ 'supplemental_address_1' => 'Hallmark Ct',
+ 'supplemental_address_2' => 'Jersey Village',
+ 'postal_code' => '90210',
+ 'city' => 'Gotham City',
+ 'is_billing' => 0,
+ ),
+ 'api.phone.create' => array(
+ 'location_type_id' => '1',
+ 'phone' => '021 512 755',
+ 'phone_type_id' => '1',
+ 'is_primary' => '1',
+ ),
+ ), $params
);
$this->_contactID = $this->individualCreate($contactParams);
/**
* @return array
*/
- function _createContactWithActivity() {
+ public function _createContactWithActivity() {
// @TODO: Create profile with custom fields
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
return array($profileParams, $expected);
}
+
/**
* Create a profile
*/
- function _createIndividualProfile() {
+ public function _createIndividualProfile() {
// creating these via the api as we want to utilise & test the flushing of caches when fields created
// via the api
$ufGroupParams = array(
- 'group_type' => 'Individual,Contact',// really we should remove this & test the ufField create sets it
+ 'group_type' => 'Individual,Contact', // really we should remove this & test the ufField create sets it
'name' => 'test_individual_contact_profile',
'title' => 'Flat Coffee',
'api.uf_field.create' => array(
'field_type' => 'Contact',
'location_type_id' => 1,
'phone_type_id' => 1,
- 'label' => 'Phone'
+ 'label' => 'Phone',
),
array(
'field_name' => 'country',
'visibility' => 'Public Pages and Listings',
'field_type' => 'Contact',
'location_type_id' => 1,
- 'label' => 'Country'
+ 'label' => 'Country',
),
array(
'field_name' => 'state_province',
'visibility' => 'Public Pages and Listings',
'field_type' => 'Contact',
'location_type_id' => 1,
- 'label' => 'State Province'
+ 'label' => 'State Province',
),
array(
'field_name' => 'postal_code',
'is_required' => 0,
'field_type' => 'Contact',
'location_type_id' => 1,
- 'label' => 'State Province'
- ),
+ 'label' => 'State Province',
+ ),
),
);
$profile = $this->callAPISuccess('uf_group', 'create', $ufGroupParams);
/**
* @param int $profileID
*/
- function _addCustomFieldToProfile($profileID) {
+ public function _addCustomFieldToProfile($profileID) {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, '');
- $this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));
+ $this->uFFieldCreate(array(
+ 'uf_group_id' => $profileID,
+ 'field_name' => 'custom_' . $ids['custom_field_id'],
+ 'contact_type' => 'Contact'
+ ));
}
}
-