handle missing array member
authordemeritcowboy <demeritcowboy@hotmail.com>
Sat, 3 Oct 2020 16:46:15 +0000 (12:46 -0400)
committerdemeritcowboy <demeritcowboy@hotmail.com>
Sat, 3 Oct 2020 20:17:10 +0000 (16:17 -0400)
CRM/Activity/BAO/Activity.php
tests/phpunit/CRM/Activity/BAO/ActivityTest.php

index 60ffb77aa5dbc82587d11a0a6732ed85a616f209..8414c93660d9bc52369cc7f15430c5b935d8abd9 100644 (file)
@@ -2566,7 +2566,7 @@ INNER JOIN  civicrm_option_group grp ON (grp.id = option_group_id AND grp.name =
             }
           }
         }
-        elseif (!$values['target_contact_name']) {
+        elseif (empty($values['target_contact_name'])) {
           $activity['target_contact_name'] = '<em>n/a</em>';
         }
 
index 913728bc0869b629e24bb0a78d15284fb31f64cc..b6a39ba499c79c4d7eae473fae0023395bd4d75c 100644 (file)
@@ -213,6 +213,35 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
     $this->cleanUpAfterACLs();
   }
 
+  /**
+   * Check for errors when viewing a contact's activity tab when there
+   * is an activity that doesn't have a target (With Contact).
+   */
+  public function testActivitySelectorNoTargets() {
+    $contact_id = $this->individualCreate([], 0, TRUE);
+    $activity = $this->callAPISuccess('activity', 'create', [
+      'source_contact_id' => $contact_id,
+      'activity_type_id' => 'Meeting',
+      'subject' => 'Lonely Meeting',
+      'details' => 'Here at this meeting all by myself and no other contacts.',
+    ]);
+    $input = [
+      '_raw_values' => [],
+      'offset' => 0,
+      'rp' => 25,
+      'page' => 1,
+      'context' => 'activity',
+      'contact_id' => $contact_id,
+    ];
+    $output = CRM_Activity_BAO_Activity::getContactActivitySelector($input);
+    $this->assertEquals($activity['id'], $output['data'][0]['DT_RowId']);
+    $this->assertEquals('<em>n/a</em>', $output['data'][0]['target_contact_name']);
+    $this->assertEquals('Lonely Meeting', $output['data'][0]['subject']);
+
+    $this->callAPISuccess('activity', 'delete', ['id' => $activity['id']]);
+    $this->callAPISuccess('contact', 'delete', ['id' => $contact_id]);
+  }
+
   /**
    * Test case for deleteActivity() method.
    *