97 lines
3.0 KiB
PHP
97 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\GameAccountUser;
|
|
use App\Models\News;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Tests\TestCase;
|
|
|
|
class AdminNewsFeatureTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_admin_can_open_news_page_through_inertia(): void
|
|
{
|
|
News::query()->create([
|
|
'title' => 'MoonWell Update',
|
|
'body' => 'Подробности обновления.',
|
|
'sort_order' => 5,
|
|
'is_published' => true,
|
|
'created_by_username' => 'ADMIN',
|
|
]);
|
|
|
|
$this->actingAs($this->admin())
|
|
->get(route('admin.news.index'))
|
|
->assertOk()
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->component('Admin/News', false)
|
|
->where('newsItems.0.title', 'MoonWell Update')
|
|
->where('newsItems.0.is_published', true)
|
|
->where('newsStats.published', 1)
|
|
->where('storeUrl', route('admin.news.store'))
|
|
->etc()
|
|
);
|
|
}
|
|
|
|
public function test_regular_player_cannot_open_news_admin(): void
|
|
{
|
|
$this->actingAs($this->admin(0))
|
|
->get(route('admin.news.index'))
|
|
->assertForbidden();
|
|
}
|
|
|
|
public function test_admin_can_create_and_update_news_without_an_image(): void
|
|
{
|
|
$admin = $this->admin();
|
|
|
|
$this->actingAs($admin)
|
|
->post(route('admin.news.store'), [
|
|
'title' => 'Новая глава MoonWell',
|
|
'body' => 'Подробности новой главы.',
|
|
'sort_order' => 10,
|
|
'is_published' => true,
|
|
])
|
|
->assertSessionHas('status', 'Новость добавлена.');
|
|
|
|
$newsItem = News::query()->firstOrFail();
|
|
|
|
$this->assertSame('Новая глава MoonWell', $newsItem->title);
|
|
$this->assertTrue($newsItem->is_published);
|
|
$this->assertSame('ADMIN', $newsItem->created_by_username);
|
|
|
|
$this->actingAs($admin)
|
|
->patch(route('admin.news.update', $newsItem), [
|
|
'title' => 'Новая глава уже доступна',
|
|
'body' => 'Обновлённые подробности.',
|
|
'sort_order' => 5,
|
|
'is_published' => false,
|
|
])
|
|
->assertSessionHas('status', 'Новость обновлена.');
|
|
|
|
$this->assertDatabaseHas('news', [
|
|
'id' => $newsItem->id,
|
|
'title' => 'Новая глава уже доступна',
|
|
'sort_order' => 5,
|
|
'is_published' => false,
|
|
]);
|
|
}
|
|
|
|
private function admin(int $gmLevel = 3): GameAccountUser
|
|
{
|
|
return new GameAccountUser(
|
|
1,
|
|
'ADMIN',
|
|
'ADMIN@EXAMPLE.COM',
|
|
'ADMIN@EXAMPLE.COM',
|
|
$gmLevel,
|
|
false,
|
|
null,
|
|
null,
|
|
str_repeat('AA', 32),
|
|
str_repeat('BB', 32),
|
|
);
|
|
}
|
|
}
|