4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 namespace api\v
4\Action
;
24 use api\v
4\UnitTestCase
;
29 class ChainTest
extends UnitTestCase
{
31 public function testGetActionsWithFields() {
32 $actions = \Civi\Api4\Activity
::getActions()
33 ->addChain('fields', \Civi\Api4\Activity
::getFields()->setAction('$name'), 'name')
37 $this->assertEquals('Array', $actions['getActions']['fields']['params']['data_type']);
40 public function testGetEntityWithActions() {
41 $entities = \Civi\Api4\Entity
::get()
44 'actions' => ['$name', 'getActions', ['select' => ['name']], 'name'],
49 $this->assertArrayHasKey('replace', $entities['Contact']['actions']);
50 $this->assertArrayHasKey('getLinks', $entities['Entity']['actions']);
51 $this->assertArrayNotHasKey('replace', $entities['Entity']['actions']);
54 public function testContactCreateWithGroup() {
55 $firstName = uniqid('cwtf');
56 $lastName = uniqid('cwtl');
58 $contact = \Civi\Api4\Contact
::create()
59 ->addValue('first_name', $firstName)
60 ->addValue('last_name', $lastName)
61 ->addChain('group', \Civi\Api4\Group
::create()->addValue('title', '$display_name'), 0)
62 ->addChain('add_to_group', \Civi\Api4\GroupContact
::create()->addValue('contact_id', '$id')->addValue('group_id', '$group.id'), 0)
63 ->addChain('check_group', \Civi\Api4\GroupContact
::get()->addWhere('group_id', '=', '$group.id'))
67 $this->assertCount(1, $contact['check_group']);
68 $this->assertEquals($contact['id'], $contact['check_group'][0]['contact_id']);
69 $this->assertEquals($contact['group']['id'], $contact['check_group'][0]['group_id']);