Skip to content

Commit

Permalink
Merge pull request #22322 from colemanw/groupContactDefaults
Browse files Browse the repository at this point in the history
APIv4 - Set default status when creating GroupContact record
  • Loading branch information
eileenmcnaughton authored Dec 27, 2021
2 parents 14418d2 + 057e323 commit ddee419
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

namespace Civi\Api4\Service\Spec\Provider;

use Civi\Api4\Service\Spec\RequestSpec;

class GroupContactCreationSpecProvider implements Generic\SpecProviderInterface {

/**
* @inheritDoc
*/
public function modifySpec(RequestSpec $spec) {
$spec->getFieldByName('status')->setDefaultValue('Added');
}

/**
* @inheritDoc
*/
public function applies($entity, $action) {
return $entity === 'GroupContact' && $action === 'create';
}

}
41 changes: 41 additions & 0 deletions tests/phpunit/api/v4/Entity/GroupContactTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/


namespace api\v4\Entity;

use api\v4\UnitTestCase;
use Civi\Api4\GroupContact;

/**
* @group headless
*/
class GroupContactTest extends UnitTestCase {

public function testCreate() {
$contact = $this->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']);
}

}
3 changes: 3 additions & 0 deletions tests/phpunit/api/v4/UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit ddee419

Please sign in to comment.