1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php
namespace Civi\Test\Api4\Action;
use Civi\Test\Api4\UnitTestCase;
/**
* @group headless
*/
class IndexTest extends UnitTestCase {
public function testIndex() {
// Results indexed by name
$resultByName = civicrm_api4('Activity', 'getActions', [], 'name');
$this->assertInstanceOf('Civi\Api4\Generic\Result', $resultByName);
$this->assertEquals('get', $resultByName['get']['name']);
// Get result at index 0
$firstResult = civicrm_api4('Activity', 'getActions', [], 0);
$this->assertInstanceOf('Civi\Api4\Generic\Result', $firstResult);
$this->assertArrayHasKey('name', $firstResult);
$this->assertEquals($resultByName->first(), (array) $firstResult);
}
public function testBadIndexInt() {
$error = '';
try {
civicrm_api4('Activity', 'getActions', [], 99);
}
catch (\API_Exception $e) {
$error = $e->getMessage();
}
$this->assertContains('not found', $error);
}
public function testBadIndexString() {
$error = '';
try {
civicrm_api4('Activity', 'getActions', [], 'xyz');
}
catch (\API_Exception $e) {
$error = $e->getMessage();
}
$this->assertContains('not found', $error);
}
}
|