From df197a567b3748a08af8d6109d3d57d22d87f3c6 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 28 Jul 2016 09:45:20 +1200 Subject: [PATCH] CRM-18563 Some fixes for the fails in new test. --- api/v3/LocBlock.php | 11 ++++----- api/v3/MailingComponent.php | 2 ++ api/v3/Mapping.php | 12 ++++++++++ api/v3/Navigation.php | 1 + api/v3/PrintLabel.php | 9 ++++++++ api/v3/RecurringEntity.php | 1 + api/v3/SavedSearch.php | 1 + api/v3/WordReplacement.php | 11 ++++----- .../phpunit/api/v3/SyntaxConformanceTest.php | 23 ++++--------------- 9 files changed, 39 insertions(+), 32 deletions(-) diff --git a/api/v3/LocBlock.php b/api/v3/LocBlock.php index f547fd5a9b..610ee7ab47 100644 --- a/api/v3/LocBlock.php +++ b/api/v3/LocBlock.php @@ -40,9 +40,12 @@ * * @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.'); } /** diff --git a/api/v3/MailingComponent.php b/api/v3/MailingComponent.php index 391f85aa36..57cd9f40b1 100644 --- a/api/v3/MailingComponent.php +++ b/api/v3/MailingComponent.php @@ -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; } /** diff --git a/api/v3/Mapping.php b/api/v3/Mapping.php index b66e2fac14..c4dabd0d70 100644 --- a/api/v3/Mapping.php +++ b/api/v3/Mapping.php @@ -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. * diff --git a/api/v3/Navigation.php b/api/v3/Navigation.php index 1a3cfea15c..b7d0d05817 100644 --- a/api/v3/Navigation.php +++ b/api/v3/Navigation.php @@ -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; } /** diff --git a/api/v3/PrintLabel.php b/api/v3/PrintLabel.php index 27c80817a3..3704b917ce 100644 --- a/api/v3/PrintLabel.php +++ b/api/v3/PrintLabel.php @@ -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. * diff --git a/api/v3/RecurringEntity.php b/api/v3/RecurringEntity.php index eba9879c6b..cbbe23af77 100644 --- a/api/v3/RecurringEntity.php +++ b/api/v3/RecurringEntity.php @@ -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; } /** diff --git a/api/v3/SavedSearch.php b/api/v3/SavedSearch.php index 1702ad8f9f..e32c258e35 100644 --- a/api/v3/SavedSearch.php +++ b/api/v3/SavedSearch.php @@ -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. diff --git a/api/v3/WordReplacement.php b/api/v3/WordReplacement.php index 1aea732629..a394284744 100644 --- a/api/v3/WordReplacement.php +++ b/api/v3/WordReplacement.php @@ -43,12 +43,7 @@ * @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; } /** diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index c58e8f9e7d..78cfdfe20f 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -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'); } /** -- 2.25.1