mirror of
https://github.com/flarum/core.git
synced 2025-08-04 23:47:32 +02:00
feat: allow resetting settings to default (#3935)
Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
@@ -187,6 +187,54 @@ class SettingsTest extends TestCase
|
||||
$this->assertEquals(null, $value);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function resetting_setting_returns_default_value()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Settings())
|
||||
->default('custom-prefix.filter_this_setting', 'extenderDefault')
|
||||
->resetWhen('custom-prefix.filter_this_setting', function (mixed $value): bool {
|
||||
return $value === '';
|
||||
})
|
||||
);
|
||||
|
||||
$this->send(
|
||||
$this->request('POST', '/api/settings', [
|
||||
'authenticatedAs' => 1,
|
||||
'json' => [
|
||||
'custom-prefix.filter_this_setting' => ''
|
||||
]
|
||||
])
|
||||
);
|
||||
|
||||
$value = $this->app()
|
||||
->getContainer()
|
||||
->make('flarum.settings')
|
||||
->get('custom-prefix.filter_this_setting');
|
||||
|
||||
$this->assertEquals('extenderDefault', $value);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function not_resetting_setting_returns_value()
|
||||
{
|
||||
$this->send(
|
||||
$this->request('POST', '/api/settings', [
|
||||
'authenticatedAs' => 1,
|
||||
'json' => [
|
||||
'custom-prefix.filter_this_setting' => ''
|
||||
]
|
||||
])
|
||||
);
|
||||
|
||||
$value = $this->app()
|
||||
->getContainer()
|
||||
->make('flarum.settings')
|
||||
->get('custom-prefix.filter_this_setting');
|
||||
|
||||
$this->assertEquals('', $value);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function custom_less_var_does_not_work_by_default()
|
||||
{
|
||||
|
Reference in New Issue
Block a user