Skip to content

Commit

Permalink
CRM-20532 Fix issue where cannot get information on a single extensio…
Browse files Browse the repository at this point in the history
…n with extension.get api and ensure that Fields specified in return key are supported
  • Loading branch information
seamuslee001 committed May 9, 2017
1 parent ab7b706 commit d4c44c7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
13 changes: 11 additions & 2 deletions api/v3/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}

/**
Expand Down
31 changes: 31 additions & 0 deletions tests/phpunit/api/v3/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

}

0 comments on commit d4c44c7

Please sign in to comment.