whitespace
[civicrm-core.git] / tests / phpunit / api / v3 / SyntaxConformanceTest.php
index 8d01a2a0c50604865c9a7f2fcdca7a39d8f642e7..a3a4e564789f4414c1cfb81ca19e673823989cc8 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -1074,9 +1074,9 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     $baoString = _civicrm_api3_get_BAO($entityName);
     $this->assertNotEmpty($baoString, $entityName);
     $this->assertNotEmpty($entityName, $entityName);
-    $fieldsGet = $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'get'));
+    $fieldsGet = $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'get', 'options' => array('get_options' => 'all')));
     if ($entityName != 'Pledge') {
-      $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create'));
+      $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create', 'options' => array('get_options' => 'all')));
     }
     $fields = $fields['values'];
     $return = array_keys($fieldsGet['values']);
@@ -1121,10 +1121,13 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       $this->assertArrayHasKey('type', $specs, "the _spec function for $entityName field $field does not specify the type");
       switch ($specs['type']) {
         case CRM_Utils_Type::T_DATE:
-        case CRM_Utils_Type::T_TIMESTAMP:
           $entity[$fieldName] = '2012-05-20';
           break;
 
+        case CRM_Utils_Type::T_TIMESTAMP:
+          // 4.6 doesn't support timestamp updates from 4.7 we should uncomment this. See CRM-16204
+          continue;
+
         //case CRM_Utils_Type::T_DATETIME:
 
         case 12:
@@ -1179,23 +1182,27 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
         case CRM_Utils_Type::T_URL:
           $entity[$field] = 'warm.beer.com';
       }
-      if (!empty($specs['pseudoconstant'])) {
-        $options = $this->callAPISuccess($entityName, 'getoptions', array('context' => 'create', 'field' => $field));
-        if (empty($options['values'])) {
+      if (empty($specs['FKClassName']) && (!empty($specs['pseudoconstant']) || !empty($specs['options']))) {
+        $options = CRM_Utils_Array::value('options', $specs, array());
+        if (!$options) {
           //eg. pdf_format id doesn't ship with any
           if (isset($specs['pseudoconstant']['optionGroupName'])) {
-            $optionGroupID = $this->callAPISuccess('option_group', 'getvalue', array(
-                'name' => 'pdf_format',
-                'return' => 'id',
-              ));
             $optionValue = $this->callAPISuccess('option_value', 'create', array(
-                'option_group_id' => $optionGroupID,
+                'option_group_id' => $specs['pseudoconstant']['optionGroupName'],
                 'label' => 'new option value',
+                'sequential' => 1,
               ));
-            $options['values'][] = $optionValue['id'];
+            $optionValue = $optionValue['values'];
+            $options[$optionValue[0]['value']] = 'new option value';
           }
         }
-        $entity[$field] = array_rand($options['values']);
+        $entity[$field] = array_rand($options);
+      }
+      if (!empty($specs['FKClassName']) && !empty($specs['pseudoconstant'])) {
+        // in the weird situation where a field has both an fk and pseudoconstant defined,
+        // e.g. campaign_id field, need to flush caches.
+        // FIXME: Why doesn't creating a campaign clear caches?
+        civicrm_api3($entityName, 'getfields', array('cache_clear' => 1));
       }
       $updateParams = array(
         'id' => $entity['id'],