mirror of
https://github.com/flarum/core.git
synced 2025-08-01 22:20:21 +02:00
Add default value to Settings extender (#2495)
This commit is contained in:
@@ -122,6 +122,56 @@ class SettingsTest extends TestCase
|
||||
$this->assertArrayHasKey('customPrefix.customSetting2', $payload['data']['attributes']);
|
||||
$this->assertEquals('customValueModifiedByInvokable', $payload['data']['attributes']['customPrefix.customSetting2']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_setting_falls_back_to_default()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Settings())
|
||||
->serializeToForum('customPrefix.noCustomSetting', 'custom-prefix.no_custom_setting', null, 'customDefault')
|
||||
);
|
||||
|
||||
$this->prepDb();
|
||||
|
||||
$response = $this->send(
|
||||
$this->request('GET', '/api', [
|
||||
'authenticatedAs' => 1,
|
||||
])
|
||||
);
|
||||
|
||||
$payload = json_decode($response->getBody(), true);
|
||||
|
||||
$this->assertArrayHasKey('customPrefix.noCustomSetting', $payload['data']['attributes']);
|
||||
$this->assertEquals('customDefault', $payload['data']['attributes']['customPrefix.noCustomSetting']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_setting_default_passed_to_callback()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Settings())
|
||||
->serializeToForum('customPrefix.noCustomSetting', 'custom-prefix.no_custom_setting', function ($value) {
|
||||
return $value.'Modified2';
|
||||
}, 'customDefault')
|
||||
);
|
||||
|
||||
$this->prepDb();
|
||||
|
||||
$response = $this->send(
|
||||
$this->request('GET', '/api', [
|
||||
'authenticatedAs' => 1,
|
||||
])
|
||||
);
|
||||
|
||||
$payload = json_decode($response->getBody(), true);
|
||||
|
||||
$this->assertArrayHasKey('customPrefix.noCustomSetting', $payload['data']['attributes']);
|
||||
$this->assertEquals('customDefaultModified2', $payload['data']['attributes']['customPrefix.noCustomSetting']);
|
||||
}
|
||||
}
|
||||
|
||||
class CustomInvokableClass
|
||||
|
Reference in New Issue
Block a user