Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
ca13b958
Unverified
Commit
ca13b958
authored
Nov 16, 2017
by
Nicolas Widart
Committed by
GitHub
Nov 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #436 from mikemand/2.0
[2.0] Fix settings with falsey values not getting returned
parents
26a9eb70
99f6e46e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
3 deletions
+46
-3
Settings.php
Modules/Setting/Support/Settings.php
+3
-3
SettingsTest.php
Modules/Setting/Tests/SettingsTest.php
+43
-0
No files found.
Modules/Setting/Support/Settings.php
View file @
ca13b958
...
...
@@ -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
;
...
...
Modules/Setting/Tests/SettingsTest.php
View file @
ca13b958
...
...
@@ -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
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment