From 47c89d6bd4459229f9a4e8a8f31b2973c1bf73bd Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 3 May 2014 06:33:55 -0700 Subject: [PATCH] CRM-14109 enable & fix group count tests --- CRM/Contact/BAO/Group.php | 68 ++++++++++++----------- tests/phpunit/CRM/Group/Page/AjaxTest.php | 4 -- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index e0436cc5db..21c5718bd5 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -607,6 +607,31 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { return $condition; } + /** + * get permission relevant clauses + * CRM-12209 + * + * @internal param $existingClauses + * + * @internal param $clauses + * + * @return array + */ + public static function getPermissionClause() { + static $clause; + static $retrieved = FALSE; + if (!$retrieved && !CRM_Core_Permission::check('view all contacts')) { + //get the allowed groups for the current user + $groups = CRM_ACL_API::group(CRM_ACL_API::VIEW); + if (!empty($groups)) { + $groupList = implode(', ', array_values($groups)); + $clause = "groups.id IN ( $groupList ) "; + } + } + $retrieved = TRUE; + return $clause; + } + public function __toString() { return $this->title; } @@ -1083,10 +1108,16 @@ WHERE {$whereClause}"; return CRM_Core_DAO::singleValueQuery($query, $params); } + /** + * Generate permissioned where clause for group search + * @param $params + * @param bool $sortBy + * @param bool $excludeHidden + * + * @return string + */ static function whereClause(&$params, $sortBy = TRUE, $excludeHidden = TRUE) { $values = array(); - $clauses = array(); - $title = CRM_Utils_Array::value('title', $params); if ($title) { $clauses[] = "groups.title LIKE %1"; @@ -1155,27 +1186,6 @@ WHERE {$whereClause}"; } } - /* - if ( $sortBy && - $this->_sortByCharacter !== null ) { - $clauses[] = - "groups.title LIKE '" . - strtolower(CRM_Core_DAO::escapeWildCardString($this->_sortByCharacter)) . - "%'"; - } - - // dont do a the below assignement when doing a - // AtoZ pager clause - if ( $sortBy ) { - if ( count( $clauses ) > 1 ) { - $this->assign( 'isSearch', 1 ); - } else { - $this->assign( 'isSearch', 0 ); - } - } - */ - - if (empty($clauses)) { $clauses[] = 'groups.is_active = 1'; } @@ -1183,16 +1193,12 @@ WHERE {$whereClause}"; if ($excludeHidden) { $clauses[] = 'groups.is_hidden = 0'; } - //CRM-12209 - if (!CRM_Core_Permission::check('view all contacts')) { - //get the allowed groups for the current user - $groups = CRM_ACL_API::group(CRM_ACL_API::VIEW); - if (!empty( $groups)) { - $groupList = implode( ', ', array_values( $groups ) ); - $clauses[] = "groups.id IN ( $groupList ) "; - } + ; + if(($permissionClause = self::getPermissionClause($clauses)) == TRUE) { + $clauses[] = $permissionClause; } + return implode(' AND ', $clauses); } diff --git a/tests/phpunit/CRM/Group/Page/AjaxTest.php b/tests/phpunit/CRM/Group/Page/AjaxTest.php index 20f47a07f7..e6dd79cf2e 100644 --- a/tests/phpunit/CRM/Group/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Group/Page/AjaxTest.php @@ -183,7 +183,6 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $_REQUEST = $this->_params; list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(0, count($groups)); - $this->markTestIncomplete('The AJAX function returns an incorrect result - needs fixing'); $this->assertEquals(0, $total, 'Total returned should be accurate based on permissions'); } /** @@ -196,7 +195,6 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $_REQUEST['status'] = 1; list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(0, count($groups)); - $this->markTestIncomplete('The AJAX function returns an incorrect result - needs fixing'); $this->assertEquals(0, $total, 'Total returned should be accurate based on permissions'); } /** @@ -209,7 +207,6 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $_REQUEST['status'] = 2; list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(0, count($groups)); - $this->markTestIncomplete('The AJAX function returns an incorrect result - needs fixing'); $this->assertEquals(0, $total, 'Total returned should be accurate based on permissions'); } @@ -223,7 +220,6 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $_REQUEST['status'] = 2; list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(0, count($groups)); - $this->markTestIncomplete('The AJAX function returns an incorrect result - needs fixing'); $this->assertEquals(0, $total, 'Total returned should be accurate based on permissions'); } -- 2.25.1