Permalink
Browse files

fix(core): elgg_get_plugin_setting() respects defaults for values tha…

…t haven't been cached or created.

Fixes #9781
  • Loading branch information...
brettp authored and mrclay committed Apr 29, 2016
1 parent b2bc2b9 commit 1e141d468c75a64bd9068908380e034765772ea6
Showing with 20 additions and 1 deletion.
  1. +2 −1 engine/classes/ElggPlugin.php
  2. +18 −0 engine/tests/ElggCorePluginsAPITest.php
@@ -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;
@@ -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.