Merge pull request #4906 from eileenmcnaughton/minor-tidies
[civicrm-core.git] / tests / phpunit / api / v3 / SyntaxConformanceTest.php
index 6c2de0c69ed65504a0051b4ccf1ebd4bece1c0a2..c2f96504ecb1c69fb3f84574a6e2621692d23413 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -39,7 +39,6 @@ require_once 'CiviTest/CiviUnitTestCase.php';
  * @package CiviCRM_APIv3
  * @subpackage API_Core
  */
-
 class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
   protected $_apiversion = 3;
 
@@ -55,21 +54,15 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
 
   /** Map custom group entities to civicrm components */
   static $componentMap = array(
-    'Contact' => NULL,
-    'Individual' => NULL,
-    'Household' => NULL,
-    'Organization' => NULL,
     'Contribution' => 'CiviContribute',
     'Membership' => 'CiviMember',
     'Participant' => 'CiviEvent',
-    'Group' => NULL,
-    'Relationship' => NULL,
     'Event' => 'CiviEvent',
     'Case' => 'CiviCase',
-    'Activity' => NULL,
     'Pledge' => 'CiviPledge',
     'Grant' => 'CiviGrant',
-    'Address' => NULL,
+    'Campaign' => 'CiviCampaign',
+    'Survey' => 'CiviCampaign',
   );
 
   /* they are two types of missing APIs:
@@ -79,18 +72,46 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
          and that will never exist (eg an obsoleted Entity
          they need to be returned by the function toBeSkipped_{$action} (because it has to be a static method and therefore couldn't access a this->toBeSkipped)
     */
