2017-12-09 22:39:34 +00:00
|
|
|
<?php
|
|
|
|
|
2022-07-29 06:47:10 +00:00
|
|
|
namespace Tests\Unit\Models;
|
2017-12-09 22:39:34 +00:00
|
|
|
|
|
|
|
use App\Models\Setting;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class SettingTest extends TestCase
|
|
|
|
{
|
2022-07-07 21:23:41 +00:00
|
|
|
public function testSetKeyValuePair(): void
|
2017-12-10 00:23:37 +00:00
|
|
|
{
|
2020-11-14 16:57:25 +00:00
|
|
|
Setting::set('foo', 'bar');
|
2017-12-09 22:39:34 +00:00
|
|
|
|
2022-07-07 21:23:41 +00:00
|
|
|
self::assertDatabaseHas(Setting::class, [
|
2017-12-10 00:23:37 +00:00
|
|
|
'key' => 'foo',
|
2022-07-07 21:23:41 +00:00
|
|
|
'value' => json_encode('bar'),
|
2017-12-10 00:23:37 +00:00
|
|
|
]);
|
|
|
|
}
|
2017-12-09 22:39:34 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
public function testSupportAssociativeArray(): void
|
2017-12-10 00:23:37 +00:00
|
|
|
{
|
|
|
|
$settings = [
|
|
|
|
'foo' => 'bar',
|
|
|
|
'baz' => 'qux',
|
|
|
|
];
|
2017-12-09 22:39:34 +00:00
|
|
|
|
2017-12-10 00:23:37 +00:00
|
|
|
Setting::set($settings);
|
2017-12-09 22:39:34 +00:00
|
|
|
|
2022-07-07 21:23:41 +00:00
|
|
|
self::assertDatabaseHas(Setting::class, [
|
2017-12-10 00:23:37 +00:00
|
|
|
'key' => 'foo',
|
2022-07-07 21:23:41 +00:00
|
|
|
'value' => json_encode('bar'),
|
|
|
|
])->assertDatabaseHas(Setting::class, [
|
2017-12-10 00:23:37 +00:00
|
|
|
'key' => 'baz',
|
2022-07-07 21:23:41 +00:00
|
|
|
'value' => json_encode('qux'),
|
2017-12-10 00:23:37 +00:00
|
|
|
]);
|
|
|
|
}
|
2017-12-09 22:39:34 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
public function testUpdateSettings(): void
|
2017-12-10 00:23:37 +00:00
|
|
|
{
|
|
|
|
Setting::set('foo', 'bar');
|
|
|
|
Setting::set('foo', 'baz');
|
2017-12-09 22:39:34 +00:00
|
|
|
|
2022-10-07 14:25:44 +00:00
|
|
|
self::assertSame('baz', Setting::get('foo'));
|
2017-12-10 00:23:37 +00:00
|
|
|
}
|
2017-12-09 22:39:34 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
public function testGetSettings(): void
|
2017-12-10 00:23:37 +00:00
|
|
|
{
|
2020-11-14 16:57:25 +00:00
|
|
|
Setting::factory()->create([
|
2017-12-10 00:23:37 +00:00
|
|
|
'key' => 'foo',
|
|
|
|
'value' => 'bar',
|
|
|
|
]);
|
2017-12-09 22:39:34 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
self::assertSame('bar', Setting::get('foo'));
|
2017-12-10 00:23:37 +00:00
|
|
|
}
|
2017-12-09 22:39:34 +00:00
|
|
|
}
|