diff options
Diffstat (limited to 'www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Action/IndexTest.php')
-rw-r--r-- | www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Action/IndexTest.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Action/IndexTest.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Action/IndexTest.php new file mode 100644 index 00000000..17356c92 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Action/IndexTest.php @@ -0,0 +1,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); + } + +} |