Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
7d61e75f | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
7d61e75f TO |
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 | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | */ |
18 | ||
19 | ||
19b53e5b C |
20 | namespace api\v4\Entity; |
21 | ||
420a0aa9 | 22 | use Civi\API\Exception\NotImplementedException; |
19b53e5b C |
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() { | |
d31fb4e3 | 32 | \CRM_Core_BAO_ConfigSetting::enableComponent('CiviEvent'); |
fe806431 | 33 | $result = Entity::get(FALSE) |
19b53e5b C |
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() { | |
fe806431 | 43 | $result = Entity::getActions(FALSE) |
19b53e5b C |
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 | ||
d31fb4e3 CW |
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 | ||
420a0aa9 CW |
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 | ||
d31fb4e3 CW |
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 | ||
19b53e5b | 77 | } |