Unverified Commit 21e551b5 authored by Nicolas Widart's avatar Nicolas Widart Committed by GitHub

Merge pull request #435 from mikemand/3.0

[3.0] Fix settings with falsey values not getting returned
parents 84756e94 5aecb48b
......@@ -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 $setting->plainValue === null ? $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