--- /dev/null
+<?php
+/**
+ * Test Generated example of using profile getfields API
+ * demonstrates retrieving profile fields passing in an id *
+ */
+function profile_getfields_example(){
+$params = array(
+ 'action' => 'submit',
+ 'profile_id' => 25,
+);
+
+try{
+ $result = civicrm_api3('profile', 'getfields', $params);
+}
+catch (CiviCRM_API3_Exception $e) {
+ // handle error here
+ $errorMessage = $e->getMessage();
+ $errorCode = $e->getErrorCode();
+ $errorData = $e->getExtraParams();
+ return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
+}
+
+return $result;
+}
+
+/**
+ * Function returns array of result expected from previous function
+ */
+function profile_getfields_expectedresult(){
+
+ $expectedResult = array(
+ 'is_error' => 0,
+ 'version' => 3,
+ 'count' => 9,
+ 'values' => array(
+ 'first_name' => array(
+ 'name' => 'first_name',
+ 'type' => 2,
+ 'title' => 'First Name',
+ 'maxlength' => 64,
+ 'size' => 30,
+ 'import' => true,
+ 'where' => 'civicrm_contact.first_name',
+ 'headerPattern' => '/^first|(f(irst\s)?name)$/i',
+ 'dataPattern' => '/^\w+$/',
+ 'export' => true,
+ ),
+ 'last_name' => array(
+ 'name' => 'last_name',
+ 'type' => 2,
+ 'title' => 'Last Name',
+ 'maxlength' => 64,
+ 'size' => 30,
+ 'import' => true,
+ 'where' => 'civicrm_contact.last_name',
+ 'headerPattern' => '/^last|(l(ast\s)?name)$/i',
+ 'dataPattern' => '/^\w+(\s\w+)?+$/',
+ 'export' => true,
+ ),
+ 'email' => array(
+ 'name' => 'email',
+ 'type' => 2,
+ 'title' => 'Email',
+ 'maxlength' => 64,
+ 'size' => 20,
+ 'import' => true,
+ 'where' => 'civicrm_email.email',
+ 'headerPattern' => '/e.?mail/i',
+ 'dataPattern' => '/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/',
+ 'export' => true,
+ 'rule' => 'email',
+ 'api.required' => 1,
+ ),
+ 'phone-1-1' => array(
+ 'name' => 'phone',
+ 'type' => 2,
+ 'title' => 'Phone',
+ 'maxlength' => 32,
+ 'size' => 20,
+ 'import' => true,
+ 'where' => 'civicrm_phone.phone',
+ 'headerPattern' => '/phone/i',
+ 'dataPattern' => '/^[\d\(\)\-\.\s]+$/',
+ 'export' => true,
+ 'api.required' => 1,
+ ),
+ 'country-1' => array(
+ 'name' => 'country_id',
+ 'type' => 1,
+ 'title' => 'Country',
+ 'FKClassName' => 'CRM_Core_DAO_Country',
+ 'pseudoconstant' => array(
+ 'table' => 'civicrm_country',
+ 'keyColumn' => 'id',
+ 'labelColumn' => 'name',
+ 'nameColumn' => 'iso_code',
+ ),
+ ),
+ 'state_province-1' => array(
+ 'name' => 'state_province_id',
+ 'type' => 1,
+ 'title' => 'State',
+ 'FKClassName' => 'CRM_Core_DAO_StateProvince',
+ 'pseudoconstant' => array(
+ 'table' => 'civicrm_state_province',
+ 'keyColumn' => 'id',
+ 'labelColumn' => 'name',
+ ),
+ ),
+ 'postal_code-1' => array(
+ 'name' => 'postal_code',
+ 'type' => 2,
+ 'title' => 'Postal Code',
+ 'maxlength' => 12,
+ 'size' => 12,
+ 'import' => true,
+ 'where' => 'civicrm_address.postal_code',
+ 'headerPattern' => '/postal|zip/i',
+ 'dataPattern' => '/\d?\d{4}(-\d{4})?/',
+ 'export' => true,
+ ),
+ 'custom_1' => array(
+ 'label' => '_addCustomFieldToProfile',
+ 'groupTitle' => '_addCustomFie',
+ 'data_type' => 'String',
+ 'html_type' => 'Text',
+ 'default_value' => 'defaultValue',
+ 'text_length' => '',
+ 'options_per_line' => '',
+ 'custom_group_id' => '1',
+ 'extends' => 'Contact',
+ 'is_search_range' => 0,
+ 'extends_entity_column_value' => '',
+ 'extends_entity_column_id' => '',
+ 'is_view' => 0,
+ 'is_multiple' => 0,
+ 'option_group_id' => '',
+ 'date_format' => '',
+ 'time_format' => '',
+ 'name' => 'custom_1',
+ ),
+ 'profile_id' => array(
+ 'api.required' => true,
+ ),
+ ),
+);
+
+ return $expectedResult;
+}
+
+
+/*
+* This example has been generated from the API test suite. The test that created it is called
+*
+* testGetFields and can be found in
+* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ProfileTest.php
+*
+* You can see the outcome of the API tests at
+* http://tests.dev.civicrm.org/trunk/results-api_v3
+*
+* To Learn about the API read
+* http://book.civicrm.org/developer/current/techniques/api/
+*
+* and review the wiki at
+* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
+*
+* Read more about testing here
+* http://wiki.civicrm.org/confluence/display/CRM/Testing
+*
+* API Standards documentation:
+* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
+*/
\ No newline at end of file
*/
class api_v3_ProfileTest extends CiviUnitTestCase {
protected $_apiversion;
+ protected $_profileID;
function get_info() {
return array(
'name' => 'Profile Test',
}
}
- /////////////// test $this->callAPISuccess3_profile_set //////////////////
-
/**
- * check with no array
+ * Check getfields works & gives us our fields
+ */
+ function testGetFields() {
+ $this->_createIndividualProfile();
+ $this->_addCustomFieldToProfile($this->_profileID);
+ $result = $this->callAPIAndDocument('profile', 'getfields', array('action' => 'submit', 'profile_id' => 25), __FUNCTION__, __FILE__,
+ 'demonstrates retrieving profile fields passing in an id');
+ $this->assertArrayKeyExists('first_name', $result['values']);
+ $this->assertEquals('2', $result['values']['first_name']['type']);
+ $this->assertEquals('Email', $result['values']['email']['title']);
+ $this->assertEquals('civicrm_state_province', $result['values']['state_province-1']['pseudoconstant']['table']);
+ $this->assertEquals('defaultValue', $result['values']['custom_1']['default_value']);
+ $this->assertFalse(array_key_exists('participant_status', $result['values']));
+ }
+ /**
+ * Check getfields works & gives us our fields
*/
- function testProfileSetNoArray() {
- $params = NULL;
- $result = $this->callAPIFailure('profile', 'set', $params);
- $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
+ function testGetFieldsParticipantProfile() {
+ $result = $this->callAPISuccess('profile', 'getfields', array(
+ 'action' => 'submit',
+ 'profile_id' => 'participant_status',
+ 'get_options' => 'all')
+ );
+ $this->assertTrue(array_key_exists('participant_status', $result['values']));
+ $this->assertEquals('Attended', $result['values']['participant_status']['options'][2]);
}
+ /////////////// test $this->callAPISuccess3_profile_set //////////////////
/**
* check Without ProfileId
*/
- function testProfileSetWithoutProfileId() {
+ function testProfileSubmitWithoutProfileId() {
$params = array(
'contact_id' => 1,
);
- $result = $this->callAPIFailure('profile', 'set', $params,
+ $result = $this->callAPIFailure('profile', 'submit', $params,
'Mandatory key(s) missing from params array: profile_id'
);
}
/**
* check with no invalid profile Id
*/
- function testProfileSetInvalidProfileId() {
+ function testProfileSubmitInvalidProfileId() {
$params = array(
'contact_id' => 1,
'profile_id' => 1000,
);
- $result = $this->callAPIFailure('profile', 'set', $params);
+ $result = $this->callAPIFailure('profile', 'submit', $params);
}
/**
* check with missing required field in profile
*/
- function testProfileSetCheckProfileRequired() {
+ function testProfileSubmitCheckProfileRequired() {
$pofileFieldValues = $this->_createIndividualContact();
current($pofileFieldValues);
$contactId = key($pofileFieldValues);
$updateParams
);
- $result = $this->callAPIFailure('profile', 'set', $params,
+ $result = $this->callAPIFailure('profile', 'submit', $params,
'Missing required parameters for profile id 25: email-Primary'
);
}
/**
* check with success
*/
- function testProfileSet() {
+ function testProfileSubmit() {
$pofileFieldValues = $this->_createIndividualContact();
current($pofileFieldValues);
$contactId = key($pofileFieldValues);
'contact_id' => $contactId,
), $updateParams);
- $result = $this->callAPIAndDocument('profile', 'set', $params, __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument('profile', 'submit', $params, __FUNCTION__, __FILE__);
$getParams = array(
'profile_id' => 25,
/*
* check contact activity profile without activity id
*/
- function testContactActivitySetWithoutActivityId() {
+ function testContactActivitySubmitWithoutActivityId() {
list($params, $expected) = $this->_createContactWithActivity();
$params = array_merge($params, $expected);
unset($params['activity_id']);
- $result = $this->callAPIFailure('profile', 'set', $params);
+ $result = $this->callAPIFailure('profile', 'submit', $params);
$this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id');
-
- $this->quickCleanup(array('civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_group', 'civicrm_custom_field', 'civicrm_custom_group', 'civicrm_contact'));
}
/*
* check contact activity profile wrong activity id
*/
- function testContactActivitySetWrongActivityId() {
+ function testContactActivitySubmitWrongActivityId() {
list($params, $expected) = $this->_createContactWithActivity();
-
$params = array_merge($params, $expected);
$params['activity_id'] = 100001;
- $result = $this->callAPIFailure('profile', 'set', $params);
+ $result = $this->callAPIFailure('profile', 'submit', $params);
$this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).');
-
- $this->quickCleanup(array('civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_group', 'civicrm_custom_field', 'civicrm_custom_group', 'civicrm_contact'));
}
/*
* check contact activity profile with wrong activity type
*/
- function testContactActivitySetWrongActivityType() {
+ function testContactActivitySubmitWrongActivityType() {
//flush cache by calling with reset
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
$params = array_merge($params, $expected);
$params['activity_id'] = $activityValues['id'];
- $result = $this->callAPIFailure('profile', 'set', $params,
+ $result = $this->callAPIFailure('profile', 'submit', $params,
'This activity cannot be edited or viewed via this profile.');
}
/*
* check contact activity profile with success
*/
- function testContactActivitySetSuccess() {
+ function testContactActivitySubmitSuccess() {
list($params, $expected) = $this->_createContactWithActivity();
$updateParams = array(
'activity_status_id' => '2',
);
$profileParams = array_merge($params, $updateParams);
- $profile = $this->callAPISuccess('profile', 'set', $profileParams);
+ $profile = $this->callAPISuccess('profile', 'submit', $profileParams);
$result = $this->callAPISuccess('profile', 'get', $params);
foreach ($updateParams as $profileField => $value) {
);
$contactID = $this->individualCreate($contactParams);
-
- // Create new profile having group_type: Contact,Individual
- $op = new PHPUnit_Extensions_Database_Operation_Insert();
- $op->execute($this->_dbconn,
- new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
- dirname(__FILE__) . "/dataset/uf_group_25.xml"
- )
- );
- // Create Contact + Idividual fields for profile
- $op = new PHPUnit_Extensions_Database_Operation_Insert();
- $op->execute($this->_dbconn,
- new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
- dirname(__FILE__) . "/dataset/uf_field_uf_group_25.xml"
- )
- );
-
-
+ $this->_createIndividualProfile();
// expected result of above created profile with contact Id $contactId
$profileData[$contactID] = array(
'first_name' => 'abc1',
return array($profileParams, $expected);
}
+ /**
+ * Create a profile
+ */
+ function _createIndividualProfile() {
+ // Create new profile having group_type: Contact,Individual
+ $op = new PHPUnit_Extensions_Database_Operation_Insert();
+ $op->execute($this->_dbconn,
+ new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
+ dirname(__FILE__) . "/dataset/uf_group_25.xml"
+ )
+ );
+ // Create Contact + Idividual fields for profile
+ $op = new PHPUnit_Extensions_Database_Operation_Insert();
+ $op->execute($this->_dbconn,
+ new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
+ dirname(__FILE__) . "/dataset/uf_field_uf_group_25.xml"
+ )
+ );
+ $this->_profileID = 25;
+ }
+
+ function _addCustomFieldToProfile($profileID) {
+ $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, '');
+ $this->uFFieldCreate(array('uf_group_id' => $profileID, 'field_name' => 'custom_' . $ids['custom_field_id'], 'contact_type' => 'Contact'));
+ }
}