From cd83e08fb08edcd5b1669b6802d27a757e4e9ba3 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Fri, 1 Apr 2016 19:55:38 +0530 Subject: [PATCH] CRM-18343: Ajax CRM test failure fixes --- CRM/Contact/BAO/Group.php | 5 +- CRM/Group/Page/AJAX.php | 6 +- tests/phpunit/CRM/Group/Page/AjaxTest.php | 80 +++++++++++------------ 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 84ca887149..8f6a63e690 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -750,7 +750,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { $value['class'] = array_diff($value['class'], array('crm-row-parent')); } $group['DT_RowId'] = 'row_' . $value['id']; - if (!$params['parentsOnly']) { + if (!empty($params['parentsOnly'])) { foreach ($value['class'] as $id => $class) { if ($class == 'crm-group-parent') { unset($value['class'][$id]); @@ -778,7 +778,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { $group['is_parent'] = $value['is_parent']; - array_push($groupList, $group); + $groupList[$id] = $group; } $groupsDT = array(); @@ -801,7 +801,6 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { $config = CRM_Core_Config::singleton(); $whereClause = self::whereClause($params, FALSE); - //$this->pagerAToZ( $whereClause, $params ); if (!empty($params['rowCount']) && diff --git a/CRM/Group/Page/AJAX.php b/CRM/Group/Page/AJAX.php index daa6b72597..57d57b0318 100644 --- a/CRM/Group/Page/AJAX.php +++ b/CRM/Group/Page/AJAX.php @@ -43,7 +43,6 @@ class CRM_Group_Page_AJAX { */ public static function getGroupList() { $params = $_GET; - if (isset($params['parent_id'])) { // requesting child groups for a given parent $params['page'] = 1; @@ -55,7 +54,8 @@ class CRM_Group_Page_AJAX { else { $sortMapper = array(); - foreach ($_GET['columns'] as $key => $value) { + $columns = CRM_Utils_Array::value('columns', $params, array()); + foreach ($columns as $key => $value) { $sortMapper[$key] = $value['data']; }; @@ -90,7 +90,7 @@ class CRM_Group_Page_AJAX { //@todo - ideally the portion of this that retrieves the groups should be extracted into a function separate // from the one which deals with web inputs & outputs so we have a properly testable & re-usable function if (!empty($params['is_unit_test'])) { - return array($groups, $iFilteredTotal); + return array($groups['data'], $params['total']); } CRM_Utils_JSON::output($groups); } diff --git a/tests/phpunit/CRM/Group/Page/AjaxTest.php b/tests/phpunit/CRM/Group/Page/AjaxTest.php index 2a17b699fe..a40beb1895 100644 --- a/tests/phpunit/CRM/Group/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Group/Page/AjaxTest.php @@ -65,8 +65,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { public function setPermissionAndRequest($permission) { CRM_Core_Config::singleton()->userPermissionClass->permissions = (array) $permission; CRM_Contact_BAO_Group::getPermissionClause(TRUE); - global $_REQUEST; - $_REQUEST = $this->_params; + global $_GET; + $_GET = $this->_params; } /** @@ -77,8 +77,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { CRM_Core_Config::singleton()->userPermissionClass->permissions = (array) $permission; $this->hookClass->setHook('civicrm_aclGroup', array($this, $hook)); CRM_Contact_BAO_Group::getPermissionClause(TRUE); - global $_REQUEST; - $_REQUEST = $this->_params; + global $_GET; + $_GET = $this->_params; } /** @@ -88,8 +88,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(2, $total); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); - $this->assertEquals('not-me-active', $groups[4]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); + $this->assertEquals('not-me-active', $groups[4]['title']); } /** @@ -99,15 +99,15 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $this->setPermissionAndRequest('view all contacts'); list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(2, $total); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); - $this->assertEquals('not-me-active', $groups[4]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); + $this->assertEquals('not-me-active', $groups[4]['title']); // as per changes made in PR-6822 $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(2, $total); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); - $this->assertEquals('not-me-active', $groups[4]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); + $this->assertEquals('not-me-active', $groups[4]['title']); } /** @@ -120,8 +120,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(2, $total); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); } /** @@ -141,8 +141,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $this->setPermissionAndRequest(array('edit all contacts', 'edit groups')); list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(2, $total); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); - $this->assertEquals('not-me-active', $groups[4]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); + $this->assertEquals('not-me-active', $groups[4]['title']); } /** @@ -153,8 +153,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(2, $total); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); - $this->assertEquals('not-me-active', $groups[4]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); + $this->assertEquals('not-me-active', $groups[4]['title']); } /** @@ -165,8 +165,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(2, $total); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); - $this->assertEquals('not-me-disabled', $groups[3]['group_name']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); + $this->assertEquals('not-me-disabled', $groups[3]['title']); } /** @@ -178,7 +178,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(1, $total); - $this->assertEquals('not-me-disabled', $groups[3]['group_name']); + $this->assertEquals('not-me-disabled', $groups[3]['title']); } /** @@ -190,7 +190,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(1, $total); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); } /** @@ -201,10 +201,10 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(4, $total); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); - $this->assertEquals('not-me-disabled', $groups[3]['group_name']); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); - $this->assertEquals('not-me-active', $groups[4]['group_name']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); + $this->assertEquals('not-me-disabled', $groups[3]['title']); + $this->assertEquals('pick-me-active', $groups[2]['title']); + $this->assertEquals('not-me-active', $groups[4]['title']); } @@ -281,7 +281,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(1, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); } public function testTraditionalACLNotFoundTitle() { @@ -299,8 +299,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(2, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(2, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); } public function testTraditionalACLDisabled() { @@ -310,7 +310,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(1, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); } public function testTraditionalACLDisabledFoundTitle() { @@ -321,7 +321,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(1, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); } public function testTraditionalACLDisabledNotFoundTitle() { @@ -340,7 +340,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(1, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); } public function testTraditionalACLAll() { @@ -350,8 +350,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(2, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(2, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); } /** @@ -363,7 +363,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(1, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); } /** @@ -376,7 +376,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(1, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); } /** @@ -400,7 +400,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(1, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); } /** @@ -423,8 +423,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(2, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(2, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); } /** @@ -436,8 +436,8 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(2, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(2, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); - $this->assertEquals('pick-me-disabled', $groups[1]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); + $this->assertEquals('pick-me-disabled', $groups[1]['title']); } /** @@ -449,7 +449,7 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { list($groups, $total) = CRM_Group_Page_AJAX::getGroupList(); $this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default'); $this->assertEquals(1, $total, 'Total needs to be set correctly'); - $this->assertEquals('pick-me-active', $groups[2]['group_name']); + $this->assertEquals('pick-me-active', $groups[2]['title']); } /** -- 2.25.1