CRM-18528 - unit test to check group filter
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Fri, 20 May 2016 06:28:30 +0000 (11:58 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Fri, 20 May 2016 06:28:30 +0000 (11:58 +0530)
CRM/Contact/BAO/Group.php
CRM/Group/Page/AJAX.php
tests/phpunit/CRM/Group/Page/AjaxTest.php

index 075d926d70cf184d60799c44928233dc7beb4dac..c832d63b2d1761b5658368a4411f7f5a97010776 100644 (file)
@@ -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]);
index 86dedb3639fd3a483c38f63fbfb06e9901ba6ebe..c9bd98791c14200558521f69792130713c18f09c 100644 (file)
@@ -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);
   }
 
 }
index 7db267319b72ee11dd10224c5457fc0a17bb6a10..6f229087daf8f545d37c66fbfb7dd5095939725e 100644 (file)
@@ -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'
    */