diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/tests/phpunit/Action/IndexTest.php |
first commit
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); + } + +} |