CRM-13254 (Closes) make entity_tag.get api use basic create rather than error if...
authoreileen <eileen@fuzion.co.nz>
Tue, 20 Aug 2013 22:21:40 +0000 (10:21 +1200)
committereileen <eileen@fuzion.co.nz>
Tue, 20 Aug 2013 22:21:40 +0000 (10:21 +1200)
api/v3/EntityTag.php
api/v3/examples/EntityTagDelete.php
api/v3/examples/EntityTagGet.php
tests/phpunit/api/v3/EntityTagTest.php

index a5a9525660b0ba3f385bc4a616c62c69d97170f3..b01b49e50857e37ba8b19ce35f7dc4c49fb08b77 100644 (file)
  */
 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';
 }
index 5abd8fea0dd87d2952e3351f4aad88287c93e145..a52bd3521bb5bd44b3d58430e34aeaea114ff630 100644 (file)
@@ -5,7 +5,7 @@
  */
 function entity_tag_delete_example(){
 $params = array(
-  'contact_id_h' => 46,
+  'contact_id_h' => 37,
   'tag_id' => '1',
 );
 
index 59841bee8d9d0902c4d88f02819e9f7fad735ba1..9fa94d810356bab9355eb03ed7bd9c5ca5758af4 100644 (file)
@@ -5,7 +5,7 @@
  */
 function entity_tag_get_example(){
 $params = array(
-  'contact_id' => 24,
+  'contact_id' => 21,
   'tag_id' => '1',
 );
 
index 81c5f1f64e881e40572e9bdd83df14032a0a41dc..9224786fddab7cece7df7a5fcececda7fd2d9c7d 100644 (file)
@@ -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,