06139637f2e60a48bf9903d196870f1ad8d226d9
[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\UnitTestCase;
25
26 /**
27 * @group headless
28 */
29 class EntityTest extends UnitTestCase {
30
31 public function testEntityGet() {
32 \CRM_Core_BAO_ConfigSetting::enableComponent('CiviEvent');
33 $result = Entity::get(FALSE)
34 ->execute()
35 ->indexBy('name');
36 $this->assertArrayHasKey('Entity', $result,
37 "Entity::get missing itself");
38 $this->assertArrayHasKey('Participant', $result,
39 "Entity::get missing Participant");
40 }
41
42 public function testEntity() {
43 $result = Entity::getActions(FALSE)
44 ->execute()
45 ->indexBy('name');
46 $this->assertNotContains(
47 'create',
48 array_keys((array) $result),
49 "Entity entity has more than basic actions");
50 }
51
52 public function testEntityComponent() {
53 \CRM_Core_BAO_ConfigSetting::disableComponent('CiviEvent');
54 $result = Entity::get(FALSE)
55 ->execute()
56 ->indexBy('name');
57 $this->assertArrayNotHasKey('Participant', $result,
58 "Entity::get should not have Participant when CiviEvent disabled");
59
60 // Trying to use a CiviEvent API will fail when component is disabled
61 try {
62 \Civi\Api4\Participant::get(FALSE)->execute();
63 $this->fail();
64 }
65 catch (NotImplementedException $e) {
66 $this->assertStringContainsString('CiviEvent', $e->getMessage());
67 }
68
69 \CRM_Core_BAO_ConfigSetting::enableComponent('CiviEvent');
70 $result = Entity::get(FALSE)
71 ->execute()
72 ->indexBy('name');
73 $this->assertArrayHasKey('Participant', $result,
74 "Entity::get should have Participant when CiviEvent enabled");
75 }
76
77 }