applicant-site/tests/Feature/admin/FeedbackStatusTest.php

93 lines
2.6 KiB
PHP
Raw Normal View History

2024-04-23 14:23:21 +03:00
<?php
namespace Tests\Feature\admin;
use App\Models\FeedbackStatus;
use App\Models\News;
use App\Models\User;
use Illuminate\Http\UploadedFile;
use Tests\TestCase;
class FeedbackStatusTest extends TestCase
{
private User $user;
private FeedbackStatus $status;
private array $data;
protected function setUp(): void
{
parent::setUp();
$this->status = FeedbackStatus::factory()->create();
$this->data = FeedbackStatus::factory()->make()->only([
'name',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexFeedbackStatusPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('feedback_statuses.index'));
$response->assertOk();
}
public function testCreateFeedbackStatusPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('feedback_statuses.create'));
$response->assertOk();
}
public function testStoreFeedbackStatus(): void
{
$file = UploadedFile::fake()->create('fake.jpg', 100);
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('feedback_statuses.store'), $this->data);
$response->assertRedirect(route('feedback_statuses.index'));
$this->assertDatabaseHas('feedback_statuses', $this->data);
}
public function testEditFeedbackStatusPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('feedback_statuses.edit', $this->status));
$response->assertOk();
}
public function testUpdateFeedbackStatus(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('feedback_statuses.update', $this->status), $this->data);
$response->assertRedirect(route('feedback_statuses.index'));
$this->assertDatabaseHas('feedback_statuses', $this->data);
}
public function testDestroyFeedbackStatus(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('feedback_statuses.destroy', $this->status));
$response->assertRedirect(route('feedback_statuses.index'));
$this->assertDatabaseMissing('feedback_statuses', $this->status->toArray());
}
}