From 9776f41734ff930a2043c643637dadd0a646a8ae Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 9 May 2017 20:13:20 +1000 Subject: [PATCH] Updates following review by Eileen including using get_options_from_params and adding an isset test to the ['key'] --- api/v3/Extension.php | 5 +++-- tests/phpunit/api/v3/ExtensionTest.php | 17 ++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/api/v3/Extension.php b/api/v3/Extension.php index 672980c420..8ffb723928 100644 --- a/api/v3/Extension.php +++ b/api/v3/Extension.php @@ -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(); @@ -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); } diff --git a/tests/phpunit/api/v3/ExtensionTest.php b/tests/phpunit/api/v3/ExtensionTest.php index c6be9eed6f..cd26011617 100644 --- a/tests/phpunit/api/v3/ExtensionTest.php +++ b/tests/phpunit/api/v3/ExtensionTest.php @@ -58,9 +58,10 @@ class api_v3_ExtensionTest extends CiviUnitTestCase { } /** - * 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']); @@ -68,23 +69,25 @@ class api_v3_ExtensionTest extends CiviUnitTestCase { } /** - * 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']); } -- 2.25.1