Skip to content
Snippets Groups Projects
Unverified Commit 6148ab3a authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #18496 from eileenmcnaughton/nfc

#2039 [NFC] Minor cleanup in tests 
parents 34ea74cf 82fd72da
No related branches found
No related tags found
No related merge requests found
......@@ -30,9 +30,8 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
public function setUp() {
parent::setUp();
$baoObj = new CRM_Core_DAO();
$baoObj->createTestObject('CRM_Pledge_BAO_Pledge', [], 1, 0);
$baoObj->createTestObject('CRM_Core_BAO_Phone', [], 1, 0);
CRM_Core_DAO::createTestObject('CRM_Pledge_BAO_Pledge', [], 1, 0);
CRM_Core_DAO::createTestObject('CRM_Core_BAO_Phone', [], 1, 0);
$this->prepareForACLs();
}
......@@ -65,8 +64,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Function tests that an empty where hook returns no results.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testContactGetNoResultsHook($version) {
$this->_apiversion = $version;
......@@ -85,8 +87,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
* Function tests that an empty where hook returns exactly 1 result with "view my contact".
*
* CRM-16512 caused contacts with Edit my contact to be able to view all records.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testContactGetOneResultHookWithViewMyContact($version) {
$this->_apiversion = $version;
......@@ -108,8 +113,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Function tests that a user with "edit my contact" can edit themselves.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testContactEditHookWithEditMyContact($version) {
$this->_apiversion = $version;
......@@ -131,8 +139,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Ensure contact permissions do not block contact-less location entities.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testAddressWithoutContactIDAccess($version) {
$this->_apiversion = $version;
......@@ -165,7 +176,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Ensure contact permissions extend to related entities like email
*
* @param int $version
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
* FIXME: Finish api4 part
*/
......@@ -252,8 +267,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Function tests all results are returned.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testContactGetAllResultsHook($version) {
$this->_apiversion = $version;
......@@ -271,8 +289,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Function tests that deleted contacts are not returned.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testContactGetPermissionHookNoDeleted($version) {
$this->_apiversion = $version;
......@@ -290,8 +311,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Test permissions limited by hook.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testContactGetHookLimitingHook($version) {
$this->_apiversion = $version;
......@@ -309,8 +333,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Confirm that without check permissions we still get 2 contacts returned.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testContactGetHookLimitingHookDontCheck($version) {
$this->_apiversion = $version;
......@@ -422,8 +449,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Check that chaining doesn't bypass permissions
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testContactGetPledgeNotChainable($version) {
$this->_apiversion = $version;
......@@ -461,7 +491,10 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* @dataProvider entities
* confirm that without check permissions we still get 2 contacts returned
* @param $entity
*
* @param string $entity
*
* @throws \CRM_Core_Exception
*/
public function testEntitiesGetHookLimitingHookNoCheck($entity) {
CRM_Core_Config::singleton()->userPermissionClass->permissions = [];
......@@ -500,8 +533,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* @dataProvider entities
* confirm that with check permissions we don't get entities
*
* @param $entity
*
* @throws \PHPUnit\Framework\IncompleteTestError
* @throws \CRM_Core_Exception
*/
public function testEntitiesGetCoreACLLimitingCheck($entity) {
$this->setupCoreACL();
......@@ -516,8 +552,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* @dataProvider entities
* Function tests that an empty where hook returns no results
*
* @param string $entity
*
* @throws \PHPUnit\Framework\IncompleteTestError
* @throws \CRM_Core_Exception
*/
public function testEntityGetNoResultsHook($entity) {
$this->markTestIncomplete('hook acls only work with contacts so far');
......@@ -545,12 +584,12 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
}
/**
* Create 2 entities
* @param $entity
* Create 2 entities.
*
* @param string $entity
*/
public function setUpEntities($entity) {
$baoObj = new CRM_Core_DAO();
$baoObj->createTestObject(_civicrm_api3_get_BAO($entity), [], 2, 0);
CRM_Core_DAO::createTestObject(_civicrm_api3_get_BAO($entity), [], 2, 0);
CRM_Core_Config::singleton()->userPermissionClass->permissions = [
'access CiviCRM',
'access CiviContribute',
......@@ -560,20 +599,27 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
}
/**
* Basic check that an unpermissioned call keeps working and permissioned call fails.
* Basic check that an un-permissioned call keeps working and permissioned call fails.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testGetActivityNoPermissions($version) {
$this->_apiversion = $version;
$this->setPermissions([]);
$this->callAPISuccess('Activity', 'get', []);
$this->callAPISuccess('Activity', 'get');
$this->callAPIFailure('Activity', 'get', ['check_permissions' => 1]);
}
/**
* View all activities is enough regardless of contact ACLs.
*
* @param int $version
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
*/
public function testGetActivityViewAllActivitiesDoesntCutItAnymore($version) {
......@@ -588,8 +634,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* View all activities is required unless id is passed in.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testGetActivityViewAllContactsEnoughWithoutID($version) {
$this->_apiversion = $version;
......@@ -599,7 +648,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Without view all activities contact level acls are used.
*
* @param int $version
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
*/
public function testGetActivityViewAllContactsEnoughWIthID($version) {
......@@ -614,7 +667,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Check the error message is not a permission error.
*
* @param int $version
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
*/
public function testGetActivityAccessCiviCRMEnough($version) {
......@@ -639,7 +696,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
*
* (logically the same component limit should apply when they have access to view all too but....
* adding test for 'how it is at the moment.)
*
* @param int $version
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
*/
public function testGetActivityCheckPermissionsByComponent($version) {
......@@ -664,7 +725,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Check that component related activity filtering works for CiviCase.
*
* @param int $version
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
*/
public function testGetActivityCheckPermissionsByCaseComponent($version) {
......@@ -696,7 +761,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
*
* The activities api applies ACLs in a very limited circumstance, if id is passed in.
* Otherwise it sticks with the blunt original permissions.
*
* @param int $version
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
*/
public function testGetActivityByACL($version) {
......@@ -754,7 +823,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
}
else {
$this->assertEquals([$contact_id], (array) $result[$roleKey]);
$this->assertTrue(!empty($result[$roleName . '_name']));
$this->assertNotEmpty($result[$roleName . '_name']);
}
}
}
......@@ -762,7 +831,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* To leverage ACL permission to view an activity you must be able to see any of the contacts.
*
* @param int $version
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
*/
public function testGetActivityByAclCannotViewAnyContacts($version) {
......@@ -784,9 +857,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
*
* CRM-18409.
*
* @throws \CRM_Core_Exception
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CiviCRM_API3_Exception
* @throws \CRM_Core_Exception
*/
public function testGetActivityACLSourceContactDeleted($version) {
$this->_apiversion = $version;
......@@ -807,8 +882,13 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Test get activities multiple ids with check permissions
*
* @see https://issues.civicrm.org/jira/browse/CRM-20441
*
* @param int $version
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
*/
public function testActivitiesGetMultipleIdsCheckPermissions($version) {
......@@ -833,8 +913,13 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Test get activities multiple ids with check permissions
* Limit access to One contact
*
* @see https://issues.civicrm.org/jira/browse/CRM-20441
*
* @param int $version
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
*/
public function testActivitiesGetMultipleIdsCheckPermissionsLimitedACL($version) {
......@@ -869,8 +954,13 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Test get activities multiple ids with check permissions
*
* @see https://issues.civicrm.org/jira/browse/CRM-20441
*
* @param int $version
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @dataProvider versionThreeAndFour
*/
public function testActivitiesGetMultipleIdsCheckPermissionsNotIN($version) {
......@@ -975,7 +1065,9 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testContactGetViaJoin($version) {
$this->_apiversion = $version;
......@@ -986,7 +1078,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
$tag2 = $this->tagCreate(['name' => uniqid('other'), 'created_id' => $other])['id'];
$this->setPermissions(['access CiviCRM']);
$this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereHookAllResults']);
$createdFirstName = $version == 4 ? 'created.first_name' : 'created_id.first_name';
$createdFirstName = $version === 4 ? 'created.first_name' : 'created_id.first_name';
$result = $this->callAPISuccess('Tag', 'get', [
'check_permissions' => 1,
'return' => ['id', $createdFirstName],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment