Commit | Line | Data |
---|---|---|
ef19fb3f AS |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
ef19fb3f | 5 | | | |
7d61e75f TO |
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 | | |
ef19fb3f AS |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * Test APIv3 civicrm_extension_* functions | |
14 | * | |
15 | * @package CiviCRM_APIv3 | |
16 | * @subpackage API_Core | |
17 | */ | |
18 | ||
19 | /** | |
20 | * Class api_v3_ExtensionTest. | |
21 | * @group headless | |
22 | */ | |
23 | class api_v3_ExtensionTest extends CiviUnitTestCase { | |
24 | ||
25 | public function setUp() { | |
26 | $url = 'file://' . dirname(dirname(dirname(dirname(__FILE__)))) . '/mock/extension_browser_results'; | |
27 | Civi::settings()->set('ext_repo_url', $url); | |
28 | } | |
29 | ||
30 | public function tearDown() { | |
31 | Civi::settings()->revert('ext_repo_url'); | |
32 | } | |
33 | ||
34 | /** | |
35 | * Test getremote. | |
36 | */ | |
37 | public function testGetremote() { | |
9099cab3 | 38 | $result = $this->callAPISuccess('extension', 'getremote', []); |
ef19fb3f AS |
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']); | |
42 | } | |
43 | ||
d4c44c70 | 44 | /** |
9776f417 SL |
45 | * Test getting a single extension |
46 | * CRM-20532 | |
d4c44c70 | 47 | */ |
34239e81 | 48 | public function testExtensionGetSingleExtension() { |
9099cab3 | 49 | $result = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.moduletest']); |
d4c44c70 SL |
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']); | |
53 | } | |
54 | ||
55 | /** | |
9776f417 SL |
56 | * Test single Extension get with specific fields in return |
57 | * CRM-20532 | |
d4c44c70 | 58 | */ |
34239e81 | 59 | public function testSingleExtensionGetWithReturnFields() { |
9099cab3 | 60 | $result = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.moduletest', 'return' => ['name', 'status', 'key']]); |
d4c44c70 | 61 | $this->assertEquals('test.extension.manager.moduletest', $result['values'][$result['id']]['key']); |
9776f417 | 62 | $this->assertFalse(isset($result['values'][$result['id']]['type'])); |
d4c44c70 SL |
63 | $this->assertEquals('test_extension_manager_moduletest', $result['values'][$result['id']]['name']); |
64 | $this->assertEquals('uninstalled', $result['values'][$result['id']]['status']); | |
65 | } | |
66 | ||
67 | /** | |
34239e81 | 68 | * Test Extension Get returns detailed information |
79d5202a | 69 | * Note that this is likely to fail locally but will work on Jenkins due to the result count check |
9776f417 | 70 | * CRM-20532 |
d4c44c70 | 71 | */ |
34239e81 | 72 | public function testExtensionGet() { |
ce28a40a | 73 | $result = $this->callAPISuccess('extension', 'get', ['options' => ['limit' => 0]]); |
9099cab3 | 74 | $testExtensionResult = $this->callAPISuccess('extension', 'get', ['key' => 'test.extension.manager.paymenttest']); |
9bb46670 TO |
75 | $ext = $result['values'][$testExtensionResult['id']]; |
76 | $this->assertNotNull($ext['typeInfo']); | |
77 | $this->assertEquals(['mock'], $ext['tags']); | |
08476511 | 78 | $this->assertTrue($result['count'] >= 6); |
79d5202a SL |
79 | } |
80 | ||
1d470b75 TO |
81 | /** |
82 | * Filtering by status=installed or status=uninstalled should produce different results. | |
83 | */ | |
84 | public function testExtensionGetByStatus() { | |
ce28a40a TO |
85 | $installed = $this->callAPISuccess('extension', 'get', ['status' => 'installed', 'options' => ['limit' => 0]]); |
86 | $uninstalled = $this->callAPISuccess('extension', 'get', ['status' => 'uninstalled', 'options' => ['limit' => 0]]); | |
1d470b75 TO |
87 | |
88 | // If the filter works, then results should be strictly independent. | |
89 | $this->assertEquals( | |
9099cab3 | 90 | [], |
1d470b75 TO |
91 | array_intersect( |
92 | CRM_Utils_Array::collect('key', $installed['values']), | |
93 | CRM_Utils_Array::collect('key', $uninstalled['values']) | |
94 | ) | |
95 | ); | |
96 | ||
ce28a40a | 97 | $all = $this->callAPISuccess('extension', 'get', ['options' => ['limit' => 0]]); |
1d470b75 TO |
98 | $this->assertEquals($all['count'], $installed['count'] + $uninstalled['count']); |
99 | } | |
100 | ||
79d5202a | 101 | public function testGetMultipleExtensions() { |
9099cab3 | 102 | $result = $this->callAPISuccess('extension', 'get', ['key' => ['test.extension.manager.paymenttest', 'test.extension.manager.moduletest']]); |
79d5202a | 103 | $this->assertEquals(2, $result['count']); |
d4c44c70 SL |
104 | } |
105 | ||
df4848b8 TS |
106 | /** |
107 | * Test that extension get works with api request with parameter full_name as build by api explorer. | |
108 | */ | |
109 | public function testGetMultipleExtensionsApiExplorer() { | |
9099cab3 | 110 | $result = $this->callAPISuccess('extension', 'get', ['full_name' => ['test.extension.manager.paymenttest', 'test.extension.manager.moduletest']]); |
df4848b8 TS |
111 | $this->assertEquals(2, $result['count']); |
112 | } | |
113 | ||
34239e81 TS |
114 | /** |
115 | * Test that extension get can be filtered by id. | |
116 | */ | |
117 | public function testGetExtensionByID() { | |
9099cab3 | 118 | $result = $this->callAPISuccess('extension', 'get', ['id' => 2, 'return' => ['label']]); |
34239e81 TS |
119 | $this->assertEquals(1, $result['count']); |
120 | } | |
121 | ||
ef19fb3f | 122 | } |