first commit

This commit is contained in:
2026-02-04 23:23:42 +07:00
commit ee28ea1a2d
202 changed files with 34797 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
<?php
namespace Tests\Feature;
use App\Models\Article;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CommentControllerTest extends TestCase
{
use RefreshDatabase;
public function test_store_creates_comment()
{
$article = Article::factory()->create();
$payload = [
'author_name' => 'John Doe',
'content' => 'This is a test comment',
];
$response = $this->postJson(route('comments.store', $article), $payload);
$response->assertCreated()
->assertJsonStructure([
'data' => ['id', 'author_name', 'content', 'created_at']
])
->assertJsonFragment([
'author_name' => 'John Doe',
'content' => 'This is a test comment',
]);
$this->assertDatabaseHas('comments', [
'author_name' => 'John Doe',
'content' => 'This is a test comment',
'article_id' => $article->id,
]);
}
public function test_store_requires_author_name_and_content()
{
$article = Article::factory()->create();
$response = $this->postJson(route('comments.store', $article));
$response->assertStatus(422)
->assertJsonValidationErrors(['author_name', 'content']);
}
public function test_store_requires_author_name_and_content_and_returns_custom_messages()
{
$article = Article::factory()->create();
$response = $this->postJson(route('comments.store', $article));
$response->assertStatus(422)
->assertJsonValidationErrors(['author_name', 'content']);
$errors = $response->json('errors');
$this->assertSame('Имя автора обязательно.', $errors['author_name'][0]);
$this->assertSame('Содержание комментария обязательно.', $errors['content'][0]);
}
}