From 34239e81f02dd6bd978f56ed861d70cd01c6fbb7 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Thomas=20Sch=C3=BCttler?= <tschuettler@oxfam.de>
Date: Mon, 31 Jul 2017 12:04:24 +0200
Subject: [PATCH] CRM-20993 - API - Extention get - Fix filtering by ID

----------------------------------------
* CRM-20993: API - Extension get - Cannot filter by ID anymore
  https://issues.civicrm.org/jira/browse/CRM-20993
---
 api/v3/Extension.php                   |  2 +-
 tests/phpunit/api/v3/ExtensionTest.php | 16 ++++++++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/api/v3/Extension.php b/api/v3/Extension.php
index f463dc7895..bb3735ca79 100644
--- a/api/v3/Extension.php
+++ b/api/v3/Extension.php
@@ -359,7 +359,7 @@ function civicrm_api3_extension_get($params) {
     }
   }
   $options = _civicrm_api3_get_options_from_params($params);
-  $returnFields = !empty($options['return']) ? $options['return'] : array();
+  $returnFields = !empty($options['return']) ? $options['return'] : array('id');
   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 ae35540512..2353d156e4 100644
--- a/tests/phpunit/api/v3/ExtensionTest.php
+++ b/tests/phpunit/api/v3/ExtensionTest.php
@@ -61,7 +61,7 @@ class api_v3_ExtensionTest extends CiviUnitTestCase {
    * Test getting a single extension
    * CRM-20532
    */
-  public function testExtesnionGetSingleExtension() {
+  public function testExtensionGetSingleExtension() {
     $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']);
@@ -72,7 +72,7 @@ class api_v3_ExtensionTest extends CiviUnitTestCase {
    * Test single Extension get with specific fields in return
    * CRM-20532
    */
-  public function testSingleExtesnionGetWithReturnFields() {
+  public function testSingleExtensionGetWithReturnFields() {
     $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->assertFalse(isset($result['values'][$result['id']]['type']));
@@ -81,11 +81,11 @@ class api_v3_ExtensionTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test Extension Get resturns detailed information
+   * Test Extension Get returns detailed information
    * Note that this is likely to fail locally but will work on Jenkins due to the result count check
    * CRM-20532
    */
-  public function testExtesnionGet() {
+  public function testExtensionGet() {
     $result = $this->callAPISuccess('extension', 'get', array());
     $testExtensionResult = $this->callAPISuccess('extension', 'get', array('key' => 'test.extension.manager.paymenttest'));
     $this->assertNotNull($result['values'][$testExtensionResult['id']]['typeInfo']);
@@ -105,4 +105,12 @@ class api_v3_ExtensionTest extends CiviUnitTestCase {
     $this->assertEquals(2, $result['count']);
   }
 
+  /**
+   * Test that extension get can be filtered by id.
+   */
+  public function testGetExtensionByID() {
+    $result = $this->callAPISuccess('extension', 'get', array('id' => 2));
+    $this->assertEquals(1, $result['count']);
+  }
+
 }
-- 
2.25.1