Files

59 lines
1.6 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Tests\Feature;
use App\Models\YogaCategory;
use App\Models\YogaPose;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class YogaPoseTest extends TestCase
{
use RefreshDatabase;
public function test_index_lists_poses(): void
{
YogaPose::factory()->count(3)->create();
$response = $this->get(route('yoga.index'));
$response->assertOk();
$response->assertViewHas('poses', function ($poses) {
return $poses->total() === 3;
});
}
public function test_index_can_filter_by_category(): void
{
$core = YogaCategory::factory()->create(['name' => 'Core Yoga']);
$balance = YogaCategory::factory()->create(['name' => 'Balance Yoga']);
$corePose = YogaPose::factory()->create(['category_id' => $core->id]);
YogaPose::factory()->create(['category_id' => $balance->id]);
$response = $this->get(route('yoga.index', ['category' => $core->id]));
$response->assertOk();
$response->assertViewHas('poses', function ($poses) use ($corePose) {
return $poses->total() === 1 && $poses->first()->id === $corePose->id;
});
}
public function test_show_displays_pose(): void
{
$pose = YogaPose::factory()->create(['english_name' => 'Downward Dog']);
$response = $this->get(route('yoga.show', $pose->slug));
$response->assertOk();
$response->assertSee('Downward Dog');
}
public function test_show_returns_404_for_unknown_slug(): void
{
$response = $this->get('/yoga/does-not-exist');
$response->assertNotFound();
}
}