From d4c44c70013fa5f687188ac65585e7f68f06c081 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 9 May 2017 19:58:59 +1000 Subject: [PATCH] CRM-20532 Fix issue where cannot get information on a single extension with extension.get api and ensure that Fields specified in return key are supported --- api/v3/Extension.php | 13 +++++++++-- tests/phpunit/api/v3/ExtensionTest.php | 31 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/api/v3/Extension.php b/api/v3/Extension.php index 367ad7b66d74..672980c420df 100644 --- a/api/v3/Extension.php +++ b/api/v3/Extension.php @@ -332,6 +332,7 @@ function _civicrm_api3_extension_refresh_spec(&$fields) { * API result */ function civicrm_api3_extension_get($params) { + $keys = (array) $params['key']; $statuses = CRM_Extension_System::singleton()->getManager()->getStatuses(); $mapper = CRM_Extension_System::singleton()->getMapper(); $result = array(); @@ -346,9 +347,17 @@ function civicrm_api3_extension_get($params) { } $info = CRM_Extension_System::createExtendedInfo($obj); $info['id'] = $id++; // backward compatibility with indexing scheme - $result[] = $info; + if (!empty($params['key'])) { + if (in_array($key, $keys)) { + $result[] = $info; + } + } + else { + $result[] = $info; + } } - return _civicrm_api3_basic_array_get('Extension', $params, $result, 'id', array()); + $returnFields = !empty($params['return']) ? (array) $params['return'] : array(); + return _civicrm_api3_basic_array_get('Extension', $params, $result, 'id', $returnFields); } /** diff --git a/tests/phpunit/api/v3/ExtensionTest.php b/tests/phpunit/api/v3/ExtensionTest.php index c786e2b0455a..c6be9eed6f7f 100644 --- a/tests/phpunit/api/v3/ExtensionTest.php +++ b/tests/phpunit/api/v3/ExtensionTest.php @@ -57,4 +57,35 @@ public function testGetremote() { $this->assertEquals('CiviDiscount', $result['values'][0]['name']); } + /** + * Test retunging a single extension + */ + public function testSingleExtesnionGet() { + $result = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.moduletest')); + $this->assertEquals('test.extension.manager.moduletest', $result['values'][$result['id']]['key']); + $this->assertEquals('module', $result['values'][$result['id']]['type']); + $this->assertEquals('test_extension_manager_moduletest', $result['values'][$result['id']]['name']); + } + + /** + * Test single get with specific fields in return + */ + public function testSingleExtesnionGetWithReturnFields() { + $result = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.moduletest', 'return' => array('name', 'status', 'key'))); + $this->assertEquals('test.extension.manager.moduletest', $result['values'][$result['id']]['key']); + $this->assertNull($result['values'][$result['id']]['type']); + $this->assertEquals('test_extension_manager_moduletest', $result['values'][$result['id']]['name']); + $this->assertEquals('uninstalled', $result['values'][$result['id']]['status']); + } + + /** + * Test Extension Get resturns detailed information + */ + public function testeExtesnionGet() { + $result = $this->callAPISuccess('extension', 'get', array()); + $angularResult = $this->callAPISuccess('extension', 'get', array('key' => 'org.civicrm.angularprofiles')); + $this->assertNotNull($result['values'][$angularResult['id']]['comments']); + $this->assertEquals(11, $result['count']); + } + }