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']); |
9776f417 | 75 | $this->assertNotNull($result['values'][$testExtensionResult['id']]['typeInfo']); |
08476511 | 76 | $this->assertTrue($result['count'] >= 6); |
79d5202a SL |
77 | } |
78 | ||
1d470b75 TO |
79 | /** |
80 | * Filtering by status=installed or status=uninstalled should produce different results. | |
81 | */ | |
82 | public function testExtensionGetByStatus() { | |
ce28a40a TO |
83 | $installed = $this->callAPISuccess('extension', 'get', ['status' => 'installed', 'options' => ['limit' => 0]]); |
84 | $uninstalled = $this->callAPISuccess('extension', 'get', ['status' => 'uninstalled', 'options' => ['limit' => 0]]); | |
1d470b75 TO |
85 | |
86 | // If the filter works, then results should be strictly independent. | |
87 | $this->assertEquals( | |
9099cab3 | 88 | [], |
1d470b75 TO |
89 | array_intersect( |
90 | CRM_Utils_Array::collect('key', $installed['values']), | |
91 | CRM_Utils_Array::collect('key', $uninstalled['values']) | |
92 | ) | |
93 | ); | |
94 | ||
ce28a40a | 95 | $all = $this->callAPISuccess('extension', 'get', ['options' => ['limit' => 0]]); |
1d470b75 TO |
96 | $this->assertEquals($all['count'], $installed['count'] + $uninstalled['count']); |
97 | } | |
98 | ||
79d5202a | 99 | public function testGetMultipleExtensions() { |
9099cab3 | 100 | $result = $this->callAPISuccess('extension', 'get', ['key' => ['test.extension.manager.paymenttest', 'test.extension.manager.moduletest']]); |
79d5202a | 101 | $this->assertEquals(2, $result['count']); |
d4c44c70 SL |
102 | } |
103 | ||
df4848b8 TS |
104 | /** |
105 | * Test that extension get works with api request with parameter full_name as build by api explorer. | |
106 | */ | |
107 | public function testGetMultipleExtensionsApiExplorer() { | |
9099cab3 | 108 | $result = $this->callAPISuccess('extension', 'get', ['full_name' => ['test.extension.manager.paymenttest', 'test.extension.manager.moduletest']]); |
df4848b8 TS |
109 | $this->assertEquals(2, $result['count']); |
110 | } | |
111 | ||
34239e81 TS |
112 | /** |
113 | * Test that extension get can be filtered by id. | |
114 | */ | |
115 | public function testGetExtensionByID() { | |
9099cab3 | 116 | $result = $this->callAPISuccess('extension', 'get', ['id' => 2, 'return' => ['label']]); |
34239e81 TS |
117 | $this->assertEquals(1, $result['count']); |
118 | } | |
119 | ||
ef19fb3f | 120 | } |