53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
use App\Models\Setting;
|
|
|
|
test('setting can store and retrieve a string value', function () {
|
|
Setting::create([
|
|
'group' => 'test',
|
|
'key' => 'string_val',
|
|
'value' => 'hello',
|
|
'type' => 'string',
|
|
]);
|
|
|
|
expect(Setting::getValue('test', 'string_val'))->toBe('hello');
|
|
});
|
|
|
|
test('setting can store and retrieve an integer value', function () {
|
|
Setting::create([
|
|
'group' => 'test',
|
|
'key' => 'int_val',
|
|
'value' => '42',
|
|
'type' => 'integer',
|
|
]);
|
|
|
|
expect(Setting::getValue('test', 'int_val'))->toBe(42);
|
|
});
|
|
|
|
test('setting can store and retrieve a boolean value', function () {
|
|
Setting::create([
|
|
'group' => 'test',
|
|
'key' => 'bool_val',
|
|
'value' => 'true',
|
|
'type' => 'boolean',
|
|
]);
|
|
|
|
expect(Setting::getValue('test', 'bool_val'))->toBeTrue();
|
|
});
|
|
|
|
test('setting returns default when key does not exist', function () {
|
|
expect(Setting::getValue('nonexistent', 'key', 'default'))->toBe('default');
|
|
});
|
|
|
|
test('setting can update value', function () {
|
|
Setting::create([
|
|
'group' => 'test',
|
|
'key' => 'update_val',
|
|
'value' => 'old',
|
|
'type' => 'string',
|
|
]);
|
|
|
|
Setting::setValue('test', 'update_val', 'new');
|
|
|
|
expect(Setting::getValue('test', 'update_val'))->toBe('new');
|
|
});
|