From 1154af949272ed641ddcb34ea631258b30daddff 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/PrintLabel.php | 9 ++++++++ api/v3/RecurringEntity.php | 1 + api/v3/WordReplacement.php | 10 ++++---- .../phpunit/api/v3/SyntaxConformanceTest.php | 23 ++++--------------- 6 files changed, 25 insertions(+), 31 deletions(-) diff --git a/api/v3/LocBlock.php b/api/v3/LocBlock.php index 9c293fc6da..1d2925dca6 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 e362dfa5fd..c7ee4a2f9f 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/PrintLabel.php b/api/v3/PrintLabel.php index 0e16a3b52a..3e0284e26a 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 9ee0b572c0..1358d9fcc8 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/WordReplacement.php b/api/v3/WordReplacement.php index 8ac602784a..8f5535f9b6 100644 --- a/api/v3/WordReplacement.php +++ b/api/v3/WordReplacement.php @@ -43,11 +43,7 @@ * @throws \API_Exception */ function civicrm_api3_word_replacement_get($params) { - $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); } @@ -71,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 0e70db6c34..a985c7c417 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -1030,26 +1030,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 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"); - 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