fa93ddbeba16b8ab3f0d29b0f97e8d8c538c59ba
[civicrm-core.git] / tests / phpunit / api / v4 / Entity / EntityTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18
19
20 namespace api\v4\Entity;
21
22 use Civi\API\Exception\NotImplementedException;
23 use Civi\Api4\Entity;
24 use api\v4\Api4TestBase;
25 use Civi\Test\TransactionalInterface;
26
27 /**
28 * @group headless
29 */
30 class EntityTest extends Api4TestBase implements TransactionalInterface {
31
32 public function testEntityGet() {
33 \CRM_Core_BAO_ConfigSetting::enableComponent('CiviEvent');
34 $result = Entity::get(FALSE)
35 ->execute()
36 ->indexBy('name');
37 $this->assertArrayHasKey('Entity', $result,
38 "Entity::get missing itself");
39 $this->assertArrayHasKey('Participant', $result,
40 "Entity::get missing Participant");
41 }
42
43 public function testEntity() {
44 $result = Entity::getActions(FALSE)
45 ->execute()
46 ->indexBy('name');
47 $this->assertNotContains(
48 'create',
49 array_keys((array) $result),
50 "Entity entity has more than basic actions");
51 }
52
53 public function testEntityComponent() {
54 \CRM_Core_BAO_ConfigSetting::disableComponent('CiviEvent');
55 $result = Entity::get(FALSE)
56 ->execute()
57 ->indexBy('name');
58 $this->assertArrayNotHasKey('Participant', $result,
59 "Entity::get should not have Participant when CiviEvent disabled");
60
61 // Trying to use a CiviEvent API will fail when component is disabled
62 try {
63 \Civi\Api4\Participant::get(FALSE)->execute();
64 $this->fail();
65 }
66 catch (NotImplementedException $e) {
67 $this->assertStringContainsString('CiviEvent', $e->getMessage());
68 }
69
70 \CRM_Core_BAO_ConfigSetting::enableComponent('CiviEvent');
71 $result = Entity::get(FALSE)
72 ->execute()
73 ->indexBy('name');
74 $this->assertArrayHasKey('Participant', $result,
75 "Entity::get should have Participant when CiviEvent enabled");
76 }
77
78 }