CRM-17350 preliminary test clean up for entity-tag acl permission fix
authoreileenmcnaughton <eileen@fuzion.co.nz>
Mon, 25 Jan 2016 02:20:00 +0000 (02:20 +0000)
committereileenmcnaughton <eileen@fuzion.co.nz>
Mon, 25 Jan 2016 02:20:00 +0000 (02:20 +0000)
CRM/Core/BAO/EntityTag.php
tests/phpunit/api/v3/ACLPermissionTest.php
tests/phpunit/api/v3/EntityTagTest.php

index 7323357e84e30ef87cb6c32308547a03d322fd75..0324c401b724b157245290846148bc77caed21a9 100644 (file)
@@ -44,7 +44,7 @@ class CRM_Core_BAO_EntityTag extends CRM_Core_DAO_EntityTag {
    * @return array
    *   reference $tag array of category id's the contact belongs to.
    */
-  public static function &getTag($entityID, $entityTable = 'civicrm_contact') {
+  public static function getTag($entityID, $entityTable = 'civicrm_contact') {
     $tags = array();
 
     $entityTag = new CRM_Core_BAO_EntityTag();
index 70ac8d354a039c6a3a22bd43dd6c4f4f7b45861c..42a32aa7e408de2f2c570c463a81b33bb97ddeb5 100644 (file)
@@ -359,7 +359,6 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
     $this->assertEquals(0, $result['count']);
   }
 
-
   /**
    * @dataProvider entities
    * Function tests that an empty where hook returns no results
@@ -401,24 +400,28 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
 
   /**
    * No results returned.
+   *
    * @implements CRM_Utils_Hook::aclWhereClause
-   * @param $type
-   * @param $tables
-   * @param $whereTables
-   * @param $contactID
-   * @param $where
+   *
+   * @param string $type
+   * @param array $tables
+   * @param array $whereTables
+   * @param int $contactID
+   * @param string $where
    */
   public function aclWhereHookNoResults($type, &$tables, &$whereTables, &$contactID, &$where) {
   }
 
   /**
    * All results returned.
+   *
    * @implements CRM_Utils_Hook::aclWhereClause
-   * @param $type
-   * @param $tables
-   * @param $whereTables
-   * @param $contactID
-   * @param $where
+   *
+   * @param string $type
+   * @param array $tables
+   * @param array $whereTables
+   * @param int $contactID
+   * @param string $where
    */
   public function aclWhereHookAllResults($type, &$tables, &$whereTables, &$contactID, &$where) {
     $where = " (1) ";
index b8396cb74b84a43d60597eccf6fb14ec2655f8c1..b2dec522c99c64d55cbf87056a5796553d24c566 100644 (file)
@@ -25,9 +25,6 @@
  +--------------------------------------------------------------------+
  */
 
-require_once 'CiviTest/CiviUnitTestCase.php';
-
-
 /**
  *  Test APIv3 civicrm_entity_tag_* functions
  *
@@ -38,10 +35,13 @@ require_once 'CiviTest/CiviUnitTestCase.php';
 require_once 'CiviTest/CiviUnitTestCase.php';
 
 /**
- * Class api_v3_EntityTagTest
+ * Class api_v3_EntityTagTest.
  */
 class api_v3_EntityTagTest extends CiviUnitTestCase {
 
+  /**
+   * @var int
+   */
   protected $_individualID;
   protected $_householdID;
   protected $_organizationID;
@@ -50,7 +50,16 @@ class api_v3_EntityTagTest extends CiviUnitTestCase {
   protected $_tag;
   protected $_entity = 'entity_tag';
 
+  /**
+   * Basic parameters for create.
+   *
+   * @var array
+   */
+  protected $_params = array();
 
+  /**
+   * Set up for test.
+   */
   public function setUp() {
     parent::setUp();
     $this->useTransaction(TRUE);
@@ -60,58 +69,48 @@ class api_v3_EntityTagTest extends CiviUnitTestCase {
     $this->_tagID = $this->_tag['id'];
     $this->_householdID = $this->houseHoldCreate();
     $this->_organizationID = $this->organizationCreate();
-  }
-
-  public function testAddEmptyParams() {
-    $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params = array(),
-      'contact_id is a required field'
+    $this->_params = array(
+      'contact_id' => $this->_individualID,
+      'tag_id' => $this->_tagID,
     );
   }
 
-  public function testAddWithoutTagID() {
-    $params = array(
-      'contact_id' => $this->_individualID,
-    );
-    $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
+  /**
+   * Test required parameters.
+   *
+   * These failure tests are low value and may not be worth putting in v4.
+   */
+  public function testFailureTests() {
+    $this->callAPIFailure('entity_tag', 'create', array('contact_id' => $this->_individualID),
       'tag_id is a required field'
     );
-  }
-
-  public function testAddWithoutContactID() {
-    $params = array(
-      'tag_id' => $this->_tagID,
+    $this->callAPIFailure('entity_tag', 'create', array('tag_id' => $this->_tagID),
+      'contact_id is a required field'
     );
-    $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params,
-      'contact_id is a required field');
   }
 
+  /**
+   * Test basic create.
+   */
   public function testContactEntityTagCreate() {
-    $params = array(
-      'contact_id' => $this->_individualID,
-      'tag_id' => $this->_tagID,
-    );
-
-    $result = $this->callAPISuccess('entity_tag', 'create', $params, __FUNCTION__, __FILE__);
+    $result = $this->callAPISuccess('entity_tag', 'create', $this->_params);
     $this->assertEquals($result['added'], 1);
   }
 
+  /**
+   * Test multiple add functionality.
+   *
+   * This needs review for api v4 as it makes for a very non standard api.
+   */
   public function testAddDouble() {
-    $individualId = $this->_individualID;
-    $organizationId = $this->_organizationID;
-    $tagID = $this->_tagID;
-    $params = array(
-      'contact_id' => $individualId,
-      'tag_id' => $tagID,
-    );
-
-    $result = $this->callAPISuccess('entity_tag', 'create', $params);
 
+    $result = $this->callAPISuccess('entity_tag', 'create', $this->_params);
     $this->assertEquals($result['added'], 1);
 
     $params = array(
-      'contact_id_i' => $individualId,
-      'contact_id_o' => $organizationId,
-      'tag_id' => $tagID,
+      'contact_id_i' => $this->_individualID,
+      'contact_id_o' => $this->_organizationID,
+      'tag_id' => $this->_tagID,
     );
 
     $result = $this->callAPISuccess('entity_tag', 'create', $params);
@@ -120,68 +119,58 @@ class api_v3_EntityTagTest extends CiviUnitTestCase {
   }
 
   /**
-   * civicrm_entity_tag_get methods.
+   * Test that get works without an entity.
    */
   public function testGetNoEntityID() {
-    $ContactId = $this->_individualID;
-    $tagID = $this->_tagID;
-    $params = array(
-      'contact_id' => $ContactId,
-      'tag_id' => $tagID,
-    );
-
-    $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
-    $this->assertEquals($individualEntity['added'], 1);
-    $result = $this->callAPISuccess($this->_entity, 'get', array('sequential' => 1, 'tag_id' => $tagID));
-    $this->assertEquals($ContactId, $result['values'][0]['entity_id']);
+    $this->callAPISuccess('entity_tag', 'create', $this->_params);
+    $result = $this->callAPISuccess($this->_entity, 'get', array('sequential' => 1, 'tag_id' => $this->_tagID));
+    $this->assertEquals($this->_individualID, $result['values'][0]['entity_id']);
   }
 
+  /**
+   * Basic get functionality test.
+   */
   public function testIndividualEntityTagGet() {
-    $contactId = $this->_individualID;
-    $tagID = $this->_tagID;
-    $params = array(
-      'contact_id' => $contactId,
-      'tag_id' => $tagID,
-    );
-
-    $individualEntity = $this->callAPIAndDocument('entity_tag', 'create', $params, __FUNCTION__, __FILE__);
+    $individualEntity = $this->callAPISuccess('entity_tag', 'create', $this->_params);
     $this->assertEquals($individualEntity['added'], 1);
 
     $paramsEntity = array(
-      'contact_id' => $contactId,
+      'contact_id' => $this->_individualID,
     );
-    $entity = $this->callAPIAndDocument('entity_tag', 'get', $paramsEntity, __FUNCTION__, __FILE__);
+    $this->callAPIAndDocument('entity_tag', 'get', $paramsEntity, __FUNCTION__, __FILE__);
   }
 
-  public function testHouseholdEntityGet() {
-    $ContactId = $this->_householdID;
-    $tagID = $this->_tagID;
+  /**
+   * Test tag can be added to a household.
+   */
+  public function testHouseholdEntityCreate() {
     $params = array(
-      'contact_id' => $ContactId,
-      'tag_id' => $tagID,
+      'contact_id' => $this->_householdID,
+      'tag_id' => $this->_tagID,
     );
 
     $householdEntity = $this->callAPISuccess('entity_tag', 'create', $params);
     $this->assertEquals($householdEntity['added'], 1);
   }
 
+  /**
+   * Test tag can be added to an organization.
+   */
   public function testOrganizationEntityGet() {
-    $ContactId = $this->_organizationID;
-    $tagID = $this->_tagID;
+
     $params = array(
-      'contact_id' => $ContactId,
-      'tag_id' => $tagID,
+      'contact_id' => $this->_organizationID,
+      'tag_id' => $this->_tagID,
     );
 
     $organizationEntity = $this->callAPISuccess('entity_tag', 'create', $params);
     $this->assertEquals($organizationEntity['added'], 1);
 
-    $paramsEntity = array('contact_id' => $ContactId);
-    $entity = $this->callAPISuccess('entity_tag', 'get', $paramsEntity);
+    $this->callAPISuccess('entity_tag', 'getsingle', array('contact_id' => $this->_organizationID));
   }
 
   /**
-   * civicrm_entity_tag_Delete methods.
+   * Civicrm_entity_tag_Delete methods.
    */
   public function testEntityTagDeleteNoTagId() {
     $entityTagParams = array(
@@ -258,20 +247,6 @@ class api_v3_EntityTagTest extends CiviUnitTestCase {
     $this->assertEquals($result['not_removed'], 1);
   }
 
-  /**
-   * civicrm_tag_entities_get methods.
-   */
-  public function testCommonContactEntityTagAdd() {
-    $params = array(
-      'contact_id' => $this->_individualID,
-      'tag_id' => $this->_tagID,
-    );
-
-    $individualEntity = $this->callAPISuccess('entity_tag', 'create', $params);
-    $this->assertEquals($individualEntity['added'], 1);
-  }
-
-
   public function testEntityTagCommonDeleteINDHH() {
     $entityTagParams = array(
       'contact_id_i' => $this->_individualID,