completed story 1.1 with QA tests and fixes
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Post;
|
||||
|
||||
test('post getTitle returns title in specified locale', function () {
|
||||
$post = Post::factory()->create([
|
||||
'title' => ['ar' => 'عنوان عربي', 'en' => 'English Title'],
|
||||
]);
|
||||
|
||||
expect($post->getTitle('ar'))->toBe('عنوان عربي')
|
||||
->and($post->getTitle('en'))->toBe('English Title');
|
||||
});
|
||||
|
||||
test('post getTitle falls back to Arabic when locale missing', function () {
|
||||
$post = Post::factory()->create([
|
||||
'title' => ['ar' => 'عنوان عربي'],
|
||||
]);
|
||||
|
||||
expect($post->getTitle('en'))->toBe('عنوان عربي');
|
||||
});
|
||||
|
||||
test('post getTitle uses current locale by default', function () {
|
||||
$post = Post::factory()->create([
|
||||
'title' => ['ar' => 'عنوان عربي', 'en' => 'English Title'],
|
||||
]);
|
||||
|
||||
app()->setLocale('en');
|
||||
expect($post->getTitle())->toBe('English Title');
|
||||
|
||||
app()->setLocale('ar');
|
||||
expect($post->getTitle())->toBe('عنوان عربي');
|
||||
});
|
||||
|
||||
test('post getBody returns body in specified locale', function () {
|
||||
$post = Post::factory()->create([
|
||||
'body' => ['ar' => 'محتوى عربي', 'en' => 'English Content'],
|
||||
]);
|
||||
|
||||
expect($post->getBody('ar'))->toBe('محتوى عربي')
|
||||
->and($post->getBody('en'))->toBe('English Content');
|
||||
});
|
||||
|
||||
test('post getBody falls back to Arabic when locale missing', function () {
|
||||
$post = Post::factory()->create([
|
||||
'body' => ['ar' => 'محتوى عربي'],
|
||||
]);
|
||||
|
||||
expect($post->getBody('en'))->toBe('محتوى عربي');
|
||||
});
|
||||
Reference in New Issue
Block a user