2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
2015-12-13 04:42:28 +00:00
|
|
|
use App\Models\Setting;
|
2016-05-30 05:52:02 +00:00
|
|
|
use App\Models\User;
|
2015-12-13 04:42:28 +00:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2016-05-27 09:07:52 +00:00
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
2017-02-14 06:53:02 +00:00
|
|
|
use Media;
|
|
|
|
use Tests\BrowserKitTestCase;
|
2015-12-13 04:42:28 +00:00
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
class SettingTest extends BrowserKitTestCase
|
2015-12-13 04:42:28 +00:00
|
|
|
{
|
2016-05-27 09:07:52 +00:00
|
|
|
use DatabaseTransactions, WithoutMiddleware;
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
|
|
public function testSetSingleKeyValue()
|
|
|
|
{
|
|
|
|
Setting::set('foo', 'bar');
|
|
|
|
|
|
|
|
$this->seeInDatabase('settings', ['key' => 'foo', 'value' => 's:3:"bar";']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetMultipleKeyValue()
|
|
|
|
{
|
|
|
|
Setting::set([
|
|
|
|
'foo' => 'bar',
|
|
|
|
'baz' => 'qux',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->seeInDatabase('settings', ['key' => 'foo', 'value' => 's:3:"bar";']);
|
|
|
|
$this->seeInDatabase('settings', ['key' => 'baz', 'value' => 's:3:"qux";']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExistingShouldBeUpdated()
|
|
|
|
{
|
|
|
|
Setting::set('foo', 'bar');
|
|
|
|
Setting::set('foo', 'baz');
|
|
|
|
|
|
|
|
$this->assertEquals('baz', Setting::get('foo'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGet()
|
|
|
|
{
|
|
|
|
Setting::set('foo', 'bar');
|
|
|
|
Setting::set('bar', ['baz' => 'qux']);
|
|
|
|
|
|
|
|
$this->assertEquals('bar', Setting::get('foo'));
|
|
|
|
$this->assertEquals(['baz' => 'qux'], Setting::get('bar'));
|
|
|
|
}
|
2016-05-27 09:07:52 +00:00
|
|
|
|
|
|
|
public function testApplicationSetting()
|
|
|
|
{
|
|
|
|
Media::shouldReceive('sync')->once();
|
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
$user = factory(User::class, 'admin')->create();
|
|
|
|
$this->postAsUser('/api/settings', ['media_path' => __DIR__], $user)
|
2016-05-27 09:07:52 +00:00
|
|
|
->seeStatusCode(200);
|
|
|
|
|
2016-11-24 04:07:57 +00:00
|
|
|
$this->assertEquals(__DIR__, Setting::get('media_path'));
|
2016-05-27 09:07:52 +00:00
|
|
|
}
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|