CRM-18706 - Activity type filter on user activities is not working
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Tue, 7 Jun 2016 11:17:53 +0000 (16:47 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Tue, 7 Jun 2016 11:17:53 +0000 (16:47 +0530)
CRM/Activity/Page/AJAX.php
templates/CRM/Activity/Selector/Selector.tpl
tests/phpunit/CRM/Activity/BAO/ActivityTest.php

index b91804d8aa0e288ba7e7e006cc7d346502d421aa..95992e121e266d5600b6b8807d8fb6ab6d325f5b 100644 (file)
@@ -396,6 +396,8 @@ class CRM_Activity_Page_AJAX {
 
     $optionalParameters = array(
       'context' => 'String',
+      'activity_type_id' => 'Integer',
+      'activity_type_exclude_id' => 'Integer',
     );
 
     $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
@@ -409,6 +411,10 @@ class CRM_Activity_Page_AJAX {
     // get the contact activities
     $activities = CRM_Activity_BAO_Activity::getContactActivitySelector($params);
 
+    if (!empty($_GET['is_unit_test'])) {
+      return $activities;
+    }
+
     foreach ($activities['data'] as $key => $value) {
       // Check if recurring activity.
       if (!empty($value['is_recurring_activity'])) {
index afd029e89d9927b81caf70f28d9add85c3b60540..e49ec1c4e78cafd99abf386a30a4057f220239ae 100644 (file)
           "ajax": {
             "url": {/literal}'{crmURL p="civicrm/ajax/contactactivity" h=0 q="snippet=4&context=$context&cid=$contactId"}'{literal},
             "data": function (d) {
-              d.activity_type_id = $('.crm-activity-selector-activity select#activity_type_filter_id').val(),
-              d.activity_type_exclude_id = $('.crm-activity-selector-activity select#activity_type_exclude_filter_id').val()
+              d.activity_type_id = $('.crm-activity-selector-' + context + ' select#activity_type_filter_id').val(),
+              d.activity_type_exclude_id = $('.crm-activity-selector-' + context + ' select#activity_type_exclude_filter_id').val()
             }
           }
         });
         $(function($) {
           $('.activity-search-options :input').change(function(){
-            CRM.$('.contact-activity-selector-activity').DataTable().draw();
+            CRM.$('table.contact-activity-selector-' + context).DataTable().draw();
           });
         });
       })(CRM.$);
index 7e3bf5f1d6a8d7acf6ac3c24eec949c2b16dfb84..18d949b8a7ee2e207f3c03afd4a6a1a3cecda38f 100644 (file)
@@ -360,6 +360,41 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
     $this->assertEquals($count, $activityCount);
   }
 
+  /**
+   * CRM-18706 - Test Include/Exclude Activity Filters
+   */
+  public function testActivityFilters() {
+    $op = new PHPUnit_Extensions_Database_Operation_Insert();
+    $op->execute($this->_dbconn,
+      $this->createFlatXMLDataSet(
+        dirname(__FILE__) . '/activities_for_dashboard_count.xml'
+      )
+    );
+
+    global $_GET;
+    $_GET = array(
+      'cid' => 9,
+      'context' => 'activity',
+      'activity_type_id' => 1,
+      'is_unit_test' => 1,
+    );
+    $obj = new CRM_Activity_Page_AJAX();
+
+    $activities = $obj->getContactActivity();
+    // This should include activities of type Meeting only.
+    foreach ($activities['data'] as $key => $value) {
+      $this->assertEquals('Meeting', $value['activity_type']);
+    }
+    unset($_GET['activity_type_id']);
+
+    $_GET['activity_type_exclude_id'] = 1;
+    $activities = $obj->getContactActivity();
+    // None of the activities should be of type Meeting.
+    foreach ($activities['data'] as $key => $value) {
+      $this->assertNotEquals('Meeting', $value['activity_type']);
+    }
+  }
+
   /**
    * Test getActivitiesCount BAO method.
    */