1
0
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:
Tristian Kelly
2024-10-21 10:17:24 -04:00
committed by GitHub
parent ee60a7f8ca
commit 084ae6fceb
3 changed files with 83 additions and 1 deletions

View File

@@ -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()
{