[NFC] Add in Unit test to ensure that Disabled groups do not appear in mailing receip...
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 2 Oct 2023 21:59:41 +0000 (08:59 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 2 Oct 2023 21:59:41 +0000 (08:59 +1100)
ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php
tests/phpunit/api/v4/Action/AutocompleteTest.php

index 427a34f71718d71c5da193cc2eece316e1eb36e0..df97bae80eeb4f6326bd6963ccfce9d3fc69d292 100644 (file)
@@ -177,7 +177,7 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction {
       default:
         if (!empty($data[$key])) {
           $item = $this->getSelectExpression($key);
-          if ($item['expr'] instanceof SqlField && $item['fields'][$key]['fk_entity'] === 'File') {
+          if ($item['expr'] instanceof SqlField && isset($item['fields'][$key]) && $item['fields'][$key]['fk_entity'] === 'File') {
             return $this->generateFileUrl($data[$key]);
           }
         }
index 2c71219de73d4116a53f36aefa7e666cd85b6449..da756de26713b22c33cd3d667a35478eba036583 100644 (file)
@@ -23,6 +23,7 @@ use api\v4\Api4TestBase;
 use Civi\API\Exception\UnauthorizedException;
 use Civi\Api4\Contact;
 use Civi\Api4\MockBasicEntity;
+use Civi\Api4\EntitySet;
 use Civi\Api4\SavedSearch;
 use Civi\Core\Event\GenericHookEvent;
 use Civi\Test\HookInterface;
@@ -331,4 +332,28 @@ class AutocompleteTest extends Api4TestBase implements HookInterface, Transactio
     $this->assertNotContains($cid, $result->column('id'));
   }
 
+  public function testMailingAutocompleteNoDisabledGroups(): void {
+    $this->createTestRecord('Group', [
+      'title' => 'Second Star',
+      'frontend_title' => 'Second Star',
+      'name' => 'Second_Star',
+      'group_type:name' => 'Mailing List',
+    ]);
+    $this->createTestRecord('Group', [
+      'title' => 'Second',
+      'frontend_title' => 'Second',
+      'name' => 'Second',
+      'group_type:name' => 'Mailing List',
+      'is_active' => 0,
+    ]);
+
+    $result = EntitySet::autocomplete()
+      ->setInput('')
+      ->setFieldName('Mailing.recipients_include')
+      ->setFormName('crmMailing.1')
+      ->execute();
+    $this->assertCount(1, $result);
+    $this->assertEquals('Second Star', $result[0]['label']);
+  }
+
 }