From: jitendrapurohit Date: Fri, 20 May 2016 06:28:30 +0000 (+0530) Subject: CRM-18528 - unit test to check group filter X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=46d33c7af0f9e37c4b2fb63d88e3658bc12ca782;p=civicrm-core.git CRM-18528 - unit test to check group filter --- diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 075d926d70..c832d63b2d 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -755,7 +755,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]); diff --git a/CRM/Group/Page/AJAX.php b/CRM/Group/Page/AJAX.php index 86dedb3639..c9bd98791c 100644 --- a/CRM/Group/Page/AJAX.php +++ b/CRM/Group/Page/AJAX.php @@ -46,8 +46,6 @@ class CRM_Group_Page_AJAX { $params['page'] = 1; $params['rp'] = 0; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); - - CRM_Utils_JSON::output($groups); } else { $requiredParams = array(); @@ -78,9 +76,13 @@ class CRM_Group_Page_AJAX { $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); } } + } - CRM_Utils_JSON::output($groups); + if (!empty($_GET['is_unit_test'])) { + return $groups; } + + CRM_Utils_JSON::output($groups); } } diff --git a/tests/phpunit/CRM/Group/Page/AjaxTest.php b/tests/phpunit/CRM/Group/Page/AjaxTest.php index 7db267319b..6f229087da 100644 --- a/tests/phpunit/CRM/Group/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Group/Page/AjaxTest.php @@ -80,6 +80,29 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase { $_REQUEST = $this->_params; } + /** + * CRM-18528 - Retrieve groups with filter + */ + public function testGroupListWithFilter() { + global $_GET; + $_GET = $this->_params; + $obj = new CRM_Group_Page_AJAX(); + + //filter with title + $_GET['title'] = "not-me-active"; + $groups = $obj->getGroupList(); + $this->assertEquals(1, $groups['recordsTotal']); + $this->assertEquals('not-me-active', $groups['data'][0]['title']); + unset($_GET['title']); + + // check on status + $_GET['status'] = 2; + $groups = $obj->getGroupList(); + $this->assertEquals(2, $groups['recordsTotal']); + $this->assertEquals('not-me-disabled', $groups['data'][0]['title']); + $this->assertEquals('pick-me-disabled', $groups['data'][1]['title']); + } + /** * Retrieve groups as 'view all contacts' */