Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21792 Extension.get API - Fix regression (4.7.13) in result filtering #11709

Merged
merged 3 commits into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions api/v3/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,14 @@ function civicrm_api3_extension_get($params) {
$result[] = $info;
}
}
$options = _civicrm_api3_get_options_from_params($params);
$returnFields = !empty($options['return']) ? $options['return'] : array();
if (!in_array('id', $returnFields)) {
$returnFields = array_merge($returnFields, array('id'));
}
return _civicrm_api3_basic_array_get('Extension', $params, $result, 'id', $returnFields);

// These fields have been filtered already, and they have special semantics.
unset($params['key']);
unset($params['keys']);
unset($params['full_name']);

$filterableFields = array('id', 'type', 'status', 'path');
return _civicrm_api3_basic_array_get('Extension', $params, $result, 'id', $filterableFields);
}

/**
Expand Down
22 changes: 21 additions & 1 deletion tests/phpunit/api/v3/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,27 @@ 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']);
$this->assertEquals(6, $result['count']);
$this->assertTrue($result['count'] >= 6);
}

/**
* Filtering by status=installed or status=uninstalled should produce different results.
*/
public function testExtensionGetByStatus() {
$installed = $this->callAPISuccess('extension', 'get', array('status' => 'installed'));
$uninstalled = $this->callAPISuccess('extension', 'get', array('status' => 'uninstalled'));

// If the filter works, then results should be strictly independent.
$this->assertEquals(
array(),
array_intersect(
CRM_Utils_Array::collect('key', $installed['values']),
CRM_Utils_Array::collect('key', $uninstalled['values'])
)
);

$all = $this->callAPISuccess('extension', 'get', array());
$this->assertEquals($all['count'], $installed['count'] + $uninstalled['count']);
}

public function testGetMultipleExtensions() {
Expand Down