koel/tests/Integration/Models/SettingTest.php

56 lines
1.2 KiB
PHP
Raw Normal View History

2017-12-09 22:39:34 +00:00
<?php
namespace Tests\Integration\Models;
use App\Models\Setting;
use Tests\TestCase;
class SettingTest extends TestCase
{
public function testSetsKeyValuePair(): void
2017-12-10 00:23:37 +00:00
{
Setting::set('foo', 'bar');
2017-12-09 22:39:34 +00:00
2020-09-06 18:21:39 +00:00
self::assertDatabaseHas('settings', [
2017-12-10 00:23:37 +00:00
'key' => 'foo',
'value' => serialize('bar'),
]);
}
2017-12-09 22:39:34 +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
2020-09-06 18:21:39 +00:00
self::assertDatabaseHas('settings', [
2017-12-10 00:23:37 +00:00
'key' => 'foo',
'value' => serialize('bar'),
])->assertDatabaseHas('settings', [
'key' => 'baz',
'value' => serialize('qux'),
]);
}
2017-12-09 22:39:34 +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
2020-09-06 18:21:39 +00:00
self::assertEquals('baz', Setting::get('foo'));
2017-12-10 00:23:37 +00:00
}
2017-12-09 22:39:34 +00:00
public function testGetSettings(): void
2017-12-10 00:23:37 +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
self::assertSame('bar', Setting::get('foo'));
2017-12-10 00:23:37 +00:00
}
2017-12-09 22:39:34 +00:00
}