Unverified Commit ca13b958 authored by Nicolas Widart's avatar Nicolas Widart Committed by GitHub

Merge pull request #436 from mikemand/2.0

[2.0] Fix settings with falsey values not getting returned
parents 26a9eb70 99f6e46e
......@@ -32,16 +32,16 @@ class Settings implements Setting
$defaultFromConfig = $this->getDefaultFromConfigFor($name);
$setting = $this->setting->findByName($name);
if (! $setting) {
if ($setting === null) {
return is_null($default) ? $defaultFromConfig : $default;
}
if ($setting->isTranslatable) {
if ($setting->hasTranslation($locale)) {
return empty($setting->translate($locale)->value) ? $defaultFromConfig : $setting->translate($locale)->value;
return trim($setting->translate($locale)->value) === '' ? $defaultFromConfig : $setting->translate($locale)->value;
}
} else {
return empty($setting->plainValue) ? $defaultFromConfig : $setting->plainValue;
return trim($setting->plainValue) === '' ? $defaultFromConfig : $setting->plainValue;
}
return $defaultFromConfig;
......
......@@ -57,6 +57,49 @@ class SettingsTest extends BaseSettingTest
$this->assertEquals('AsgardCMS_fr', $setting);
}
/** @test */
public function it_returns_correctly_if_setting_is_falsey()
{
// Prepare
$data = [
'blog::posts-per-page' => 0,
];
// Run
$this->settingRepository->createOrUpdate($data);
// Assert
$setting = $this->setting->get('blog::posts-per-page');
$this->assertEquals(0, $setting);
}
/** @test */
public function it_returns_correctly_if_setting_for_locale_is_falsey()
{
// Prepare
$this->app['config']->set('asgard.block.settings', [
'display-some-feature' => [
'description' => 'block::settings.display-some-feature',
'view' => 'text',
'translatable' => true,
],
]);
$data = [
'block::display-some-feature' => [
'en' => 0,
'fr' => 1,
],
];
// Run
$this->settingRepository->createOrUpdate($data);
// Assert
$this->assertEquals(0, $this->setting->get('block::display-some-feature', 'en'));
$this->assertEquals(1, $this->setting->get('block::display-some-feature', 'fr'));
}
/** @test */
public function it_returns_a_default_value_if_no_setting_found()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment