CRM-18563 Some fixes for the fails in new test.
authoreileen <emcnaughton@wikimedia.org>
Wed, 27 Jul 2016 21:45:20 +0000 (09:45 +1200)
committerSeamus Lee <seamuslee001@gmail.com>
Thu, 4 Aug 2016 07:21:22 +0000 (17:21 +1000)
api/v3/LocBlock.php
api/v3/MailingComponent.php
api/v3/Mapping.php
api/v3/Navigation.php
api/v3/PrintLabel.php
api/v3/RecurringEntity.php
api/v3/SavedSearch.php
api/v3/WordReplacement.php
tests/phpunit/api/v3/SyntaxConformanceTest.php

index f547fd5a9be21942aa0deb1fc392ef67c11dd6a6..610ee7ab4767a1e1869de3dbeccb9a2af03001e0 100644 (file)
  *
  * @return array
  *   API result array.
+ *
+ * @throws \API_Exception
  */
 function civicrm_api3_loc_block_create($params) {
   $entities = array();
+  civicrm_api3_verify_one_mandatory($params, NULL, array('address', 'phone', 'im', 'email'));
   // Call the appropriate api to create entities if any are passed in the params
   // This is basically chaining but in reverse - we create the sub-entities first
   // This exists because chainging does not work in reverse, or with keys like 'email_2'
@@ -58,12 +61,8 @@ function civicrm_api3_loc_block_create($params) {
         }
         // Bother calling the api
         else {
-          $info['version'] = $params['version'];
           $info['contact_id'] = CRM_Utils_Array::value('contact_id', $info, 'null');
-          $result = civicrm_api($item, 'create', $info);
-          if (!empty($result['is_error'])) {
-            return $result;
-          }
+          $result = civicrm_api3($item, 'create', $info);
           $entities[$key] = $result['values'][$result['id']];
           $params[$key . '_id'] = $result['id'];
         }
@@ -78,7 +77,7 @@ function civicrm_api3_loc_block_create($params) {
     _civicrm_api3_object_to_array($dao, $values[$dao->id]);
     return civicrm_api3_create_success($values, $params, 'LocBlock', 'create', $dao);
   }
-  return civicrm_api3_create_error('Unable to create LocBlock. Please check your params.');
+  throw New API_Exception('Unable to create LocBlock. Please check your params.');
 }
 
 /**
index 391f85aa3644d0df194533b87f2ff5c9261f8ebc..57cd9f40b1581922f2cb6ed394b5f41ca71490e3 100644 (file)
@@ -55,6 +55,8 @@ function civicrm_api3_mailing_component_create($params) {
  */
 function _civicrm_api3_mailing_component_create_spec(&$spec) {
   $spec['is_active']['api.default'] = 1;
+  $spec['name']['api.required'] = 1;
+  $spec['component_type']['api.required'] = 1;
 }
 
 /**
index b66e2fac147ea637a0ca54f4ea7233e9ff9845ce..c4dabd0d70c098e9479c9a24c4fb8afbe2f5dd4d 100644 (file)
@@ -43,6 +43,18 @@ function civicrm_api3_mapping_create($params) {
   return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
+/**
+ * Adjust Metadata for Create action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
+ *
+ * @param array $spec
+ *   Array of parameters determined by getfields.
+ */
+function _civicrm_api3_mapping_create_spec(&$spec) {
+  $spec['name']['api.required'] = 1;
+}
+
 /**
  * Deletes an existing Mapping.
  *
index 1a3cfea15c8d282f88d2ad1429833cb5c796565f..b7d0d058177d4b6426a1d8a8d09f716f57ff9020 100644 (file)
@@ -93,6 +93,7 @@ function civicrm_api3_navigation_get($params) {
  * @param array $params
  */
 function _civicrm_api3_navigation_create_spec(&$params) {
+  $params['name']['api.required'] = 1;
 }
 
 /**
index 27c80817a366df6f404bb2cf811cf13cd24313c5..3704b917cee0efb5f5b6998fbf26fc1add0bb591 100644 (file)
@@ -42,6 +42,15 @@ function civicrm_api3_print_label_create($params) {
   return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
+/**
+ * Adjust metadata for navigation create action.
+ *
+ * @param array $params
+ */
+function _civicrm_api3_print_label_create_spec(&$params) {
+  $params['name']['api.required'] = 1;
+}
+
 /**
  * Get a PrintLabel.
  *
index eba9879c6bf477f41932245c0136c37c0a745ad4..cbbe23af773c3cab6730c412515f9f0e13ea260b 100644 (file)
@@ -82,6 +82,7 @@ function _civicrm_api3_recurring_entity_create_spec(&$params) {
     'civicrm_event' => 'civicrm_event',
     'civicrm_activity' => 'civicrm_activity',
   );
+  $params['entity_table']['api.required'] = 1;
 }
 
 /**
index 1702ad8f9f7b9eccbe83c68cbc031d9375bf8399..e32c258e35282961af64d811031e582956f5c0e4 100644 (file)
@@ -43,6 +43,7 @@
  * @access public
  */
 function civicrm_api3_saved_search_create($params) {
+  civicrm_api3_verify_one_mandatory($params, NULL, array('form_values', 'where_clause'));
   // The create function of the dao expects a 'formValues' that is
   // not serialized. The get function returns form_values, that is
   // serialized.
index 1aea732629789aa556edc3ef84124b00639b25fa..a394284744f2bf95deb642b15df458bd5214fd87 100644 (file)
  * @throws \API_Exception
  */
 function civicrm_api3_word_replacement_get($params) {
-  // NEVER COPY THIS. No idea why a newish api would not use basic_get.
-  $bao = new CRM_Core_BAO_WordReplacement();
-  _civicrm_api3_dao_set_filter($bao, $params, TRUE);
-  $wordReplacements = _civicrm_api3_dao_to_array($bao, $params, TRUE, 'WordReplacement');
-
-  return civicrm_api3_create_success($wordReplacements, $params, 'WordReplacement', 'get', $bao);
+  return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
 
@@ -72,7 +67,9 @@ function civicrm_api3_word_replacement_create($params) {
  *   Array of parameters determined by getfields.
  */
 function _civicrm_api3_word_replacement_create_spec(&$params) {
-  unset($params['version']);
+  $params['find_word']['api.required'] = 1;
+  $params['replace_word']['api.required'] = 1;
+  $params['is_active']['api.default'] = 1;
 }
 
 /**
index c58e8f9e7d73600918cb5d65adfd259be858914c..78cfdfe20f3fed33a652ecd9987ed5bbbc79f306 100644 (file)
@@ -1078,26 +1078,11 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
    * @param $Entity
    */
   public function testWithoutParam_create($Entity) {
-    // should create php complaining that a param is missing
-    $result = civicrm_api3($Entity, 'Create');
-  }
-
-  /**
-   * @dataProvider entities_create
-   * @param $Entity
-   * @throws \PHPUnit_Framework_IncompleteTestError
-   */
-  public function testEmptyParam_create($Entity) {
-    $this->markTestIncomplete("fixing this test to test the api functions fails on numerous 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");
-      return;
+    if ($Entity === 'Setting') {
+      $this->markTestSkipped('It seems OK for setting to skip here as it silently sips invalid params');
     }
-    $result = $this->callAPIFailure($Entity, 'Create', array());
-    $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']);
+    // should create php complaining that a param is missing
+    civicrm_api3($Entity, 'Create');
   }
 
   /**