From 1644b9089e1bcf14eca86277ff5c33f3ad5a7f35 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 19 Feb 2015 10:48:43 -0500 Subject: [PATCH] CRM-15988 - Fix inconsistent handling of api entity names --- api/api.php | 6 ++---- api/v3/utils.php | 6 ++++-- tests/phpunit/api/v3/ContactTest.php | 4 ++-- tests/phpunit/api/v3/EventTest.php | 2 +- tests/phpunit/api/v3/UtilsTest.php | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/api.php b/api/api.php index 1ba09c7b3b..fa1d345e8b 100644 --- a/api/api.php +++ b/api/api.php @@ -77,7 +77,7 @@ function _civicrm_api3_api_getfields(&$apiRequest) { } $getFieldsParams = array('action' => $apiRequest['action']); $entity = $apiRequest['entity']; - if ($entity == 'profile' && array_key_exists('profile_id', $apiRequest['params'])) { + if ($entity == 'Profile' && array_key_exists('profile_id', $apiRequest['params'])) { $getFieldsParams['profile_id'] = $apiRequest['params']['profile_id']; } $fields = civicrm_api3($entity, 'getfields', $getFieldsParams); @@ -171,11 +171,9 @@ function _civicrm_api_replace_variables(&$params, &$parentResult, $separator = ' * * @return string * Entity name in underscore separated format. - * - * @fixme Why isn't this called first thing in civicrm_api wrapper? */ function _civicrm_api_get_entity_name_from_camel($entity) { - if ($entity == strtolower($entity)) { + if (!$entity || $entity === strtolower($entity)) { return $entity; } else { diff --git a/api/v3/utils.php b/api/v3/utils.php index 988016a1f3..b41db295d8 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -266,7 +266,7 @@ function civicrm_api3_create_success($values = 1, $params = array(), $entity = N } if ($deprecated) { // Metadata-level deprecations or wholesale entity deprecations. - if ($entity == 'entity' || $action == 'getactions' || is_string($deprecated)) { + if ($entity == 'Entity' || $action == 'getactions' || is_string($deprecated)) { $result['deprecated'] = $deprecated; } // Action-specific deprecations @@ -310,7 +310,7 @@ function _civicrm_api3_get_DAO($name) { $name = substr($name, 13, $last - 13); } - $name = _civicrm_api_get_camel_name($name, 3); + $name = _civicrm_api_get_camel_name($name); if ($name == 'Individual' || $name == 'Household' || $name == 'Organization') { $name = 'Contact'; @@ -746,6 +746,8 @@ function _civicrm_api3_apply_filters_to_dao($filterField, $filterValue, &$dao) { * options extracted from params */ function _civicrm_api3_get_options_from_params(&$params, $queryObject = FALSE, $entity = '', $action = '') { + // Entity should be l-case so it can be concatenated into field names + $entity = _civicrm_api_get_entity_name_from_camel($entity); $is_count = FALSE; $sort = CRM_Utils_Array::value('sort', $params, 0); $sort = CRM_Utils_Array::value('option.sort', $params, $sort); diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index f9d97e9394..a8a7f03eb9 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -1746,7 +1746,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $config = CRM_Core_Config::singleton(); $config->userPermissionClass->permissions = array('access CiviCRM'); $result = $this->callAPIFailure('contact', 'create', $params); - $this->assertEquals('API permission check failed for contact/create call; insufficient permission: require access CiviCRM and add contacts', $result['error_message'], 'lacking permissions should not be enough to create a contact'); + $this->assertEquals('API permission check failed for Contact/create call; insufficient permission: require access CiviCRM and add contacts', $result['error_message'], 'lacking permissions should not be enough to create a contact'); $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'import contacts'); $this->callAPISuccess('contact', 'create', $params, NULL, 'overfluous permissions should be enough to create a contact'); @@ -1773,7 +1773,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $config->userPermissionClass->permissions = array('access CiviCRM'); $result = $this->callAPIFailure('contact', 'update', $params); - $this->assertEquals('API permission check failed for contact/update call; insufficient permission: require access CiviCRM and edit all contacts', $result['error_message'], 'lacking permissions should not be enough to update a contact'); + $this->assertEquals('API permission check failed for Contact/update call; insufficient permission: require access CiviCRM and edit all contacts', $result['error_message'], 'lacking permissions should not be enough to update a contact'); $config->userPermissionClass->permissions = array( 'access CiviCRM', diff --git a/tests/phpunit/api/v3/EventTest.php b/tests/phpunit/api/v3/EventTest.php index 05094f7a6e..a6f6d210cf 100644 --- a/tests/phpunit/api/v3/EventTest.php +++ b/tests/phpunit/api/v3/EventTest.php @@ -518,7 +518,7 @@ class api_v3_EventTest extends CiviUnitTestCase { $config = &CRM_Core_Config::singleton(); $config->userPermissionClass->permissions = array('access CiviCRM'); $result = $this->callAPIFailure('event', 'create', $params); - $this->assertEquals('API permission check failed for event/create call; insufficient permission: require access CiviCRM and access CiviEvent and edit all events', $result['error_message'], 'lacking permissions should not be enough to create an event'); + $this->assertEquals('API permission check failed for Event/create call; insufficient permission: require access CiviCRM and access CiviEvent and edit all events', $result['error_message'], 'lacking permissions should not be enough to create an event'); $config->userPermissionClass->permissions = array( 'access CiviEvent', diff --git a/tests/phpunit/api/v3/UtilsTest.php b/tests/phpunit/api/v3/UtilsTest.php index 46d2caf419..c2ffbbb88c 100644 --- a/tests/phpunit/api/v3/UtilsTest.php +++ b/tests/phpunit/api/v3/UtilsTest.php @@ -83,7 +83,7 @@ class api_v3_UtilsTest extends CiviUnitTestCase { catch (Exception $e) { $message = $e->getMessage(); } - $this->assertEquals($message, 'API permission check failed for contact/create call; insufficient permission: require access CiviCRM and add contacts', 'lacking permissions should throw an exception'); + $this->assertEquals($message, 'API permission check failed for Contact/create call; insufficient permission: require access CiviCRM and add contacts', 'lacking permissions should throw an exception'); $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'import contacts'); $this->assertTrue($this->runPermissionCheck('contact', 'create', $check), 'overfluous permissions should return true'); -- 2.25.1