- Added standard Laravel directory structure and configuration. - Included Svelte and Tailwind configuration for the admin interface. - Added core PHPUnit and testing scripts.
88 lines
2.7 KiB
PHP
88 lines
2.7 KiB
PHP
<?php
|
|
|
|
$content = <<<'EOF'
|
|
<?php
|
|
|
|
namespace Tests\Feature\Admin;
|
|
|
|
use Tests\TestCase;
|
|
use App\Models\User;
|
|
use App\Models\Role;
|
|
use App\Models\Page;
|
|
use Database\Seeders\RoleSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
class PageManagementTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $admin;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->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('<h2>Page Title</h2>', $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);
|