From c4e0c054f226c3867e55da18c1cd75ad8e73b153 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 3 Oct 2023 08:59:41 +1100 Subject: [PATCH] [NFC] Add in Unit test to ensure that Disabled groups do not appear in mailing receipients autocomplete --- .../SearchDisplay/AbstractRunAction.php | 2 +- .../api/v4/Action/AutocompleteTest.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php index 427a34f717..df97bae80e 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php @@ -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]); } } diff --git a/tests/phpunit/api/v4/Action/AutocompleteTest.php b/tests/phpunit/api/v4/Action/AutocompleteTest.php index 2c71219de7..da756de267 100644 --- a/tests/phpunit/api/v4/Action/AutocompleteTest.php +++ b/tests/phpunit/api/v4/Action/AutocompleteTest.php @@ -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']); + } + } -- 2.25.1