CRM-13234 one line fix for test failure caused by change to set-up class
authoreileen <eileen@fuzion.co.nz>
Tue, 20 Aug 2013 08:16:08 +0000 (20:16 +1200)
committereileen <eileen@fuzion.co.nz>
Tue, 20 Aug 2013 08:16:08 +0000 (20:16 +1200)
Well - it would have been one line - except then I wanted to keep testing what happens when the custom field has a default value (the breakage) & without (per before) so then I wound up having to fix up the function signature too

api/v3/CustomValue.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
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

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 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 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']);
   }
 }