/
evo
/
docviz
Обзор
Документация
Войти
/
evo
/
docviz
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
tests/Unit/DocCategoryModelTest.php
80 строк
3 KB
evo
Checkout for tests
08 фев 2026, 09:59
Верифицирован
08 фев 2026, 09:59
ccd7e85
Код
Авторство
О чём код?
<?php namespace Tests\Unit; use App\Models\DocCategory; use App\Models\DocPage; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; class DocCategoryModelTest extends TestCase { use RefreshDatabase; public function test_doc_category_fillable_attributes(): void { $fillable = (new DocCategory())->getFillable(); $this->assertContains('name', $fillable); $this->assertContains('slug', $fillable); $this->assertContains('description', $fillable); $this->assertContains('order', $fillable); $this->assertContains('is_published', $fillable); $this->assertContains('created_by', $fillable); } public function test_doc_category_uses_slug_as_route_key(): void { $category = DocCategory::factory()->create(); $this->assertSame('slug', $category->getRouteKeyName()); } public function test_doc_category_has_pages_relationship(): void { $category = DocCategory::factory()->create(); DocPage::factory()->count(3)->create(['category_id' => $category->id]); $this->assertCount(3, $category->pages); $this->assertInstanceOf(DocPage::class, $category->pages->first()); } public function test_doc_category_published_pages_filters_by_is_published(): void { $category = DocCategory::factory()->create(); DocPage::factory()->count(2)->create(['category_id' => $category->id, 'is_published' => true]); DocPage::factory()->count(2)->create(['category_id' => $category->id, 'is_published' => false]); $this->assertCount(2, $category->publishedPages); } public function test_doc_category_belongs_to_creator(): void { $user = User::factory()->create(); $category = DocCategory::factory()->create(['created_by' => $user->id]); $this->assertInstanceOf(User::class, $category->creator); $this->assertSame($user->id, $category->creator->id); } public function test_doc_category_scope_published(): void { DocCategory::factory()->count(2)->create(['is_published' => true]); DocCategory::factory()->count(3)->create(['is_published' => false]); $this->assertCount(2, DocCategory::published()->get()); } public function test_doc_category_factory_creates_valid_model(): void { $category = DocCategory::factory()->create(); $this->assertDatabaseHas('doc_categories', [ 'id' => $category->id, 'name' => $category->name, 'slug' => $category->slug, 'is_published' => true, ]); } }