-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c9a574
commit 29eebf5
Showing
6 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace Justijndepover\Settings\Tests; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
use Justijndepover\Settings\Tests\Models\User; | ||
|
||
class DatabaseSettingsTest extends TestCase | ||
{ | ||
|
@@ -233,4 +234,35 @@ public function it_can_store_locale_settings_and_normal_settings() | |
$setting = DB::table('settings')->where('key', '=', 'name')->where('locale', '=', null)->first(); | ||
$this->assertEquals($setting->value, 'value'); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_store_different_locale_settings() | ||
{ | ||
$this->settings->forLocale('nl')->set('name', 'value'); | ||
$this->settings->forLocale('fr')->set('name', 'value-fr'); | ||
|
||
$setting = DB::table('settings')->where('key', '=', 'name')->where('locale', '=', 'nl')->first(); | ||
$this->assertEquals($setting->value, 'value'); | ||
|
||
$setting = DB::table('settings')->where('key', '=', 'name')->where('locale', '=', 'fr')->first(); | ||
$this->assertEquals($setting->value, 'value-fr'); | ||
} | ||
|
||
/** @test */ | ||
public function it_has_a_working_user_setting_trait() | ||
{ | ||
$this->settings->forUser(1)->set('name', 'value'); | ||
|
||
$setting = DB::table('settings')->where('key', '=', 'name')->where('user_id', '=', 1)->first(); | ||
$this->assertEquals($setting->value, 'value'); | ||
|
||
$user = User::create([ | ||
'name' => 'Foo Bar', | ||
'email' => '[email protected]', | ||
'password' => 'foobar', | ||
]); | ||
|
||
$this->assertEquals($user->settings->get('name'), 'value'); | ||
$this->assertEquals($user->settings()->get('name'), 'value'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Justijndepover\Settings\Tests\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Foundation\Auth\User as Authenticatable; | ||
use Illuminate\Notifications\Notifiable; | ||
use Justijndepover\Settings\Concerns\HasSettings; | ||
|
||
class User extends Authenticatable | ||
{ | ||
use HasFactory, Notifiable, HasSettings; | ||
|
||
protected $fillable = ['name', 'email', 'password']; | ||
protected $hidden = ['password', 'remember_token']; | ||
|
||
protected $casts = [ | ||
'email_verified_at' => 'datetime', | ||
]; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateUsersTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('users', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('name'); | ||
$table->string('email')->unique(); | ||
$table->timestamp('email_verified_at')->nullable(); | ||
$table->string('password'); | ||
$table->rememberToken(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('users'); | ||
} | ||
} |