Merge pull request #4185 from samuelsov/CRM-15330
[civicrm-core.git] / tests / phpunit / api / v3 / CustomFieldTest.php
index 6c5850fdd4834ce5c2d6a48dc2f0fb85f404bb6e..de09416c29e238561a692150e7198595448dcad5 100644 (file)
@@ -23,7 +23,7 @@
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *  Include class definitions
@@ -46,7 +46,8 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
 
   public function tearDown() {
     $tablesToTruncate = array(
-      'civicrm_custom_group', 'civicrm_custom_field',
+      'civicrm_custom_group',
+      'civicrm_custom_field',
     );
     // true tells quickCleanup to drop any tables that might have been created in the test
     $this->quickCleanup($tablesToTruncate, TRUE);
@@ -101,9 +102,9 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
       'is_active' => 1,
     );
 
-    $customField  = $this->callAPIAndDocument('custom_field', 'create', $params, __FUNCTION__, __FILE__);
+    $customField = $this->callAPIAndDocument('custom_field', 'create', $params, __FUNCTION__, __FILE__);
     $params['id'] = $customField['id'];
-    $customField  = $this->callAPISuccess('custom_field', 'create', $params);
+    $customField = $this->callAPISuccess('custom_field', 'create', $params);
 
     $this->assertNotNull($customField['id'], 'in line ' . __LINE__);
   }
@@ -131,7 +132,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
 
   /**
    * Check for Each data type: loop through available form input types
-   **/
+   */
   public function testCustomFieldCreateAllAvailableFormInputs() {
     $gid = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'testAllFormInputs'));
 
@@ -148,8 +149,8 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
     }
   }
   /*
-  * Can't figure out the point of this?
-  */
+   * Can't figure out the point of this?
+   */
   /**
    * @param array $params
    */
@@ -169,14 +170,14 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
   public function _buildParams($gid, $htype, $dtype) {
     $params = $this->_buildBasicParams($gid, $htype, $dtype);
     /* //Not Working for any type. Maybe redundant with testCustomFieldCreateWithOptionValues()
-        if ($htype == 'Multi-Select')
-            $params = array_merge($params, array(
-                         'option_label'    => array( 'Label1','Label2'),
-                         'option_value'    => array( 'val1', 'val2' ),
-                         'option_weight'   => array( 1, 2),
-                         'option_status'   => array( 1, 1),
-                         ));
-    */
+    if ($htype == 'Multi-Select')
+    $params = array_merge($params, array(
+    'option_label'    => array( 'Label1','Label2'),
+    'option_value'    => array( 'val1', 'val2' ),
+    'option_weight'   => array( 1, 2),
+    'option_status'   => array( 1, 1),
+    ));
+     */
 
     return $params;
   }
@@ -206,15 +207,15 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
    *  Test  using example code
    */
   /*function testCustomFieldCreateExample( )
-    {
+  {
 
 
-        $customGroup = $this->customGroupCreate('Individual','date_test_group',3);
-        require_once 'api/v3/examples/CustomField/Create.php';
-        $result = custom_field_create_example();
-        $expectedResult = custom_field_create_expectedresult();
-        $this->assertEquals($result,$expectedResult);
-    }*/
+  $customGroup = $this->customGroupCreate('Individual','date_test_group',3);
+  require_once 'api/v3/examples/CustomField/Create.php';
+  $result = custom_field_create_example();
+  $expectedResult = custom_field_create_expectedresult();
+  $this->assertEquals($result,$expectedResult);
+  }*/
 
   /**
    * Check with data type - Options with option_values
@@ -241,10 +242,12 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
 
     $this->assertTrue(is_numeric($optionGroupID) && ($optionGroupID > 0));
     $optionGroup = $this->callAPISuccess('option_group', 'getsingle', array(
-      'id' => $optionGroupID));
+      'id' => $optionGroupID,
+    ));
     $this->assertEquals($optionGroup['title'], 'Country');
     $optionValueCount = $this->callAPISuccess('option_value', 'getcount', array(
-      'option_group_id' => $optionGroupID));
+      'option_group_id' => $optionGroupID,
+    ));
     $this->assertEquals(0, $optionValueCount);
   }
 
@@ -301,7 +304,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
     $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
 
     $result = $this->callAPISuccess('custom_field', 'getsingle', array(
-           'id' => $customField['id'],
+      'id' => $customField['id'],
       'return' => array('data_type'),
     ));
     $this->assertTrue(array_key_exists('data_type', $result));
@@ -316,7 +319,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
     $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
 
     $result = $this->callAPISuccess('custom_field', 'getsingle', array(
-           'id' => $customField['id'],
+      'id' => $customField['id'],
       'return' => 'data_type, custom_group_id',
     ));
     $this->assertTrue(array_key_exists('data_type', $result));
@@ -329,7 +332,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
 
     $option_values = array(
       array(
-    'weight' => 1,
+        'weight' => 1,
         'label' => 'Label1',
         'value' => 1,
         'is_active' => 1,
@@ -361,16 +364,16 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
     $this->assertNotNull($customField['id']);
     $getFieldsParams = array(
       'options' => array('get_options' => 'custom_' . $customField['id']),
-           'action' => 'create',
+      'action' => 'create',
     );
-    $description  = "Demonstrate retrieving metadata with custom field options";
+    $description = "Demonstrate retrieving metadata with custom field options";
     $subfile = "GetFieldsOptions";
     $fields = $this->callAPIAndDocument('contact', 'getfields', $getFieldsParams, __FUNCTION__, 'ContactTest.php', $description, $subfile, 'GetFields');
     $this->assertArrayHasKey('options', $fields['values']['custom_' . $customField['id']]);
     $this->assertEquals('Label1', $fields['values']['custom_' . $customField['id']]['options'][1]);
     $getOptionsArray = array(
       'field' => 'custom_' . $customField['id'],
-         );
+    );
     $description = "Demonstrates retrieving options for a custom field";
     $subfile = "GetOptions";
     $result = $this->callAPIAndDocument('contact', 'getoptions', $getOptionsArray, __FUNCTION__, 'ContactTest.php', $description, '', 'getoptions');
@@ -446,11 +449,17 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
 
     // Add some fields
     $contactGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'test_group_c'));
-    $contactField = $this->customFieldCreate(array('custom_group_id' => $contactGroup['id'], 'label' => 'For Contacts'));
+    $contactField = $this->customFieldCreate(array(
+        'custom_group_id' => $contactGroup['id'],
+        'label' => 'For Contacts',
+      ));
     $indivGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group_i'));
     $indivField = $this->customFieldCreate(array('custom_group_id' => $indivGroup['id'], 'label' => 'For Individuals'));
     $activityGroup = $this->customGroupCreate(array('extends' => 'Activity', 'title' => 'test_group_a'));
-    $activityField = $this->customFieldCreate(array('custom_group_id' => $activityGroup['id'], 'label' => 'For Activities'));
+    $activityField = $this->customFieldCreate(array(
+        'custom_group_id' => $activityGroup['id'],
+        'label' => 'For Activities',
+      ));
 
     // Check getfields
     $this->assertEquals(
@@ -488,11 +497,12 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
    * @return array
    */
   public function getCustomFieldKeys($getFieldsResult) {
-    $isCustom = function($key) {
+    $isCustom = function ($key) {
       return preg_match('/^custom_/', $key);
     };
     $r = array_values(array_filter(array_keys($getFieldsResult['values']), $isCustom));
     sort($r);
     return $r;
   }
+
 }