-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
837cbdf
commit c679d4b
Showing
9 changed files
with
116 additions
and
15 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 was deleted.
Oops, something went wrong.
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Fixtures\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use LaravelLang\Models\HasTranslations; | ||
|
||
class TestModel extends Model | ||
{ | ||
use HasTranslations; | ||
|
||
protected function translatable(): array | ||
{ | ||
return [ | ||
'title', | ||
]; | ||
} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
function fakeText(?string $locale = null): string | ||
{ | ||
return fake($locale)->words(5, true); | ||
} |
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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Tests\Fixtures\Models\TestModel; | ||
|
||
test('get', function () { | ||
$model = TestModel::create(); | ||
|
||
$locale = config('app.locale'); | ||
$fallback = config('app.fallback_locale'); | ||
|
||
expect($model->title)->toBeNull(); | ||
|
||
expect($model->translation->content->get('title', $locale))->toBeNull(); | ||
expect($model->translation->content->get('title', $fallback))->toBeNull(); | ||
|
||
expect($model->getTranslation('title'))->toBeNull(); | ||
expect($model->getTranslation('title', $locale))->toBeNull(); | ||
expect($model->getTranslation('title', $fallback))->toBeNull(); | ||
}); | ||
|
||
test('set', function () { | ||
$model = TestModel::create(); | ||
|
||
$locale = config('app.locale'); | ||
$fallback = config('app.fallback_locale'); | ||
|
||
$text = fakeText(); | ||
|
||
$model->title = $text; | ||
|
||
expect($model->title)->toBe($text); | ||
|
||
expect($model->translation->content->get('title', $locale))->toBe($text); | ||
expect($model->translation->content->get('title', $fallback))->toBe($text); | ||
|
||
expect($model->getTranslation('title'))->toBe($text); | ||
expect($model->getTranslation('title', $locale))->toBe($text); | ||
expect($model->getTranslation('title', $fallback))->toBe($text); | ||
}); |
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,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
test('', function () {}); |
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,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
test('', function () {}); |
26 changes: 26 additions & 0 deletions
26
tests/database/migrations/2024_06_11_031722_create_test_table.php
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::create('test_models', function (Blueprint $table) { | ||
$table->id(); | ||
|
||
$table->string('key', 255); | ||
|
||
$table->timestamps(); | ||
$table->softDeletes(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists('test_models'); | ||
} | ||
}; |