From 24602943f485447e772afbefbce6d1982ed998a7 Mon Sep 17 00:00:00 2001 From: eileenmcnaughton Date: Mon, 25 Jan 2016 02:20:00 +0000 Subject: [PATCH] CRM-17350 preliminary test clean up for entity-tag acl permission fix --- CRM/Core/BAO/EntityTag.php | 2 +- tests/phpunit/api/v3/ACLPermissionTest.php | 25 ++-- tests/phpunit/api/v3/EntityTagTest.php | 149 +++++++++------------ 3 files changed, 77 insertions(+), 99 deletions(-) diff --git a/CRM/Core/BAO/EntityTag.php b/CRM/Core/BAO/EntityTag.php index 7323357e84..0324c401b7 100644 --- a/CRM/Core/BAO/EntityTag.php +++ b/CRM/Core/BAO/EntityTag.php @@ -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(); diff --git a/tests/phpunit/api/v3/ACLPermissionTest.php b/tests/phpunit/api/v3/ACLPermissionTest.php index 70ac8d354a..42a32aa7e4 100644 --- a/tests/phpunit/api/v3/ACLPermissionTest.php +++ b/tests/phpunit/api/v3/ACLPermissionTest.php @@ -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) "; diff --git a/tests/phpunit/api/v3/EntityTagTest.php b/tests/phpunit/api/v3/EntityTagTest.php index b8396cb74b..b2dec522c9 100644 --- a/tests/phpunit/api/v3/EntityTagTest.php +++ b/tests/phpunit/api/v3/EntityTagTest.php @@ -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, -- 2.25.1