From 057e323f32c105f44dff9d50d4f1c5f2fdedfb93 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 26 Dec 2021 19:52:57 -0500 Subject: [PATCH] APIv4 - Set default status when creating GroupContact record Fixes dev/core#2924 --- .../GroupContactCreationSpecProvider.php | 33 +++++++++++++++ .../api/v4/Entity/GroupContactTest.php | 41 +++++++++++++++++++ tests/phpunit/api/v4/UnitTestCase.php | 3 ++ 3 files changed, 77 insertions(+) create mode 100644 Civi/Api4/Service/Spec/Provider/GroupContactCreationSpecProvider.php create mode 100644 tests/phpunit/api/v4/Entity/GroupContactTest.php diff --git a/Civi/Api4/Service/Spec/Provider/GroupContactCreationSpecProvider.php b/Civi/Api4/Service/Spec/Provider/GroupContactCreationSpecProvider.php new file mode 100644 index 000000000000..240a1a228b55 --- /dev/null +++ b/Civi/Api4/Service/Spec/Provider/GroupContactCreationSpecProvider.php @@ -0,0 +1,33 @@ +getFieldByName('status')->setDefaultValue('Added'); + } + + /** + * @inheritDoc + */ + public function applies($entity, $action) { + return $entity === 'GroupContact' && $action === 'create'; + } + +} diff --git a/tests/phpunit/api/v4/Entity/GroupContactTest.php b/tests/phpunit/api/v4/Entity/GroupContactTest.php new file mode 100644 index 000000000000..0824e249574e --- /dev/null +++ b/tests/phpunit/api/v4/Entity/GroupContactTest.php @@ -0,0 +1,41 @@ +createEntity(['type' => 'Individual']); + $group = $this->createEntity(['type' => 'Group']); + $result = GroupContact::create(FALSE) + ->addValue('group_id', $group['id']) + ->addValue('contact_id', $contact['id']) + ->execute() + ->first(); + $this->assertEquals('Added', $result['status']); + } + +} diff --git a/tests/phpunit/api/v4/UnitTestCase.php b/tests/phpunit/api/v4/UnitTestCase.php index 5982f1b920f1..992550b1b4df 100644 --- a/tests/phpunit/api/v4/UnitTestCase.php +++ b/tests/phpunit/api/v4/UnitTestCase.php @@ -264,6 +264,9 @@ public static function sampleData($type) { 'subject' => 'unit testing', 'source_contact_id' => 'dummy.Individual', ], + 'Group' => [ + 'title' => 'unit testing', + ], ]; if ($type == 'Contact') { $type = 'Individual';