whitespace
[civicrm-core.git] / tests / phpunit / api / v3 / SyntaxConformanceTest.php
index 2fe3a5c0e5a0a30efa8ac433f1797038508148f3..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.                                    |
  |                                                                    |
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 require_once 'CiviTest/CiviUnitTestCase.php';
 
@@ -47,12 +47,16 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
    */
   protected $deletableTestObjects;
 
-  /** This test case doesn't require DB reset */
+  /**
+   * This test case doesn't require DB reset.
+   */
   public $DBResetRequired = FALSE;
 
   protected $_entity;
 
-  /** Map custom group entities to civicrm components */
+  /**
+   * Map custom group entities to civicrm components.
+   */
   static $componentMap = array(
     'Contribution' => 'CiviContribute',
     'Membership' => 'CiviMember',
@@ -192,6 +196,11 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     return static::entities(static::toBeSkipped_getlimit());
   }
 
+  /**
+   * Generate list of entities that can be retrieved using SQL operator syntax.
+   *
+   * @return array
+   */
   public static function entities_getSqlOperators() {
     return static::entities(static::toBeSkipped_getSqlOperators());
   }
@@ -317,7 +326,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       'Domain',
       'Profile',
       'CustomValue',
-      'Setting'
+      'Setting',
     );
     if ($sequential === TRUE) {
       return $entitiesWithout;
@@ -348,7 +357,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
   }
 
   /**
-   * Generate list of entities to test for get by id functions
+   * Generate list of entities to test for get by id functions.
    * @param bool $sequential
    * @return array
    *   Entities to be skipped
@@ -365,7 +374,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       'CustomSearch',
       'Extension',
       'ReportTemplate',
-      'System'
+      'System',
     );
     if ($sequential === TRUE) {
       return $entitiesWithoutGet;
@@ -439,7 +448,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       'PaymentProcessor',
       'Setting',
       'MailingContact',
-      'SystemLog'
+      'SystemLog',
       //skip this because it doesn't make sense to update logs,
     );
     if ($sequential === TRUE) {
@@ -550,7 +559,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
           'installments',
           'original_installment_amount',
           'next_pay_date',
-          'amount' // can't be changed through API,
+          'amount', // can't be changed through API,
         ),
         'break_return' => array(// if these are passed in they are retrieved from the wrong table
           'honor_contact_id',
@@ -597,11 +606,11 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     return $knownFailures[$entity][$key];
   }
 
-  /** testing the _get **/
+  /* ----- testing the _get  ----- */
 
   /**
    * @dataProvider toBeSkipped_get
-  entities that don't need a get action
+   *   Entities that don't need a get action
    * @param $Entity
    */
   public function testNotImplemented_get($Entity) {
@@ -742,7 +751,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
   }
 
   /**
-   * Create two entities and make sure we can fetch them individually by ID
+   * Create two entities and make sure we can fetch them individually by ID.
    *
    * @dataProvider entities_get
    *
@@ -880,7 +889,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
   }
 
   /**
-   * Check that get fetches an appropriate number of results
+   * Check that get fetches an appropriate number of results.
    *
    * @param string $entityName
    *   Name of entity to test.
@@ -928,10 +937,10 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
 
     // create entities
     $baoObj1 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
-    $this->assertTrue(is_integer($baoObj1->id), 'check first id');
+    $this->assertTrue(is_int($baoObj1->id), 'check first id');
     $this->deletableTestObjects[$baoString][] = $baoObj1->id;
     $baoObj2 = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
-    $this->assertTrue(is_integer($baoObj2->id), 'check second id');
+    $this->assertTrue(is_int($baoObj2->id), 'check second id');
     $this->deletableTestObjects[$baoString][] = $baoObj2->id;
 
     // fetch first by ID
@@ -980,7 +989,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     }
   }
 
-  /** testing the _create **/
+  /* ---- testing the _create ---- */
 
   /**
    * @dataProvider toBeSkipped_create
@@ -1065,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']);
@@ -1112,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:
@@ -1170,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,
-                'label' => 'new option value'
+                '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'],
@@ -1214,7 +1230,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
             'update-result' => $update,
             'getsingle-params' => $checkParams,
             'getsingle-result' => $checkEntity,
-            'expected entity' => $entity
+            'expected entity' => $entity,
           ), TRUE));
       if ($resetFKTo) {
         //reset the foreign key fields because otherwise our cleanup routine fails & some other unexpected stuff can kick in
@@ -1230,9 +1246,9 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     $baoObj->free();
   }
 
-  /** testing the _getFields **/
+  /* ---- testing the _getFields ---- */
 
-  /** testing the _delete **/
+  /* ---- testing the _delete ---- */
 
   /**
    * @dataProvider toBeSkipped_delete
@@ -1403,7 +1419,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     while ($i < $count) {
       // create entities
       $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
-      $this->assertTrue(is_integer($baoObj->id), 'check first id');
+      $this->assertTrue(is_int($baoObj->id), 'check first id');
       $this->deletableTestObjects[$baoString][] = $baoObj->id;
       $baos[] = $baoObj;
       $i++;
@@ -1413,7 +1429,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
 
 
   /**
-   * Verify that HTML metacharacters provided as inputs appear consistently
+   * Verify that HTML metacharacters provided as inputs appear consistently.
    * as outputs.
    *
    * At time of writing, the encoding scheme requires (for example) that an
@@ -1557,4 +1573,5 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       1 => array($eventId, 'Integer'),
     ));
   }
+
 }