Fixes to Group Page PHPUnit test
authorJoseph Lacey <joseph@palantetech.coop>
Wed, 17 Feb 2016 18:11:07 +0000 (13:11 -0500)
committerdeb.monish <monish.deb@webaccessglobal.com>
Fri, 8 Apr 2016 08:49:06 +0000 (14:19 +0530)
CRM/Group/Page/AJAX.php
tests/phpunit/CRM/Group/Page/AjaxTest.php

index 57d57b0318b7deeaae9e5ce546ef45cf9b41bf0b..b492427a1c2cfdb5dc6024e01a55400acf84a636 100644 (file)
@@ -57,7 +57,7 @@ class CRM_Group_Page_AJAX {
       $columns = CRM_Utils_Array::value('columns', $params, array());
       foreach ($columns as $key => $value) {
         $sortMapper[$key] = $value['data'];
-      };
+      }
 
       $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
       $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25;
@@ -86,12 +86,6 @@ class CRM_Group_Page_AJAX {
         }
       }
 
-      //add setting so this can be tested by unit test
-      //@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['data'], $params['total']);
-      }
       CRM_Utils_JSON::output($groups);
     }
   }
index d27085ddb2225b1f27bbcb8aab7d463e7d2e4d48..cbea43d9d128ebab08533a2ff6a770176a323270 100644 (file)
@@ -86,10 +86,11 @@ class CRM_Group_Page_AjaxTest extends CiviUnitTestCase {
    */
   public function testGroupListViewAllContacts() {
     $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
-    list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
-    $this->assertEquals(2, $total);
-    $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
-    $this->assertEquals('<span class="crm-editable crmf-title">not-me-active</span>', $groups[4]['group_name']);
+    $params = $this->_params;
+    $groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
+    $this->assertEquals(2, $groups['recordsTotal']);
+    $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups['data'][2]['group_name']);
+    $this->assertEquals('<span class="crm-editable crmf-title">not-me-active</span>', $groups['data'][4]['group_name']);
   }
 
   /**