Skip to content

Commit

Permalink
Updates following review by Eileen including using get_options_from_p…
Browse files Browse the repository at this point in the history
…arams and adding an isset test to the ['key']
  • Loading branch information
seamuslee001 committed May 9, 2017
1 parent d4c44c7 commit 9776f41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions api/v3/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ function _civicrm_api3_extension_refresh_spec(&$fields) {
* API result
*/
function civicrm_api3_extension_get($params) {
$keys = (array) $params['key'];
$keys = isset($params['key']) ? (array) $params['key'] : NULL;
$statuses = CRM_Extension_System::singleton()->getManager()->getStatuses();
$mapper = CRM_Extension_System::singleton()->getMapper();
$result = array();
Expand All @@ -356,7 +356,8 @@ function civicrm_api3_extension_get($params) {
$result[] = $info;
}
}
$returnFields = !empty($params['return']) ? (array) $params['return'] : array();
$options = _civicrm_api3_get_options_from_params($params);
$returnFields = !empty($options['return']) ? $options['return'] : array();
return _civicrm_api3_basic_array_get('Extension', $params, $result, 'id', $returnFields);
}

Expand Down
17 changes: 10 additions & 7 deletions tests/phpunit/api/v3/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,36 @@ public function testGetremote() {
}

/**
* Test retunging a single extension
* Test getting a single extension
* CRM-20532
*/
public function testSingleExtesnionGet() {
public function testExtesnionGetSingleExtension() {
$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
* Test single Extension get with specific fields in return
* CRM-20532
*/
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->assertFalse(isset($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
* CRM-20532
*/
public function testeExtesnionGet() {
public function testExtesnionGet() {
$result = $this->callAPISuccess('extension', 'get', array());
$angularResult = $this->callAPISuccess('extension', 'get', array('key' => 'org.civicrm.angularprofiles'));
$this->assertNotNull($result['values'][$angularResult['id']]['comments']);
$testExtensionResult = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.paymenttest'));
$this->assertNotNull($result['values'][$testExtensionResult['id']]['typeInfo']);
$this->assertEquals(11, $result['count']);
}

Expand Down

0 comments on commit 9776f41

Please sign in to comment.