seed(RoleSeeder::class);
$this->admin = User::factory()->create();
$this->admin->roles()->attach(Role::where('slug', 'admin')->first());
}
public function test_admin_can_create_a_page(): void
{
$response = $this->actingAs($this->admin)->postJson('/loom/pages', [
'title' => 'Test Page',
'slug' => 'test-page',
'content' => [
['type' => 'heading', 'data' => ['text' => 'Page Title']],
['type' => 'text', 'data' => ['text' => 'Some content here.']]
],
'is_published' => true
]);
$response->assertStatus(201);
$this->assertDatabaseHas('pages', ['slug' => 'test-page']);
$page = Page::where('slug', 'test-page')->first();
$this->assertNotNull($page->cached_html);
$this->assertStringContainsString('
Page Title
', $page->cached_html);
}
public function test_it_blocks_reserved_slugs(): void
{
$response = $this->actingAs($this->admin)->postJson('/loom/pages', [
'title' => 'Admin Page',
'slug' => 'loom',
'content' => [['type' => 'text', 'data' => ['text' => '...']]]
]);
$response->assertStatus(422);
$response->assertJsonValidationErrors(['slug']);
}
public function test_admin_can_update_a_page(): void
{
$page = Page::factory()->create(['user_id' => $this->admin->id, 'content' => []]);
$response = $this->actingAs($this->admin)->putJson("/loom/pages/{$page->id}", [
'title' => 'Updated Title',
'slug' => 'updated-slug',
'content' => [['type' => 'text', 'data' => ['text' => 'Updated content.']]]
]);
$response->assertStatus(200);
$this->assertDatabaseHas('pages', ['title' => 'Updated Title', 'slug' => 'updated-slug']);
}
public function test_admin_can_delete_a_page(): void
{
$page = Page::factory()->create(['user_id' => $this->admin->id, 'content' => []]);
$response = $this->actingAs($this->admin)->deleteJson("/loom/pages/{$page->id}");
$response->assertStatus(204);
$this->assertDatabaseMissing('pages', ['id' => $page->id]);
}
}
EOF;
file_put_contents('tests/Feature/Admin/PageManagementTest.php', $content);