Merge pull request #1471 from eileenmcnaughton/CRM-13254
authorKurund Jalmi <kurund@civicrm.org>
Wed, 21 Aug 2013 07:24:25 +0000 (00:24 -0700)
committerKurund Jalmi <kurund@civicrm.org>
Wed, 21 Aug 2013 07:24:25 +0000 (00:24 -0700)
CRM-13254 (Closes) make entity_tag.get api use basic create rather than ...

16 files changed:
api/v3/Contact.php
api/v3/CustomValue.php
api/v3/Profile.php
api/v3/examples/Contact/APIChainedArrayMultipleCustom.php
api/v3/examples/Contact/GetFieldsOptions.php
api/v3/examples/CustomFieldCreate.php
api/v3/examples/CustomValue/formatFieldName.php
api/v3/examples/CustomValueGet.php
api/v3/examples/ProfileGetFields.php
api/v3/utils.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/ContactTest.php
tests/phpunit/api/v3/CustomFieldTest.php
tests/phpunit/api/v3/CustomValueContactTypeTest.php
tests/phpunit/api/v3/CustomValueTest.php
tests/phpunit/api/v3/ProfileTest.php

index 6040e5ceb66369d11173d88c350e06dd543004e7..a96ba078e7dc8d22513f4c795f736066bbaaa3d3 100644 (file)
@@ -123,6 +123,7 @@ function _civicrm_api3_contact_create_spec(&$params) {
   $params['current_employer'] = array(
     'title' => 'Current Employer',
     'description' => 'Name of Current Employer',
+    'type' => CRM_Utils_Type::T_STRING,
   );
   $params['dupe_check'] = array(
     'title' => 'Check for Duplicates',
index 2ad7bc96af02574a8aef9f087249d82c39398f03..dde56fd8a72c372541aebb1b621dd5323330b5c9 100644 (file)
@@ -176,7 +176,7 @@ function civicrm_api3_custom_value_get($params) {
       return civicrm_api3_create_success($values, $params);
     }
     else {
-      return civicrm_api3_create_error($result['error_message']);
+      throw new API_Exception($result['error_message']);
     }
   }
   else {
index 16c1b2aecea88b21b6a7891d7fd31be90fa4e3a0..7c41d54d96d70f2c5776aa475ccde60764450d0b 100644 (file)
@@ -147,20 +147,22 @@ function _civicrm_api3_profile_get_spec(&$params) {
  * @return array API result array
  */
 function civicrm_api3_profile_submit($params) {
+  $profileID = _civicrm_api3_profile_getProfileID($params['profile_id']);
 
-  if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $params['profile_id'], 'is_active')) {
+  if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_active')) {
+    //@todo declare pseudoconstant & let api do this
     throw new API_Exception('Invalid value for profile_id');
   }
 
-  $isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($params['profile_id']);
+  $isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($profileID);
 
-  if (CRM_Core_BAO_UFField::checkProfileType($params['profile_id']) && !$isContactActivityProfile) {
-    throw new API_Exception('Can not retrieve values for profiles include fields for more than one record type.');
+  if (!empty($params['id']) && CRM_Core_BAO_UFField::checkProfileType($profileID) && !$isContactActivityProfile) {
+    throw new API_Exception('Update profiles including more than one entity not currently supported');
   }
 
   $contactParams = $activityParams = $missingParams = array();
 
-  $profileFields = CRM_Core_BAO_UFGroup::getFields($params['profile_id'],
+  $profileFields = CRM_Core_BAO_UFGroup::getFields($profileID,
     FALSE,
     NULL,
     NULL,
@@ -177,7 +179,7 @@ function civicrm_api3_profile_submit($params) {
 
     $errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'],
       $params['contact_id'],
-      $params['profile_id']
+      $profileID
     );
     if (!empty($errors)) {
       throw new API_Exception(array_pop($errors));
@@ -212,9 +214,8 @@ function civicrm_api3_profile_submit($params) {
     throw new API_Exception("Missing required parameters for profile id {$params['profile_id']}: " . implode(', ', $missingParams));
   }
 
-  $contactParams['version'] = 3;
   $contactParams['contact_id'] = CRM_Utils_Array::value('contact_id', $params);
-  $contactParams['profile_id'] = $params['profile_id'];
+  $contactParams['profile_id'] = $profileID;
   $contactParams['skip_custom'] = 1;
 
   $contactProfileParams = civicrm_api3_profile_apply($contactParams);
@@ -245,7 +246,7 @@ function civicrm_api3_profile_submit($params) {
   return civicrm_api3('contact', 'create', $profileParams);
 
   $ufGroupDetails = array();
-  $ufGroupParams = array('id' => $params['profile_id']);
+  $ufGroupParams = array('id' => $profileID);
   CRM_Core_BAO_UFGroup::retrieve($ufGroupParams, $ufGroupDetails);
 
   if (isset($profileFields['group'])) {
@@ -325,12 +326,6 @@ function civicrm_api3_profile_set($params) {
  */
 function civicrm_api3_profile_apply($params) {
 
-  civicrm_api3_verify_mandatory($params, NULL, array('profile_id'));
-
-  if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $params['profile_id'], 'is_active')) {
-    return civicrm_api3_create_error('Invalid value for profile_id');
-  }
-
   $profileFields = CRM_Core_BAO_UFGroup::getFields($params['profile_id'],
     FALSE,
     NULL,
@@ -468,23 +463,32 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour =
 
     $realFieldName = $field['field_name'];
     //see function notes
+    // as we build up a list of these we should be able to determine a generic approach
+    //
     $hardCodedEntityFields = array(
       'state_province' => 'state_province_id',
       'country' => 'country_id',
       'participant_status' => 'status_id',
       'gender' => 'gender_id',
+      'financial_type' => 'financial_type_id',
+      'soft_credit' => 'soft_credit_to',
+      'group' => 'group_id',
+      'tag' => 'tag_id',
     );
+
     if(array_key_exists($realFieldName, $hardCodedEntityFields)) {
       $realFieldName = $hardCodedEntityFields[$realFieldName];
     }
+
     $entities[$entity][$fieldName] = $realFieldName;
   }
 
   foreach ($entities as $entity => $entityFields) {
     $result = civicrm_api3($entity, 'getfields', array('action' => 'create'));
+    $entityGetFieldsResult = _civicrm_api3_profile_appendaliases($result['values'], $entity);
     foreach ($entityFields as $entityfield => $realName) {
-      $profileFields[$profileID][$entityfield] = $result['values'][$realName];
-      if($optionsBehaviour && !empty($result['values'][$realName]['pseudoconstant'])) {
+      $profileFields[$profileID][$entityfield] = $entityGetFieldsResult[$realName];
+      if($optionsBehaviour && !empty($entityGetFieldsResult[$realName]['pseudoconstant'])) {
         if($optionsBehaviour > 1  || !in_array($realName, array('state_province_id', 'county_id', 'country_id'))) {
           $options = civicrm_api3($entity, 'getoptions', array('field' => $realName));
           $profileFields[$profileID][$entityfield]['options'] = $options['values'];
@@ -527,8 +531,11 @@ function _civicrm_api3_map_profile_fields_to_entity(&$field) {
     $fieldName .= '-' . $field['location_type_id'];
     $entity = 'Phone';
   }
+  // @todo - sort this out!
   //here we do a hard-code list of known fields that don't map to where they are mapped to
-  // not a great solution but probably if we looked in the BAO we'd find a scary switch
+  // not a great solution but probably if we looked in the BAO we'd find a scary switch statement
+  // in a perfect world the uf_field table would hold the correct entity for each item
+  // & only the relationships between entities would need to be coded
   $hardCodedEntityMappings = array(
     'street_address' => 'Address',
     'street_number' => 'Address',
@@ -541,6 +548,18 @@ function _civicrm_api3_map_profile_fields_to_entity(&$field) {
     'state_province' => 'Address',
     'country' => 'Address',
     'county' => 'Address',
+    //note that in discussions about how to restructure the api we discussed making these membership
+    // fields into 'membership_payment' fields - which would entail declaring them in getfields
+    // & renaming them in existing profiles
+    'financial_type' => 'Contribution',
+    'total_amount' => 'Contribution',
+    'receive_date' => 'Contribution',
+    'payment_instrument' => 'Contribution',
+    'check_number' => 'Contribution',
+    'contribution_status_id' => 'Contribution',
+    'soft_credit' => 'Contribution',
+    'group' => 'GroupContact',
+    'tag' => 'EntityTag',
    );
   if(array_key_exists($fieldName, $hardCodedEntityMappings)) {
     $entity = $hardCodedEntityMappings[$fieldName];
@@ -553,8 +572,34 @@ function _civicrm_api3_map_profile_fields_to_entity(&$field) {
  * how we add a a pseudoconstant to this pseudoapi to make that work
  */
 function _civicrm_api3_profile_getProfileID($profileID) {
-  if(!empty($profileID) && !strtolower($profileID) == 'billing' && !is_numeric($profileID)) {
+  if(!empty($profileID) && strtolower($profileID) != 'billing' && !is_numeric($profileID)) {
     $profileID = civicrm_api3('uf_group', 'getvalue', array('return' => 'id', 'name' => $profileID));
   }
   return $profileID;
+}
+
+/**
+ * helper function to add all aliases as keys to getfields response so we can look for keys within it
+ * since the relationship between profile fields & api / metadata based fields is a bit inconsistent
+ * @param array $values
+ *
+ * e.g getfields response incl 'membership_type_id' - with api.aliases = 'membership_type'
+ * returned array will include both as keys (with the same values)
+ */
+function _civicrm_api3_profile_appendaliases($values, $entity) {
+  foreach ($values as $field => $spec) {
+    if(!empty($spec['api.aliases'])) {
+      foreach ($spec['api.aliases'] as $alias) {
+        $values[$alias] = $spec;
+      }
+    }
+    if(!empty($spec['uniqueName'])) {
+      $values[$spec['uniqueName']] = $spec;
+    }
+  }
+  //special case on membership & contribution - can't see how to handle in a generic way
+  if(in_array($entity, array('Membership', 'Contribution'))) {
+    $values['send_receipt'] = array('title' => 'Send Receipt', 'type' => (int) 16);
+  }
+  return $values;
 }
\ No newline at end of file
index 7ab21a1d6781eb5b161f069a6a739b2b534617f2..4c1b8d26ec4009b52ef96b9db19ea73c08fd0b5f 100644 (file)
@@ -126,23 +126,23 @@ function contact_get_expectedresult(){
                     ),
                   '3' => array(
                       'entity_id' => '1',
-                      'latest' => '',
+                      'latest' => 'defaultValue',
                       'id' => '3',
                       '1' => 'warm beer',
-                      '2' => '',
+                      '2' => 'defaultValue',
                     ),
                   '4' => array(
                       'entity_id' => '1',
-                      'latest' => '',
+                      'latest' => 'defaultValue',
                       'id' => '4',
-                      '1' => '',
-                      '2' => '',
+                      '1' => 'defaultValue',
+                      '2' => 'defaultValue',
                     ),
                   '5' => array(
                       'entity_id' => '1',
-                      'latest' => '',
+                      'latest' => 'defaultValue',
                       'id' => '5',
-                      '1' => '',
+                      '1' => 'defaultValue',
                     ),
                   '6' => array(
                       'entity_id' => '1',
@@ -152,9 +152,9 @@ function contact_get_expectedresult(){
                     ),
                   '7' => array(
                       'entity_id' => '1',
-                      'latest' => '',
+                      'latest' => 'defaultValue',
                       'id' => '7',
-                      '1' => '',
+                      '1' => 'defaultValue',
                     ),
                 ),
             ),
index 5605b345f34d31124e32d6a54346fdf0b042be6b..73f989bc360635d1576b49e7b5e1c104603e4903 100644 (file)
@@ -320,6 +320,10 @@ function contact_getfields_expectedresult(){
           'pseudoconstant' => array(
               'optionGroupName' => 'individual_prefix',
             ),
+          'api.aliases' => array(
+              '0' => 'individual_prefix',
+              '1' => 'individual_prefix_id',
+            ),
         ),
       'suffix_id' => array(
           'name' => 'suffix_id',
@@ -333,6 +337,10 @@ function contact_getfields_expectedresult(){
           'pseudoconstant' => array(
               'optionGroupName' => 'individual_suffix',
             ),
+          'api.aliases' => array(
+              '0' => 'individual_suffix',
+              '1' => 'individual_suffix_id',
+            ),
         ),
       'email_greeting_id' => array(
           'name' => 'email_greeting_id',
@@ -552,6 +560,7 @@ function contact_getfields_expectedresult(){
           'groupTitle' => 'select_test_g',
           'data_type' => 'String',
           'html_type' => 'Select',
+          'default_value' => '',
           'text_length' => '',
           'options_per_line' => '',
           'custom_group_id' => '1',
index c0496c093cc89b5d17b04c08112e3419ad8259a0..24644eb443bbdaea7ea133a14d55e88d3948e747 100644 (file)
@@ -45,7 +45,7 @@ function custom_field_create_expectedresult(){
       '1' => array(
           'id' => '1',
           'custom_group_id' => '1',
-          'name' => 'Name1',
+          'name' => 'test_textfield2',
           'label' => 'Name1',
           'data_type' => 'String',
           'html_type' => 'Text',
index e88d7b454fda3948269094a8d20d61a329a44067..a7f3e0abc50a8a36a7de1936d0edb3c812d8fe4a 100644 (file)
@@ -32,31 +32,52 @@ function custom_value_get_expectedresult(){
   $expectedResult = array(
   'is_error' => 0,
   'version' => 3,
-  'count' => 4,
+  'count' => 7,
   'values' => array(
       'mySingleField' => array(
           'entity_id' => '2',
           'latest' => 'value 1',
           'id' => 'mySingleField',
         ),
-      'Cust_Field' => array(
+      'field_12' => array(
+          'entity_id' => '2',
+          'latest' => 'value 3',
+          'id' => 'field_12',
+          '1' => 'value 2',
+          '2' => 'value 3',
+        ),
+      'field_22' => array(
+          'entity_id' => '2',
+          'latest' => '',
+          'id' => 'field_22',
+          '1' => 'warm beer',
+          '2' => '',
+        ),
+      'field_32' => array(
+          'entity_id' => '2',
+          'latest' => '',
+          'id' => 'field_32',
+          '1' => 'fl* w*',
+          '2' => '',
+        ),
+      'field_13' => array(
           'entity_id' => '2',
           'latest' => 'coffee',
-          'id' => 'Cust_Field',
-          '1' => '',
+          'id' => 'field_13',
+          '1' => 'defaultValue',
           '2' => 'coffee',
         ),
-      'field_2' => array(
+      'field_23' => array(
           'entity_id' => '2',
           'latest' => 'value 4',
-          'id' => 'field_2',
+          'id' => 'field_23',
           '1' => '',
           '2' => 'value 4',
         ),
-      'field_3' => array(
+      'field_33' => array(
           'entity_id' => '2',
           'latest' => '',
-          'id' => 'field_3',
+          'id' => 'field_33',
           '1' => 'vegemite',
           '2' => '',
         ),
index 4ca42103af4320807f7c879a454a02df81bd0b54..e5d81ea44715977d935038a990587d8adcb87c03 100644 (file)
@@ -63,7 +63,7 @@ function custom_value_get_expectedresult(){
           'entity_id' => '2',
           'latest' => 'coffee',
           'id' => '5',
-          '1' => '',
+          '1' => 'defaultValue',
           '2' => 'coffee',
         ),
       '6' => array(
index c4ab716249ae2119c3f1fcbd466215d0ba87c4f6..4ec751934410cd8a8aa38876739682f5fea17623 100644 (file)
@@ -138,6 +138,7 @@ function profile_getfields_expectedresult(){
           'date_format' => '',
           'time_format' => '',
           'name' => 'custom_1',
+          'type' => 2,
         ),
       'profile_id' => array(
           'api.required' => true,
index 01b7bf5a685e4d151ce5acd5d7474c6a73f79b06..a0798270f4ff078a509569cd995da650ece75ae5 100644 (file)
@@ -1335,6 +1335,7 @@ function _civicrm_api_get_custom_fields($entity, &$params) {
   foreach ($customfields as $key => $value) {
     // Regular fields have a 'name' property
     $value['name'] = 'custom_' . $key;
+    $value['type'] = _getStandardTypeFromCustomDataType($value['data_type']);
     $customfields['custom_' . $key] = $value;
     if (in_array('custom_' . $key, $getoptions)) {
       $customfields['custom_' . $key]['options'] = CRM_Core_BAO_CustomOption::valuesByID($key);
@@ -1343,7 +1344,25 @@ function _civicrm_api_get_custom_fields($entity, &$params) {
   }
   return $customfields;
 }
-
+/**
+ * Translate the custom field data_type attribute into a std 'type'
+ */
+function _getStandardTypeFromCustomDataType($dataType) {
+  $mapping = array(
+    'String' => CRM_Utils_Type::T_STRING,
+    'Int' => CRM_Utils_Type::T_INT,
+    'Money' => CRM_Utils_Type::T_MONEY,
+    'Memo' => CRM_Utils_Type::T_LONGTEXT,
+    'Float' => CRM_Utils_Type::T_FLOAT,
+    'Date' => CRM_Utils_Type::T_DATE,
+    'Boolean' => CRM_Utils_Type::T_BOOLEAN,
+    'StateProvince' => CRM_Utils_Type::T_INT,
+    'File' => CRM_Utils_Type::T_STRING,
+    'Link' => CRM_Utils_Type::T_STRING,
+    'ContactReference' => CRM_Utils_Type::T_INT,
+  );
+  return $mapping[$dataType];
+}
 /**
  * Return array of defaults for the given API (function is a wrapper on getfields)
  */
index 920602397532a37216df4c681469a7b2af3940b8..5006e9bde6b1ff9f167d1af5eef699eb39aba8ad 100644 (file)
@@ -1704,14 +1704,14 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     $customGroup = $this->CustomGroupMultipleCreateByParams($params);
     $ids['custom_group_id'] = $customGroup['id'];
 
-    $customField = $this->customFieldCreate($ids['custom_group_id']);
+    $customField = $this->customFieldCreate(array('custom_group_id' => $ids['custom_group_id'], 'label' => 'field_1' . $ids['custom_group_id']));
 
     $ids['custom_field_id'][] = $customField['id'];
 
-    $customField = $this->customFieldCreate($ids['custom_group_id'], 'field_2');
+    $customField = $this->customFieldCreate(array('custom_group_id' => $ids['custom_group_id'], 'default_value' => '', 'label' => 'field_2' . $ids['custom_group_id']));
     $ids['custom_field_id'][] = $customField['id'];
 
-    $customField = $this->customFieldCreate($ids['custom_group_id'], 'field_3');
+    $customField = $this->customFieldCreate(array('custom_group_id' => $ids['custom_group_id'], 'default_value' => '', 'label' => 'field_3' . $ids['custom_group_id']));
     $ids['custom_field_id'][] = $customField['id'];
 
     return $ids;
@@ -1732,7 +1732,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     $entity = substr(basename($filename), 0, strlen(basename($filename)) - 8);
     $params['extends'] =  $entity ? $entity : 'Contact';
     $customGroup = $this->CustomGroupCreate($params);
-    $customField = $this->customFieldCreate($customGroup['id'], $function);
+    $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'], 'label' => $function));
     CRM_Core_PseudoConstant::flush();
 
     return array('custom_group_id' => $customGroup['id'], 'custom_field_id' => $customField['id']);
@@ -1744,7 +1744,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @param int    $customGroupID
    */
   function customGroupDelete($customGroupID) {
-
     $params['id'] = $customGroupID;
     return $this->callAPISuccess('custom_group', 'delete', $params);
   }
@@ -1752,22 +1751,19 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * Function to create custom field
    *
-   * @param int    $customGroupID
+   * @param array $params (custom_group_id) is required
    * @param string $name  name of custom field
    * @param int $apiversion API  version to use
    */
-  function customFieldCreate($customGroupID, $name = "Cust Field") {
-
-    $params = array(
-      'label' => $name,
-      'name' => $name,
-      'custom_group_id' => $customGroupID,
+  function customFieldCreate($params) {
+    $params = array_merge(array(
+      'label' => 'Custom Field',
       'data_type' => 'String',
       'html_type' => 'Text',
       'is_searchable' => 1,
       'is_active' => 1,
       'default_value' => 'defaultValue',
-    );
+    ), $params);
 
     $result = $this->callAPISuccess('custom_field', 'create', $params);
 
index 4a62bbbed8f6677597a4f97d567b3fd23dfa1287..d3f7bee1cdc1371a5a50616f09d745a64ac06a00 100644 (file)
@@ -1329,7 +1329,7 @@ class api_v3_ContactTest extends CiviUnitTestCase {
     $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
     $params['custom_' . $ids['custom_field_id']] = "custom string";
     $moreids = $this->CustomGroupMultipleCreateWithFields();
-    $andmoreids = $this->CustomGroupMultipleCreateWithFields(array('title' => "another group"));
+    $andmoreids = $this->CustomGroupMultipleCreateWithFields(array('title' => "another group", 'name' => 'another name'));
     $description = "/*this demonstrates the usage of chained api functions. A variety of techniques are used";
     $subfile = "APIChainedArrayMultipleCustom";
     $params = array(
index 672e22b4a569520f026fae6ef7c72d5eb291a049..f2ba51260d7f15d131ce492741cfc3b3fcb517d2 100644 (file)
@@ -247,7 +247,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
    */
   function testCustomFieldGetReturnOptions(){
     $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
-    $customField = $this->customFieldCreate($customGroup['id'], 'test_name');
+    $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
 
     $result = $this->callAPISuccess('custom_field', 'getsingle', array(
       'id' => $customField['id'],
@@ -262,7 +262,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
    */
   function testCustomFieldGetReturnArray(){
     $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
-    $customField = $this->customFieldCreate($customGroup['id'], 'test_name');
+    $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
 
     $result = $this->callAPISuccess('custom_field', 'getsingle', array(
            'id' => $customField['id'],
@@ -277,7 +277,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
    */
   function testCustomFieldGetReturnTwoOptions(){
     $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'test_group'));
-    $customField = $this->customFieldCreate($customGroup['id'], 'test_name');
+    $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
 
     $result = $this->callAPISuccess('custom_field', 'getsingle', array(
            'id' => $customField['id'],
@@ -365,7 +365,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
    */
   function testCustomFieldDelete() {
     $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
-    $customField = $this->customFieldCreate($customGroup['id'], 'test_name');
+    $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
     $this->assertNotNull($customField['id'], 'in line ' . __LINE__);
 
     $params = array(
index 258ceefd9f149258724a043bc7b419df85ecaf0c..a173bea0634a6f2ad97a1c995694a51191c5e01b 100644 (file)
@@ -61,7 +61,7 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase {
 
     $this->CustomGroupIndividual = $this->customGroupCreate($groupIndividual);
 
-    $this->IndividualField = $this->customFieldCreate($this->CustomGroupIndividual['id'], "Custom Field" . substr(sha1(rand()), 0, 7));
+    $this->IndividualField = $this->customFieldCreate(array('custom_group_id' => $this->CustomGroupIndividual['id']));
 
     //  Create Group For Individual-Student  Contact Sub  Type
     $groupIndiStudent = array(
@@ -73,7 +73,7 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase {
 
     $this->CustomGroupIndiStudent = $this->customGroupCreate($groupIndiStudent);
 
-    $this->IndiStudentField = $this->customFieldCreate($this->CustomGroupIndiStudent['id'], "Custom Field" . substr(sha1(rand()), 0, 7));
+    $this->IndiStudentField = $this->customFieldCreate(array('custom_group_id' => $this->CustomGroupIndiStudent['id']));
 
     $params = array(
       'first_name' => 'Mathev',
index 1ea078c79829c872497973705956c94ef783242a..5c1189662464811763429224325983f79476d2e8 100644 (file)
@@ -85,15 +85,17 @@ class api_v3_CustomValueTest extends CiviUnitTestCase {
 
     $result = $this->callAPISuccess('Contact', 'create', $params);
     $contact_id = $result['id'];
-    $result = $this->callAPISuccess('Contact', 'create',
-      array(
-        'contact_type' => 'Individual',
-        'id' => $contact_id,
-        'custom_' . $this->ids['multi']['custom_field_id'][0] => "value 3",
-        'custom_' . $this->ids['multi2']['custom_field_id'][0] => "coffee",
-        'custom_' . $this->ids['multi2']['custom_field_id'][1] => "value 4",
-      )
+    $firstCustomField = $this->ids['multi']['custom_field_id'][0];
+    $secondCustomField = $this->ids['multi2']['custom_field_id'][0];
+    $thirdCustomField = $this->ids['multi2']['custom_field_id'][1];
+    $createParams = array(
+      'contact_type' => 'Individual',
+      'id' => $contact_id,
+       'custom_' . $firstCustomField => "value 3",
+       'custom_' . $secondCustomField => "coffee",
+       'custom_' . $thirdCustomField => "value 4",
     );
+    $result = $this->callAPISuccess('Contact', 'create', $createParams);
 
     $params = array(
       'id' => $result['id'],
@@ -105,15 +107,16 @@ class api_v3_CustomValueTest extends CiviUnitTestCase {
     $resultformatted = $this->callAPIAndDocument('CustomValue', 'Get', $params, __FUNCTION__, __FILE__, "utilises field names", 'formatFieldName');
     // delete the contact
     $this->callAPISuccess('contact', 'delete', array('id' => $contact_id));
-
-    $this->assertEquals('coffee', $result['values'][$this->ids['multi2']['custom_field_id'][0]]['2'], "In line " . __LINE__);
-    $this->assertEquals('coffee', $result['values'][$this->ids['multi2']['custom_field_id'][0]]['latest'], "In line " . __LINE__);
-    $this->assertEquals($this->ids['multi2']['custom_field_id'][0], $result['values'][$this->ids['multi2']['custom_field_id'][0]]['id'], "In line " . __LINE__);
-    $this->assertEquals('', $result['values'][$this->ids['multi2']['custom_field_id'][0]]['1'], "In line " . __LINE__);
-    $this->assertEquals($contact_id, $result['values'][$this->ids['multi2']['custom_field_id'][0]]['entity_id'], "In line " . __LINE__);
-    $this->assertEquals('value 1', $result['values'][$this->ids['single']['custom_field_id']]['0'], "In line " . __LINE__);
-    $this->assertEquals('value 1', $result['values'][$this->ids['single']['custom_field_id']]['latest'], "In line " . __LINE__);
-    $this->assertEquals('value 1', $resultformatted['values']['mySingleField']['latest'], "In line " . __LINE__);
+    $this->assertEquals('coffee', $result['values'][$secondCustomField]['2']);
+    $this->assertEquals('coffee', $result['values'][$secondCustomField]['latest']);
+    $this->assertEquals($secondCustomField, $result['values'][$secondCustomField]['id']);
+    $this->assertEquals('defaultValue', $result['values'][$secondCustomField]['1']);
+    $this->assertEquals($contact_id, $result['values'][$secondCustomField]['entity_id']);
+    $this->assertEquals('value 1', $result['values'][$this->ids['single']['custom_field_id']]['0']);
+    $this->assertEquals('value 1', $result['values'][$this->ids['single']['custom_field_id']]['latest']);
+    $this->assertEquals('value 1', $resultformatted['values']['mySingleField']['latest']);
+    $this->assertEquals('', $result['values'][$thirdCustomField]['1']);
+    $this->assertEquals('value 4', $result['values'][$thirdCustomField]['2']);
   }
 }
 
index 61f3ef99b18fd63882ca531b9e0f9725fc382359..01d9fb179f47857b026350a1b3a56eb97fe423bc 100644 (file)
@@ -287,7 +287,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     $this->assertFalse(array_key_exists('participant_status', $result['values']));
   }
   /**
-   * Check getfields works & gives us our fields
+   * Check getfields works & gives us our fields - partipant profile
    */
   function testGetFieldsParticipantProfile() {
     $result = $this->callAPISuccess('profile', 'getfields', array(
@@ -298,6 +298,36 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
     $this->assertTrue(array_key_exists('participant_status', $result['values']));
     $this->assertEquals('Attended', $result['values']['participant_status']['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() {
+    $result = $this->callAPISuccess('profile', 'getfields', array(
+      'action' => 'submit',
+      'profile_id' => 'membership_batch_entry',
+      'get_options' => 'all')
+    );
+    $this->assertTrue(array_key_exists('total_amount', $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() {
+    $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')
+    );
+    }
+  }
   /////////////// test $this->callAPISuccess3_profile_set //////////////////
 
   /**