Skip to content

Commit

Permalink
fix(core): elgg_get_plugin_setting() respects defaults for values tha…
Browse files Browse the repository at this point in the history
…t haven't been cached or created.

Fixes #9781
  • Loading branch information
brettp authored and mrclay committed May 6, 2016
1 parent b2bc2b9 commit 1e141d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion engine/classes/ElggPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,9 @@ public function setPriority($priority, $site_guid = null) {
*/
public function getSetting($name, $default = null) {
$values = _elgg_services()->pluginSettingsCache->getAll($this->guid);

if ($values !== null) {
return isset($values[$name]) ? $values[$name] : null;
return isset($values[$name]) ? $values[$name] : $default;
}

$val = $this->$name;
Expand Down
18 changes: 18 additions & 0 deletions engine/tests/ElggCorePluginsAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,22 @@ public function testElggPluginGetID() {

$this->assertIdentical('profile', $test_plugin->getID());
}

public function testGetSettingRespectsDefaults() {
$plugin = elgg_get_plugin_from_id('profile');
if (!$plugin) {
return;
}

$cache = _elgg_services()->pluginSettingsCache;
$cache->setCachedValues([
$plugin->guid => [
__METHOD__ => 'foo',
],
]);

$this->assertEqual('foo', $plugin->getSetting(__METHOD__, 'bar'));
$cache->clearAll();
$this->assertEqual('bar', $plugin->getSetting(__METHOD__, 'bar'));
}
}

0 comments on commit 1e141d4

Please sign in to comment.