From 33072bc700cbf86954f411218705ffbfabbc64e6 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 3 Mar 2017 20:38:07 +1300 Subject: [PATCH] CRM-19773 unit test to verify acls apply --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 14 ++++++++++++ tests/phpunit/api/v3/ACLPermissionTest.php | 14 ------------ tests/phpunit/api/v3/ReportTemplateTest.php | 24 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 9695943029..c95c39b0f3 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3770,4 +3770,18 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) $this->_ids['membership_type'] = $membershipTypeID; } + /** + * No results returned. + * + * @implements CRM_Utils_Hook::aclWhereClause + * + * @param string $type + * @param array $tables + * @param array $whereTables + * @param int $contactID + * @param string $where + */ + public function aclWhereHookNoResults($type, &$tables, &$whereTables, &$contactID, &$where) { + } + } diff --git a/tests/phpunit/api/v3/ACLPermissionTest.php b/tests/phpunit/api/v3/ACLPermissionTest.php index 7e17d7aec0..2bc56747a4 100644 --- a/tests/phpunit/api/v3/ACLPermissionTest.php +++ b/tests/phpunit/api/v3/ACLPermissionTest.php @@ -427,20 +427,6 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase { ); } - /** - * No results returned. - * - * @implements CRM_Utils_Hook::aclWhereClause - * - * @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. * diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index 34904b5ab6..accb984d73 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -235,6 +235,30 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $this->assertEquals(1, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE)); } + /** + * Test Lybunt report applies ACLs. + */ + public function testLybuntReportWithDataAndACLFilter() { + CRM_Core_Config::singleton()->userPermissionClass->permissions = array('administer CiviCRM'); + $inInd = $this->individualCreate(); + $outInd = $this->individualCreate(); + $this->contributionCreate(array('contact_id' => $inInd, 'receive_date' => '2014-03-01')); + $this->contributionCreate(array('contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL)); + $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookNoResults')); + $params = array( + 'report_id' => 'contribute/lybunt', + 'yid_value' => 2015, + 'yid_op' => 'calendar', + 'options' => array('metadata' => array('sql')), + 'check_permissions' => 1, + ); + + $rows = $this->callAPISuccess('report_template', 'getrows', $params); + $this->assertEquals(0, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE)); + + CRM_Utils_Hook::singleton()->reset(); + } + /** * Test Lybunt report to check basic inclusion of a contact who gave in the year before the chosen year. */ -- 2.25.1