-  function setUp() {
+  public function setUp() {
     parent::setUp();
     $this->enableCiviCampaign();
-    $this->toBeImplemented['get'] = array('Profile', 'CustomValue', 'Constant', 'CustomSearch', 'Extension', 'ReportTemplate', 'System', 'Setting');
-    $this->toBeImplemented['create'] = array('SurveyRespondant', 'OptionGroup', 'MailingRecipients', 'UFMatch', 'LocationType', 'CustomSearch', 'Extension', 'ReportTemplate', 'System');
-    $this->toBeImplemented['delete'] = array('MembershipPayment', 'OptionGroup', 'SurveyRespondant', 'UFJoin', 'UFMatch', 'Extension', 'LocationType', 'System');
-    $this->onlyIDNonZeroCount['get'] = array('ActivityType', 'Entity', 'Domain','Setting');
+    $this->toBeImplemented['get'] = array(
+      'Profile',
+      'CustomValue',
+      'Constant',
+      'CustomSearch',
+      'Extension',
+      'ReportTemplate',
+      'System',
+      'Setting'
+    );
+    $this->toBeImplemented['create'] = array(
+      'SurveyRespondant',
+      'OptionGroup',
+      'MailingRecipients',
+      'UFMatch',
+      'LocationType',
+      'CustomSearch',
+      'Extension',
+      'ReportTemplate',
+      'System'
+    );
+    $this->toBeImplemented['delete'] = array(
+      'MembershipPayment',
+      'OptionGroup',
+      'SurveyRespondant',
+      'UFJoin',
+      'UFMatch',
+      'Extension',
+      'LocationType',
+      'System'
+    );
+    $this->onlyIDNonZeroCount['get'] = array('ActivityType', 'Entity', 'Domain', 'Setting');
     $this->deprecatedAPI = array('Location', 'ActivityType', 'SurveyRespondant');
     $this->deletableTestObjects = array();
   }
 
-  function tearDown() {
+  public function tearDown() {
     foreach ($this->deletableTestObjects as $entityName => $entities) {
       foreach ($entities as $entityID) {
         CRM_Core_DAO::deleteTestObjects($entityName, array('id' => $entityID));
@@ -112,7 +133,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     $tmp = civicrm_api('Entity', 'Get', array('version' => 3));
     if (getenv('SYNTAX_CONFORMANCE_ENTITIES')) {
       $tmp = array(
-        'values' => explode(' ', getenv('SYNTAX_CONFORMANCE_ENTITIES'))
+        'values' => explode(' ', getenv('SYNTAX_CONFORMANCE_ENTITIES')),
       );
     }
 
@@ -159,6 +180,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
   public static function entities_getSqlOperators() {
     return static::entities(static::toBeSkipped_getSqlOperators());
   }
+
   /**
    * @return array
    */
@@ -172,6 +194,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
   public static function entities_getfields() {
     return static::entities(static::toBeSkipped_getfields(TRUE));
   }
+
   /**
    * @return array
    */
@@ -183,17 +206,19 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
    * @return array
    */
   public static function custom_data_entities() {
-    $enableComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
     $entities = CRM_Core_BAO_CustomQuery::$extendsMap;
-    $components = self::$componentMap;
+    $enabledComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
     $customDataEntities = array();
     $invalidEntities = array('Individual', 'Organization', 'Household');
     $entitiesToFix = array('Case', 'Relationship');
-    foreach ($entities as $entityName => $entity ) {
-      if(!in_array($entityName, $invalidEntities)
+    foreach ($entities as $entityName => $entity) {
+      if (!in_array($entityName, $invalidEntities)
         && !in_array($entityName, $entitiesToFix)
-        && (!empty($components[$entityName]) && in_array($components[$entityName], $enableComponents) || $components[$entityName] == NULL)) {
-        $customDataEntities[] = array($entityName );
+      ) {
+        if (!empty(self::$componentMap[$entityName]) && empty($enabledComponents[self::$componentMap[$entityName]])) {
+          CRM_Core_BAO_ConfigSetting::enableComponent(self::$componentMap[$entityName]);
+        }
+        $customDataEntities[] = array($entityName);
       }
     }
     return $customDataEntities;
@@ -205,7 +230,13 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
    * @return array
    */
   public static function toBeSkipped_get($sequential = FALSE) {
-    $entitiesWithoutGet = array('MailingEventSubscribe', 'MailingEventConfirm', 'MailingEventResubscribe', 'MailingEventUnsubscribe', 'Location');
+    $entitiesWithoutGet = array(
+      'MailingEventSubscribe',
+      'MailingEventConfirm',
+      'MailingEventResubscribe',
+      'MailingEventUnsubscribe',
+      'Location'
+    );
     if ($sequential === TRUE) {
       return $entitiesWithoutGet;
     }
@@ -218,15 +249,17 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
 
   /**
    * Mailing Contact Just doesn't support id. We have always insisted on finding a way to
-   * support id in API but in this case the underlying tables are crying out for a restructue
-   * & it just doesn't make sense
+   * support id in API but in this case the underlying tables are crying out for a restructure
+   * & it just doesn't make sense, on the otherhand Event need id to be existant as pseudo property
+   * is been associated with it, so we need to bypass for get api otherwise it will through pseudo_match validation
    *
-   * @param bool|\unknown_type $sequential
+   * @param bool $sequential
    *
-   * @return multitype:string |multitype:multitype:string
+   * @return array
+   *   Entities that cannot be retrieved by ID
    */
   public static function toBeSkipped_getByID($sequential = FALSE) {
-    return array('MailingContact');
+    return array('MailingContact', 'Event');
   }
 
   /**
@@ -252,7 +285,21 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
    * @return array
    */
   public static function toBeSkipped_delete($sequential = FALSE) {
-    $entitiesWithout = array('MailingContact', 'MailingEventConfirm', 'MailingEventResubscribe', 'MailingEventSubscribe', 'MailingEventUnsubscribe', 'MailingRecipients', 'Constant', 'Entity', 'Location', 'Domain', 'Profile', 'CustomValue', 'Setting');
+    $entitiesWithout = array(
+      'MailingContact',
+      'MailingEventConfirm',
+      'MailingEventResubscribe',
+      'MailingEventSubscribe',
+      'MailingEventUnsubscribe',
+      'MailingRecipients',
+      'Constant',
+      'Entity',
+      'Location',
+      'Domain',
+      'Profile',
+      'CustomValue',
+      'Setting'
+    );
     if ($sequential === TRUE) {
       return $entitiesWithout;
     }
@@ -272,7 +319,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
   public static function toBeSkipped_getfields($sequential = FALSE) {
     $entitiesWithMetadataNotYetFixed = array('ReportTemplate', 'CustomSearch');
     if ($sequential === TRUE) {
-      return $entitiesWithMetadataNotYetFixed ;
+      return $entitiesWithMetadataNotYetFixed;
     }
     $entities = array();
     foreach ($entitiesWithMetadataNotYetFixed as $e) {
@@ -280,13 +327,27 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     }
     return $entities;
   }
-/**
- * Generate list of entities to test for get by id functions
- * @param boolean $sequential
- * @return multitype:string |multitype:multitype:string
- */
+
+  /**
+   * Generate list of entities to test for get by id functions
+   * @param bool $sequential
+   * @return array
+   *   Entities to be skipped
+   */
   public static function toBeSkipped_automock($sequential = FALSE) {
-    $entitiesWithoutGet = array('MailingContact', 'EntityTag', 'Participant', 'ParticipantPayment', 'Setting', 'SurveyRespondant', 'MailingRecipients',  'CustomSearch', 'Extension', 'ReportTemplate', 'System');
+    $entitiesWithoutGet = array(
+      'MailingContact',
+      'EntityTag',
+      'Participant',
+      'ParticipantPayment',
+      'Setting',
+      'SurveyRespondant',
+      'MailingRecipients',
+      'CustomSearch',
+      'Extension',
+      'ReportTemplate',
+      'System'
+    );
     if ($sequential === TRUE) {
       return $entitiesWithoutGet;
     }
@@ -299,11 +360,12 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
 
 
   /**
-  * At this stage exclude the ones that don't pass & add them as we can troubleshoot them
-  */
+   * At this stage exclude the ones that don't pass & add them as we can troubleshoot them
+   */
   public static function toBeSkipped_updatesingle($sequential = FALSE) {
     $entitiesWithout = array(
-      'Attachment', // pseudo-entity; testUpdateSingleValueAlter doesn't introspect properly on it. Multiple magic fields
+      'Attachment',
+      // pseudo-entity; testUpdateSingleValueAlter doesn't introspect properly on it. Multiple magic fields
       'Mailing',
       'MailingGroup',
       'MailingJob',
@@ -356,7 +418,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       'PaymentProcessor',
       'Setting',
       'MailingContact',
-      'SystemLog' //skip this because it doesn't make sense to update logs
+      'SystemLog'
+      //skip this because it doesn't make sense to update logs,
     );
     if ($sequential === TRUE) {
       return $entitiesWithout;
@@ -376,12 +439,18 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
    */
   public static function toBeSkipped_getlimit() {
     $entitiesWithout = array(
-      'Case',//case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id)
-      'EntityTag', // non-standard api - has inappropriate mandatory fields & doesn't implement limit
-      'Event', // failed 'check that a 5 limit returns 5' - probably is_template field is wrong or something, or could be limit doesn't work right
-      'Extension', // can't handle creating 25
-      'Note', // fails on 5 limit - probably a set up problem
-      'Setting', //a bit of a pseudoapi - keys by domain
+      'Case',
+      //case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id)
+      'EntityTag',
+      // non-standard api - has inappropriate mandatory fields & doesn't implement limit
+      'Event',
+      // failed 'check that a 5 limit returns 5' - probably is_template field is wrong or something, or could be limit doesn't work right
+      'Extension',
+      // can't handle creating 25
+      'Note',
+      // fails on 5 limit - probably a set up problem
+      'Setting',
+      //a bit of a pseudoapi - keys by domain
     );
     return $entitiesWithout;
   }
@@ -391,7 +460,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
    */
   public static function toBeSkipped_getSqlOperators() {
     $entitiesWithout = array(
-      'Case',//case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id)
+      'Case', //case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id)
       'Contact', // on the todo list!
       'EntityTag', // non-standard api - has inappropriate mandatory fields & doesn't implement limit
       'Extension', // can't handle creating 25
@@ -407,7 +476,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
    *
    * @return array
    */
-  public function getKnownUnworkablesUpdateSingle($entity, $key){
+  public function getKnownUnworkablesUpdateSingle($entity, $key) {
     // can't update values are values for which updates don't result in the value being changed
     $knownFailures = array(
       'ActionSchedule' => array(
@@ -417,16 +486,16 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       ),
       'ActivityContact' => array(
         'cant_update' => array(
-          'activity_id', //we have an FK on activity_id + contact_id + record id so if we don't leave this one distinct we get an FK constraint error
+          'activity_id',
+          //we have an FK on activity_id + contact_id + record id so if we don't leave this one distinct we get an FK constraint error
         ),
       ),
       'Address' => array(
         'cant_update' => array(
           'state_province_id', //issues with country id - need to ensure same country
-          'master_id',//creates relationship
+          'master_id', //creates relationship
         ),
-        'cant_return' => array(
-        )
+        'cant_return' => array(),
       ),
       'Batch' => array(
         'cant_update' => array(
@@ -434,19 +503,25 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
         ),
         'cant_return' => array(
           'entity_table',
-        )
+        ),
       ),
       'CaseType' => array(
         'cant_update' => array(
           'definition',
-        )
+        ),
       ),
       'MembershipBlock' => array(
         'cant_update' => array(
           // The fake/auto-generated values leave us unable to properly cleanup fake data
           'entity_type',
           'entity_id',
-        )
+        ),
+      ),
+      'ContributionSoft' => array(
+        'cant_update' => array(
+          // can't be changed through api
+          'pcp_id',
+        ),
       ),
       'Pledge' => array(
         'cant_update' => array(
@@ -454,7 +529,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',
@@ -462,7 +537,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
           'contribution_page_id',
           'financial_account_id',
           'financial_type_id',
-          'currency'
+          'currency',
         ),
         'cant_return' => array(// can't be retrieved from api
           'honor_type_id', //due to uniquename missing
@@ -480,16 +555,14 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
           'pledge_status_id',
           'pledge_campaign_id',
           'pledge_financial_type_id',
-        )
+        ),
       ),
       'PaymentProcessorType' => array(
         'cant_update' => array(
           'billing_mode',
         ),
-        'break_return' => array(
-        ),
-        'cant_return' => array(
-        ),
+        'break_return' => array(),
+        'cant_return' => array(),
       ),
       'PriceFieldValue' => array(
         'cant_update' => array(
@@ -497,7 +570,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
         ),
       ),
     );
-    if(empty($knownFailures[$entity]) || empty($knownFailures[$entity][$key])){
+    if (empty($knownFailures[$entity]) || empty($knownFailures[$entity][$key])) {
       return array();
     }
     return $knownFailures[$entity][$key];
@@ -507,13 +580,13 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
 
   /**
    * @dataProvider toBeSkipped_get
-   entities that don't need a get action
+  entities that don't need a get action
    */
   public function testNotImplemented_get($Entity) {
     $result = civicrm_api($Entity, 'Get', array('version' => 3));
     $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__);
     // $this->assertContains("API ($Entity, Get) does not exist", $result['error_message']);
-    $this->assertRegExp('/API (.*) does not exist/',  $result['error_message']);
+    $this->assertRegExp('/API (.*) does not exist/', $result['error_message']);
   }
 
   /**
@@ -553,6 +626,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__);
     $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']);
   }
+
   /**
    * @dataProvider entities_get
    */
@@ -566,6 +640,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     $this->assertEquals(2000, $result['error_code']);
     $this->assertEquals('Input variable `params` is not an array', $result['error_message']);
   }
+
   /**
    * @dataProvider entities_get
    * @Xdepends testEmptyParam_get // no need to test the simple if the empty doesn't work/is skipped. doesn't seem to work
@@ -616,7 +691,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     // big random number. fun fact: if you multiply it by pi^e, the result is another random number, but bigger ;)
     $nonExistantID = 30867307034;
     if (in_array($Entity, $this->toBeImplemented['get'])
-        || in_array($Entity, $this->toBeSkipped_getByID())
+      || in_array($Entity, $this->toBeSkipped_getByID())
     ) {
       return;
     }
@@ -683,9 +758,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
    * @dataProvider entities_getlimit
    *
    * @param string $entityName
-   *
    */
-  function testLimit($entityName) {
+  public function testLimit($entityName) {
     $cases = array(); // each case is array(0 => $inputtedApiOptions, 1 => $expectedResultCount)
     $cases[] = array(
       array('options' => array('limit' => NULL)),
@@ -731,7 +805,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       $this->checkLimitAgainstExpected($entityName, $case[0], $case[1], $case[2]);
 
       //non preferred / legacy syntax
-      if(isset($case[0]['options']['limit'])) {
+      if (isset($case[0]['options']['limit'])) {
         $this->checkLimitAgainstExpected($entityName, array('rowCount' => $case[0]['options']['limit']), $case[1], $case[2]);
         $this->checkLimitAgainstExpected($entityName, array('option_limit' => $case[0]['options']['limit']), $case[1], $case[2]);
         $this->checkLimitAgainstExpected($entityName, array('option.limit' => $case[0]['options']['limit']), $case[1], $case[2]);
@@ -749,9 +823,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
    * @dataProvider entities_getSqlOperators
    *
    * @param string $entityName
-   *
    */
-  function testSqlOperators($entityName) {
+  public function testSqlOperators($entityName) {
     $baoString = _civicrm_api3_get_BAO($entityName);
     if (empty($baoString)) {
       $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO");
@@ -779,14 +852,15 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
   /**
    * Check that get fetches an appropriate number of results
    *
-   * @param string $entityName Name of entity to test
+   * @param string $entityName
+   *   Name of entity to test.
    * @param array $params
-   * @param integer $limit
+   * @param int $limit
    * @param string $message
    */
-  function checkLimitAgainstExpected($entityName, $params, $limit, $message) {
+  public function checkLimitAgainstExpected($entityName, $params, $limit, $message) {
     $result = $this->callAPISuccess($entityName, 'get', $params);
-    if($limit == 30) {
+    if ($limit == 30) {
       $this->assertGreaterThanOrEqual($limit, $result['count'], $message);
       $this->assertGreaterThanOrEqual($limit, $result['count'], $message);
     }
@@ -795,6 +869,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       $this->assertEquals($limit, count($result['values']), $message);
     }
   }
+
   /**
    * Create two entities and make sure we can fetch them individually by ID (e.g. using "contact_id=>2"
    * or "group_id=>4")
@@ -865,7 +940,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       return;
     }
 
-
     $this->assertArrayHasKey('version', $result);
     $this->assertEquals(3, $result['version']);
     if (!in_array($Entity, $this->onlyIDNonZeroCount['get'])) {
@@ -877,7 +951,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
 
   /**
    * @dataProvider toBeSkipped_create
-   entities that don't need a create action
+  entities that don't need a create action
    */
   public function testNotImplemented_create($Entity) {
     $result = civicrm_api($Entity, 'Create', array('version' => 3));
@@ -901,7 +975,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     $this->markTestIncomplete("fixing this test to test the api functions fails on numberous tests
       which will either create a completely blank entity (batch, participant status) or
       have a damn good crack at it (e.g mailing job). Marking this as incomplete beats false success");
-    //
     return;
     if (in_array($Entity, $this->toBeImplemented['create'])) {
       // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
@@ -953,20 +1026,20 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     $this->assertNotEmpty($baoString, $entityName);
     $this->assertNotEmpty($entityName, $entityName);
     $fieldsGet = $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'get'));
-    if($entityName != 'Pledge'){
+    if ($entityName != 'Pledge') {
       $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create'));
     }
     $fields = $fields['values'];
     $return = array_keys($fieldsGet['values']);
     $valuesNotToReturn = $this->getKnownUnworkablesUpdateSingle($entityName, 'break_return');
-      // these can't be requested as return values
+    // these can't be requested as return values
     $entityValuesThatDoNotWork = array_merge(
-        $this->getKnownUnworkablesUpdateSingle($entityName, 'cant_update'),
-        $this->getKnownUnworkablesUpdateSingle($entityName, 'cant_return'),
-        $valuesNotToReturn
-      );
+      $this->getKnownUnworkablesUpdateSingle($entityName, 'cant_update'),
+      $this->getKnownUnworkablesUpdateSingle($entityName, 'cant_return'),
+      $valuesNotToReturn
+    );
 
-    $return = array_diff($return,$valuesNotToReturn);
+    $return = array_diff($return, $valuesNotToReturn);
     $baoObj = new CRM_Core_DAO();
     $baoObj->createTestObject($baoString, array('currency' => 'USD'), 2, 0);
 
@@ -991,7 +1064,8 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
         $fieldName = $specs['uniquename'];
       }
       if ($field == 'currency' || $field == 'id' || $field == strtolower($entityName) . '_id'
-      || in_array($field,$entityValuesThatDoNotWork)) {
+        || in_array($field, $entityValuesThatDoNotWork)
+      ) {
         //@todo id & entity_id are correct but we should fix currency & frequency_day
         continue;
       }
@@ -1001,6 +1075,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
         case CRM_Utils_Type::T_TIMESTAMP:
           $entity[$fieldName] = '2012-05-20';
           break;
+
         //case CRM_Utils_Type::T_DATETIME:
 
         case 12:
@@ -1013,7 +1088,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
         case CRM_Utils_Type::T_TEXT:
         case CRM_Utils_Type::T_LONGTEXT:
         case CRM_Utils_Type::T_EMAIL:
-          $entity[$fieldName] = substr('New String',0, CRM_Utils_Array::Value('maxlength',$specs,100));
+          $entity[$fieldName] = substr('New String', 0, CRM_Utils_Array::Value('maxlength', $specs, 100));
           break;
 
         case CRM_Utils_Type::T_INT:
@@ -1022,16 +1097,16 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
             $entity[$fieldName] = 2;
           }
           elseif (!empty($specs['FKClassName'])) {
-            if($specs['FKClassName'] == $baoString){
+            if ($specs['FKClassName'] == $baoString) {
               $entity[$fieldName] = (string) $entity2['id'];
             }
-            else{
+            else {
               $uniqueName = CRM_Utils_Array::value('uniqueName', $specs);
               if (!empty($entity[$fieldName])) {
                 $resetFKTo = array($fieldName => $entity[$fieldName]);
               }
               $entity[$fieldName] = (string) empty($entity2[$field]) ? CRM_Utils_Array::value($uniqueName, $entity2) : $entity2[$field];
-             //todo - there isn't always something set here - & our checking on unset values is limited
+              //todo - there isn't always something set here - & our checking on unset values is limited
               if (empty($entity[$field])) {
                 unset($entity[$field]);
               }
@@ -1059,9 +1134,15 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
         $options = $this->callAPISuccess($entityName, 'getoptions', array('context' => 'create', 'field' => $field));
         if (empty($options['values'])) {
           //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'));
+          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'
+              ));
             $options['values'][] = $optionValue['id'];
           }
         }
@@ -1071,7 +1152,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
         'id' => $entity['id'],
         $field => isset($entity[$field]) ? $entity[$field] : NULL,
       );
-      if(isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
+      if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
         //api has special handling on these 2 fields for backward compatibility reasons
         $entity['contribution_type_id'] = $updateParams['financial_type_id'];
       }
@@ -1088,13 +1169,19 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
       );
 
       $checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams);
-      $this->assertAPIArrayComparison($entity, $checkEntity, array(), "checking if $fieldName was correctly updated\n" . print_r(array('update-params' => $updateParams, 'update-result' => $update, 'getsingle-params' => $checkParams, 'getsingle-result' => $checkEntity, 'expected entity' => $entity), TRUE));
+      $this->assertAPIArrayComparison($entity, $checkEntity, array(), "checking if $fieldName was correctly updated\n" . print_r(array(
+            'update-params' => $updateParams,
+            'update-result' => $update,
+            'getsingle-params' => $checkParams,
+            'getsingle-result' => $checkEntity,
+            'expected entity' => $entity
+          ), TRUE));
       if ($resetFKTo) {
         //reset the foreign key fields because otherwise our cleanup routine fails & some other unexpected stuff can kick in
         $entity = array_merge($entity, $resetFKTo);
         $updateParams = array_merge($updateParams, $resetFKTo);
         $this->callAPISuccess($entityName, 'create', $updateParams);
-        if(isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
+        if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
           //api has special handling on these 2 fields for backward compatibility reasons
           $entity['contribution_type_id'] = $updateParams['financial_type_id'];
         }
@@ -1109,7 +1196,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
 
   /**
    * @dataProvider toBeSkipped_delete
-   entities that don't need a delete action
+  entities that don't need a delete action
    */
   public function testNotImplemented_delete($Entity) {
     $nonExistantID = 151416349;
@@ -1139,6 +1226,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__);
     $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']);
   }
+
   /**
    * @dataProvider entities_delete
    */
@@ -1152,6 +1240,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     }
     $result = $this->callAPIFailure($Entity, 'Delete', array('id' => 999));
   }
+
   /**
    * @dataProvider entities
    */
@@ -1192,7 +1281,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     $this->callAPISuccess($entityName, 'delete', array('id' => $baoObj2->id));
     //make sure 1 less exists now
     $result = $this->callAPISuccess($entityName, 'getcount', array(),
-      ($createcount + $startCount) -1
+      ($createcount + $startCount) - 1
     );
 
     //make sure id #1 exists
@@ -1209,16 +1298,15 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
    * Create two entities and make sure delete action only deletes one!
    *
    * @dataProvider entities_getfields
-   *
    */
   public function testGetfieldsHasTitle($entity) {
     $entities = $this->getEntitiesSupportingCustomFields();
     if (in_array($entity, $entities)) {
       $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, $entity . 'Test.php');
     }
-    $actions =  $this->callAPISuccess($entity, 'getactions', array());
+    $actions = $this->callAPISuccess($entity, 'getactions', array());
     foreach ($actions['values'] as $action) {
-      if (substr($action, -7) == '_create'  || substr($action, -4) == '_get' || substr($action, -7) == '_delete') {
+      if (substr($action, -7) == '_create' || substr($action, -4) == '_get' || substr($action, -7) == '_delete') {
         //getactions can't distinguish between contribution_page.create & contribution_page.create
         continue;
       }
@@ -1249,28 +1337,28 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     }
     return $returnEntities;
   }
+
   /**
    * @param string $entityName
    * @param int $count
    *
-   *
    * @return array
    */
   private function getMockableBAOObjects($entityName, $count = 2) {
     $baoString = _civicrm_api3_get_BAO($entityName);
     if (empty($baoString)) {
       $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO");
-      return;
+      return array();
     }
     $baos = array();
     $i = 0;
-    while($i < $count) {
-    // create entities
+    while ($i < $count) {
+      // create entities
       $baoObj = CRM_Core_DAO::createTestObject($baoString, array('currency' => 'USD'));
       $this->assertTrue(is_integer($baoObj->id), 'check first id');
       $this->deletableTestObjects[$baoString][] = $baoObj->id;
       $baos[] = $baoObj;
-      $i ++;
+      $i++;
     }
     return $baos;
   }
@@ -1332,8 +1420,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     // Verify that chaining handles decoding
     $chainResult = $this->callAPISuccess('Event', 'Get', array(
       'id' => $eventId,
-      'api.event.get' => array(
-      ),
+      'api.event.get' => array(),
     ));
     $this->assertEquals('CiviCRM <> TheRest', $chainResult['values'][$eventId]['title']);
     $this->assertEquals('TheRest <> CiviCRM', $chainResult['values'][$eventId]['description']);
@@ -1357,7 +1444,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     ));
     //$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue
     $this->assertEquals('setValueDescription: TheRest <> CiviCRM', $setValueDescriptionResult['values']['description']);
-}
+  }
 
   /**
    * Verify that write operations (create/update) use partial HTML-encoding
@@ -1378,10 +1465,10 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     $this->assertAPISuccess($createResult);
     $eventId = $createResult['id'];
     $this->assertDBQuery('createNew: CiviCRM &lt;&gt; TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
-      1 => array($eventId, 'Integer')
+      1 => array($eventId, 'Integer'),
     ));
     $this->assertDBQuery('createNew: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
-      1 => array($eventId, 'Integer')
+      1 => array($eventId, 'Integer'),
     ));
 
     // Verify that "create" handles encoding for updates
@@ -1393,10 +1480,10 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     ));
     $this->assertAPISuccess($createWithIdResult);
     $this->assertDBQuery('createWithId:  CiviCRM &lt;&gt; TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
-      1 => array($eventId, 'Integer')
+      1 => array($eventId, 'Integer'),
     ));
     $this->assertDBQuery('createWithId:  TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
-      1 => array($eventId, 'Integer')
+      1 => array($eventId, 'Integer'),
     ));
 
     // Verify that "setvalue" handles encoding for updates
@@ -1408,7 +1495,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     ));
     $this->assertAPISuccess($setValueTitleResult);
     $this->assertDBQuery('setValueTitle: CiviCRM &lt;&gt; TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
-      1 => array($eventId, 'Integer')
+      1 => array($eventId, 'Integer'),
     ));
     $setValueDescriptionResult = civicrm_api('Event', 'setvalue', array(
       'version' => 3,
@@ -1419,7 +1506,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
     //$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue
     $this->assertAPISuccess($setValueDescriptionResult);
     $this->assertDBQuery('setValueDescription: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
-      1 => array($eventId, 'Integer')
+      1 => array($eventId, 'Integer'),
     ));
   }
 }