From 283c85e9358e91065eb66a6801f7d513c689f173 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 21 Aug 2013 10:21:40 +1200 Subject: [PATCH] CRM-13254 (Closes) make entity_tag.get api use basic create rather than error if no entity_id passed in --- api/v3/EntityTag.php | 18 ++++++++------ api/v3/examples/EntityTagDelete.php | 2 +- api/v3/examples/EntityTagGet.php | 2 +- tests/phpunit/api/v3/EntityTagTest.php | 34 +++++++++----------------- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/api/v3/EntityTag.php b/api/v3/EntityTag.php index a5a9525660..b01b49e508 100644 --- a/api/v3/EntityTag.php +++ b/api/v3/EntityTag.php @@ -50,13 +50,18 @@ */ function civicrm_api3_entity_tag_get($params) { - - $values = CRM_Core_BAO_EntityTag::getTag($params['entity_id'], $params['entity_table']); - $result = array(); - foreach ($values as $v) { - $result[$v] = array('tag_id' => $v); + if(empty($params['entity_id'])) { + return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + } + else{ + //do legacy non-standard behaviour + $values = CRM_Core_BAO_EntityTag::getTag($params['entity_id'], $params['entity_table']); + $result = array(); + foreach ($values as $v) { + $result[$v] = array('tag_id' => $v); + } + return civicrm_api3_create_success($result, $params); } - return civicrm_api3_create_success($result, $params); } /** @@ -66,7 +71,6 @@ function civicrm_api3_entity_tag_get($params) { * @param array $params array or parameters determined by getfields */ function _civicrm_api3_entity_tag_get_spec(&$params) { - $params['entity_id']['api.required'] = 1; $params['entity_id']['api.aliases'] = array('contact_id'); $params['entity_table']['api.default'] = 'civicrm_contact'; } diff --git a/api/v3/examples/EntityTagDelete.php b/api/v3/examples/EntityTagDelete.php index 5abd8fea0d..a52bd3521b 100644 --- a/api/v3/examples/EntityTagDelete.php +++ b/api/v3/examples/EntityTagDelete.php @@ -5,7 +5,7 @@ */ function entity_tag_delete_example(){ $params = array( - 'contact_id_h' => 46, + 'contact_id_h' => 37, 'tag_id' => '1', ); diff --git a/api/v3/examples/EntityTagGet.php b/api/v3/examples/EntityTagGet.php index 59841bee8d..9fa94d8103 100644 --- a/api/v3/examples/EntityTagGet.php +++ b/api/v3/examples/EntityTagGet.php @@ -5,7 +5,7 @@ */ function entity_tag_get_example(){ $params = array( - 'contact_id' => 24, + 'contact_id' => 21, 'tag_id' => '1', ); diff --git a/tests/phpunit/api/v3/EntityTagTest.php b/tests/phpunit/api/v3/EntityTagTest.php index 81c5f1f64e..9224786fdd 100644 --- a/tests/phpunit/api/v3/EntityTagTest.php +++ b/tests/phpunit/api/v3/EntityTagTest.php @@ -44,6 +44,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { protected $_tagID; protected $_apiversion = 3; protected $_tag; + protected $_entity = 'entity_tag'; public $_eNoticeCompliant = TRUE; function setUp() { @@ -118,7 +119,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { } ///////////////// civicrm_entity_tag_get methods - function testGetWrongParamsType() { + function testGetNoEntityID() { $ContactId = $this->_individualID; $tagID = $this->_tagID; $params = array( @@ -128,13 +129,8 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params); $this->assertEquals($individualEntity['added'], 1); - } - - function testIndividualEntityTagGetWithoutContactID() { - $paramsEntity = array(); - $entity = $this->callAPIFailure('entity_tag', 'get', $paramsEntity, - 'Mandatory key(s) missing from params array: entity_id' - ); + $result = $this->callAPISuccess($this->_entity, 'get', array('sequential' => 1, 'tag_id' => $tagID)); + $this->assertEquals($ContactId, $result['values'][0]['entity_id']); } function testIndividualEntityTagGet() { @@ -154,10 +150,6 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity); } - function testHouseholdEntityGetWithoutContactID() { - $entity = $this->callAPIFailure('entity_tag', 'get', array()); - } - function testHouseholdEntityGet() { $ContactId = $this->_householdID; $tagID = $this->_tagID; @@ -170,10 +162,6 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { $this->assertEquals($householdEntity['added'], 1); } - function testOrganizationEntityGetWithoutContactID() { - $entity = $this->callAPIFailure('entity_tag', 'get', array()); - } - function testOrganizationEntityGet() { $ContactId = $this->_organizationID; $tagID = $this->_tagID; @@ -189,8 +177,8 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity); } - ///////////////// civicrm_entity_tag_remove methods - function testEntityTagRemoveNoTagId() { + ///////////////// civicrm_entity_tag_Delete methods + function testEntityTagDeleteNoTagId() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, @@ -208,7 +196,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { ); } - function testEntityTagRemoveINDHH() { + function testEntityTagDeleteINDHH() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, @@ -244,7 +232,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { $this->assertEquals($result['removed'], 1); } - function testEntityTagRemoveHHORG() { + function testEntityTagDeleteHHORG() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, @@ -276,7 +264,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { } - function testEntityTagCommonRemoveINDHH() { + function testEntityTagCommonDeleteINDHH() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, @@ -294,7 +282,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { $this->assertEquals($result['removed'], 2); } - function testEntityTagCommonRemoveHH() { + function testEntityTagCommonDeleteHH() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, @@ -311,7 +299,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { $this->assertEquals($result['removed'], 1); } - function testEntityTagCommonRemoveHHORG() { + function testEntityTagCommonDeleteHHORG() { $entityTagParams = array( 'contact_id_i' => $this->_individualID, 'contact_id_h' => $this->_householdID, -- 2.25.1