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 | * $Id$ |
18 | * | |
19 | */ | |
20 | ||
21 | ||
19b53e5b C |
22 | namespace api\v4\Action; |
23 | ||
24 | use api\v4\UnitTestCase; | |
25 | ||
26 | /** | |
27 | * @group headless | |
28 | */ | |
29 | class IndexTest extends UnitTestCase { | |
30 | ||
31 | public function testIndex() { | |
32 | // Results indexed by name | |
33 | $resultByName = civicrm_api4('Activity', 'getActions', [], 'name'); | |
34 | $this->assertInstanceOf('Civi\Api4\Generic\Result', $resultByName); | |
35 | $this->assertEquals('get', $resultByName['get']['name']); | |
36 | ||
37 | // Get result at index 0 | |
38 | $firstResult = civicrm_api4('Activity', 'getActions', [], 0); | |
39 | $this->assertInstanceOf('Civi\Api4\Generic\Result', $firstResult); | |
40 | $this->assertArrayHasKey('name', $firstResult); | |
41 | ||
42 | $this->assertEquals($resultByName->first(), (array) $firstResult); | |
43 | } | |
44 | ||
45 | public function testBadIndexInt() { | |
46 | $error = ''; | |
47 | try { | |
48 | civicrm_api4('Activity', 'getActions', [], 99); | |
49 | } | |
50 | catch (\API_Exception $e) { | |
51 | $error = $e->getMessage(); | |
52 | } | |
53 | $this->assertContains('not found', $error); | |
54 | } | |
55 | ||
56 | public function testBadIndexString() { | |
57 | $error = ''; | |
58 | try { | |
59 | civicrm_api4('Activity', 'getActions', [], 'xyz'); | |
60 | } | |
61 | catch (\API_Exception $e) { | |
62 | $error = $e->getMessage(); | |
63 | } | |
64 | $this->assertContains('not found', $error); | |
65 | } | |
66 | ||
56d00639 CW |
67 | public function testIndexWithSelect() { |
68 | $result = civicrm_api4('Activity', 'getFields', ['select' => ['title'], 'where' => [['name', '=', 'subject']]], 'name'); | |
69 | $this->assertEquals(['subject' => ['title' => 'Subject']], (array) $result); | |
70 | } | |
71 | ||
4a7dc83a CW |
72 | public function testArrayIndex() { |
73 | // Non-associative | |
74 | $result = civicrm_api4('Activity', 'getFields', ['where' => [['name', '=', 'subject']]], ['name' => 'title']); | |
75 | $this->assertEquals(['subject' => 'Subject'], (array) $result); | |
76 | ||
77 | // Associative | |
78 | $result = civicrm_api4('Activity', 'getFields', ['where' => [['name', '=', 'subject']]], ['title']); | |
79 | $this->assertEquals(['Subject'], (array) $result); | |
80 | } | |
81 | ||
19b53e5b | 82 | } |