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