mirror of
https://github.com/flarum/core.git
synced 2025-07-30 21:20:24 +02:00
feat: Default Settings Extender (#3127)
Co-authored-by: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>
This commit is contained in:
@@ -163,6 +163,63 @@ class SettingsTest extends TestCase
|
||||
$this->assertArrayHasKey('customPrefix.noCustomSetting', $payload['data']['attributes']);
|
||||
$this->assertEquals('customDefaultModified2', $payload['data']['attributes']['customPrefix.noCustomSetting']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_setting_default_prioritizes_extender()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Settings())
|
||||
->serializeToForum('customPrefix.unavailableCustomSetting3', 'custom-prefix.unavailable_custom_setting3')
|
||||
->default('custom-prefix.unavailable_custom_setting3', 'extenderDefault')
|
||||
);
|
||||
|
||||
$value = $this->app()
|
||||
->getContainer()
|
||||
->make('flarum.settings')
|
||||
->get('custom-prefix.unavailable_custom_setting3', 'defaultParameterValue');
|
||||
|
||||
$this->assertEquals('extenderDefault', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_setting_default_falls_back_to_parameter()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Settings())
|
||||
->serializeToForum('customPrefix.unavailableCustomSetting4', 'custom-prefix.unavailable_custom_setting4')
|
||||
);
|
||||
|
||||
$value = $this->app()
|
||||
->getContainer()
|
||||
->make('flarum.settings')
|
||||
->get('custom-prefix.unavailable_custom_setting4', 'defaultParameterValue');
|
||||
|
||||
$this->assertEquals('defaultParameterValue', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function null_custom_setting_returns_null()
|
||||
{
|
||||
$this->setting('custom-prefix.custom_null_setting', null);
|
||||
|
||||
$this->extend(
|
||||
(new Extend\Settings())
|
||||
->default('custom-prefix.custom_null_setting', 'extenderDefault')
|
||||
);
|
||||
|
||||
$value = $this->app()
|
||||
->getContainer()
|
||||
->make('flarum.settings')
|
||||
->get('custom-prefix.custom_null_setting');
|
||||
|
||||
$this->assertEquals(null, $value);
|
||||
}
|
||||
}
|
||||
|
||||
class CustomInvokableClass
|
||||
|
Reference in New Issue
Block a user