From: Coleman Watts Date: Mon, 6 Jul 2020 21:59:31 +0000 (-0400) Subject: APIv4 - Add activity contacts to APIv4 field spec X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8c6a5fd64bb49006c96490aa221ff1af71e5092f;p=civicrm-core.git APIv4 - Add activity contacts to APIv4 field spec The BAO supports these pseudo-fields during save operations, this exposes them to the api explorer. --- diff --git a/Civi/Api4/Service/Spec/Provider/ActivityCreationSpecProvider.php b/Civi/Api4/Service/Spec/Provider/ActivityCreationSpecProvider.php deleted file mode 100644 index 028dbcfb0b..0000000000 --- a/Civi/Api4/Service/Spec/Provider/ActivityCreationSpecProvider.php +++ /dev/null @@ -1,45 +0,0 @@ -setRequired(TRUE); - $sourceContactField->setFkEntity('Contact'); - - $spec->addFieldSpec($sourceContactField); - } - - /** - * @inheritDoc - */ - public function applies($entity, $action) { - return $entity === 'Activity' && $action === 'create'; - } - -} diff --git a/Civi/Api4/Service/Spec/Provider/ActivitySpecProvider.php b/Civi/Api4/Service/Spec/Provider/ActivitySpecProvider.php new file mode 100644 index 0000000000..95504953b1 --- /dev/null +++ b/Civi/Api4/Service/Spec/Provider/ActivitySpecProvider.php @@ -0,0 +1,60 @@ +getAction(); + + $field = new FieldSpec('source_contact_id', 'Activity', 'Integer'); + $field->setTitle(ts('Source Contact')); + $field->setDescription(ts('Contact who created this activity.')); + $field->setRequired($action === 'create'); + $field->setFkEntity('Contact'); + $spec->addFieldSpec($field); + + $field = new FieldSpec('target_contact_id', 'Activity', 'Array'); + $field->setTitle(ts('Target Contacts')); + $field->setDescription(ts('Contact(s) involved in this activity.')); + $field->setFkEntity('Contact'); + $spec->addFieldSpec($field); + + $field = new FieldSpec('assignee_contact_id', 'Activity', 'Array'); + $field->setTitle(ts('Assignee Contacts')); + $field->setDescription(ts('Contact(s) assigned to this activity.')); + $field->setFkEntity('Contact'); + $spec->addFieldSpec($field); + } + + /** + * @inheritDoc + */ + public function applies($entity, $action) { + return $entity === 'Activity' && in_array($action, ['create', 'update'], TRUE); + } + +} diff --git a/tests/phpunit/api/v3/ActivityTest.php b/tests/phpunit/api/v3/ActivityTest.php index 7db390114f..86e7d23062 100644 --- a/tests/phpunit/api/v3/ActivityTest.php +++ b/tests/phpunit/api/v3/ActivityTest.php @@ -370,9 +370,11 @@ class api_v3_ActivityTest extends CiviUnitTestCase { /** * Test get returns target and assignee contacts. + * @dataProvider versionThreeAndFour + * @var int $version */ - public function testActivityReturnTargetAssignee() { - + public function testActivityReturnTargetAssignee($version) { + $this->_apiversion = $version; $description = "Demonstrates setting & retrieving activity target & source."; $subfile = "GetTargetandAssignee"; $params = [ @@ -390,9 +392,18 @@ class api_v3_ActivityTest extends CiviUnitTestCase { ]; $result = $this->callAPIAndDocument('activity', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); + + $actContacts = $this->callAPISuccess('ActivityContact', 'get', [ + 'activity_id' => $result['id'], + ]); + $this->assertCount(3, $actContacts['values']); + + if ($version === 4) { + $this->markTestIncomplete("APIv4 doesn't retrieve activity contacts directly."); + } + $result = $this->callAPISuccess('activity', 'get', [ 'id' => $result['id'], - 'version' => $this->_apiversion, 'return.assignee_contact_id' => 1, 'return.target_contact_id' => 1, ]);