3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test APIv3 civicrm_extension_* functions
15 * @package CiviCRM_APIv3
16 * @subpackage API_Core
20 * Class api_v3_ExtensionTest.
23 class api_v3_ExtensionTest
extends CiviUnitTestCase
{
25 public function setUp(): void
{
26 $url = 'file://' . dirname(dirname(dirname(dirname(__FILE__
)))) . '/mock/extension_browser_results';
27 Civi
::settings()->set('ext_repo_url', $url);
30 public function tearDown(): void
{
31 Civi
::settings()->revert('ext_repo_url');
37 public function testGetremote() {
38 $result = $this->callAPISuccess('extension', 'getremote', []);
39 $this->assertEquals('org.civicrm.module.cividiscount', $result['values'][0]['key']);
40 $this->assertEquals('module', $result['values'][0]['type']);
41 $this->assertEquals('CiviDiscount', $result['values'][0]['name']);
45 * Test getting a single extension
46 * @see https://issues.civicrm.org/jira/browse/CRM-20532
48 public function testExtensionGetSingleExtension() {
49 $result = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.moduletest']);
50 $this->assertEquals('test.extension.manager.moduletest', $result['values'][$result['id']]['key']);
51 $this->assertEquals('module', $result['values'][$result['id']]['type']);
52 $this->assertEquals('test_extension_manager_moduletest', $result['values'][$result['id']]['name']);
56 * Test single Extension get with specific fields in return
57 * @see https://issues.civicrm.org/jira/browse/CRM-20532
59 public function testSingleExtensionGetWithReturnFields() {
60 $result = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.moduletest', 'return' => ['name', 'status', 'key']]);
61 $this->assertEquals('test.extension.manager.moduletest', $result['values'][$result['id']]['key']);
62 $this->assertFalse(isset($result['values'][$result['id']]['type']));
63 $this->assertEquals('test_extension_manager_moduletest', $result['values'][$result['id']]['name']);
64 $this->assertEquals('uninstalled', $result['values'][$result['id']]['status']);
68 * Test Extension Get returns detailed information
69 * Note that this is likely to fail locally but will work on Jenkins due to the result count check
70 * @see https://issues.civicrm.org/jira/browse/CRM-20532
72 public function testExtensionGet() {
73 $result = $this->callAPISuccess('extension', 'get', ['options' => ['limit' => 0]]);
74 $testExtensionResult = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.paymenttest']);
75 $ext = $result['values'][$testExtensionResult['id']];
76 $this->assertNotNull($ext['typeInfo']);
77 $this->assertEquals(['mock'], $ext['tags']);
78 $this->assertTrue($result['count'] >= 6);
82 * Filtering by status=installed or status=uninstalled should produce different results.
84 public function testExtensionGetByStatus() {
85 $installed = $this->callAPISuccess('extension', 'get', ['status' => 'installed', 'options' => ['limit' => 0]]);
86 $uninstalled = $this->callAPISuccess('extension', 'get', ['status' => 'uninstalled', 'options' => ['limit' => 0]]);
88 // If the filter works, then results should be strictly independent.
92 CRM_Utils_Array
::collect('key', $installed['values']),
93 CRM_Utils_Array
::collect('key', $uninstalled['values'])
97 $all = $this->callAPISuccess('extension', 'get', ['options' => ['limit' => 0]]);
98 $this->assertEquals($all['count'], $installed['count'] +
$uninstalled['count']);
101 public function testGetMultipleExtensions() {
102 $result = $this->callAPISuccess('extension', 'get', ['key' => ['test.extension.manager.paymenttest', 'test.extension.manager.moduletest']]);
103 $this->assertEquals(2, $result['count']);
107 * Test that extension get works with api request with parameter full_name as build by api explorer.
109 public function testGetMultipleExtensionsApiExplorer() {
110 $result = $this->callAPISuccess('extension', 'get', ['full_name' => ['test.extension.manager.paymenttest', 'test.extension.manager.moduletest']]);
111 $this->assertEquals(2, $result['count']);
115 * Test that extension get can be filtered by id.
117 public function testGetExtensionByID() {
118 $result = $this->callAPISuccess('extension', 'get', ['id' => 2, 'return' => ['label']]);
119 $this->assertEquals(1, $result['count']);