- Added standard Laravel directory structure and configuration. - Included Svelte and Tailwind configuration for the admin interface. - Added core PHPUnit and testing scripts.
154 lines
4.9 KiB
PHP
154 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Admin;
|
|
|
|
use App\Models\User;
|
|
use App\Models\Page;
|
|
use App\Support\PageRenderer;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class AdvancedBlockEditorTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->user = User::factory()->create();
|
|
\App\Models\Media::create([
|
|
'id' => 1,
|
|
'filename' => 'test.jpg',
|
|
'path' => 'public/test.jpg',
|
|
'user_id' => $this->user->id,
|
|
'disk' => 'public',
|
|
'size' => 1024,
|
|
'mime_type' => 'image/jpeg'
|
|
]);
|
|
}
|
|
|
|
/** @test */
|
|
public function it_renders_nested_columns_block()
|
|
{
|
|
$content = [
|
|
'en' => [
|
|
[
|
|
'type' => 'columns',
|
|
'data' => [
|
|
'columns' => [
|
|
[
|
|
'blocks' => [
|
|
['type' => 'heading', 'data' => ['text' => 'Col 1 Heading', 'level' => 2]],
|
|
['type' => 'paragraph', 'data' => ['text' => 'Col 1 Paragraph']]
|
|
]
|
|
],
|
|
[
|
|
'blocks' => [
|
|
['type' => 'paragraph', 'data' => ['text' => 'Col 2 Paragraph']]
|
|
]
|
|
]
|
|
]
|
|
]
|
|
]
|
|
]
|
|
];
|
|
|
|
$page = Page::create([
|
|
'title' => 'Nested Test',
|
|
'slug' => 'nested-test',
|
|
'content' => $content,
|
|
'is_published' => true,
|
|
'user_id' => $this->user->id
|
|
]);
|
|
|
|
$renderer = new PageRenderer();
|
|
$html = $renderer->render($page->content);
|
|
|
|
$this->assertStringContainsString('block-columns columns-2', $html);
|
|
$this->assertStringContainsString('Col 1 Heading', $html);
|
|
$this->assertStringContainsString('Col 1 Paragraph', $html);
|
|
$this->assertStringContainsString('Col 2 Paragraph', $html);
|
|
}
|
|
|
|
/** @test */
|
|
public function it_renders_grid_block()
|
|
{
|
|
$content = [
|
|
'en' => [
|
|
[
|
|
'type' => 'grid',
|
|
'data' => [
|
|
'cols' => 3,
|
|
'items' => [
|
|
['blocks' => [['type' => 'paragraph', 'data' => ['text' => 'Item 1']]]],
|
|
['blocks' => [['type' => 'paragraph', 'data' => ['text' => 'Item 2']]]],
|
|
['blocks' => [['type' => 'paragraph', 'data' => ['text' => 'Item 3']]]]
|
|
]
|
|
]
|
|
]
|
|
]
|
|
];
|
|
|
|
$page = Page::create([
|
|
'title' => 'Grid Test',
|
|
'slug' => 'grid-test',
|
|
'content' => $content,
|
|
'is_published' => true,
|
|
'user_id' => $this->user->id
|
|
]);
|
|
|
|
$renderer = new PageRenderer();
|
|
$html = $renderer->render($page->content);
|
|
|
|
$this->assertStringContainsString('block-grid grid-3', $html);
|
|
$this->assertStringContainsString('Item 1', $html);
|
|
$this->assertStringContainsString('Item 2', $html);
|
|
$this->assertStringContainsString('Item 3', $html);
|
|
}
|
|
|
|
/** @test */
|
|
public function it_renders_media_with_jit_parameters()
|
|
{
|
|
// We can't easily test the actual image generation here without a real file,
|
|
// but we can test that sw_media is called with correct parameters
|
|
// by checking the output URL if we know how sw_media generates it.
|
|
|
|
$content = [
|
|
'en' => [
|
|
[
|
|
'type' => 'media',
|
|
'data' => [
|
|
'media_id' => 1,
|
|
'filename' => 'test.jpg',
|
|
'w' => 500,
|
|
'h' => 300,
|
|
'fit' => 'crop',
|
|
'q' => 50,
|
|
'fp-x' => 0.2,
|
|
'fp-y' => 0.8,
|
|
'alt' => 'JIT Alt'
|
|
]
|
|
]
|
|
]
|
|
];
|
|
|
|
$page = Page::create([
|
|
'title' => 'JIT Test',
|
|
'slug' => 'jit-test',
|
|
'content' => $content,
|
|
'is_published' => true,
|
|
'user_id' => $this->user->id
|
|
]);
|
|
|
|
$renderer = new PageRenderer();
|
|
$html = $renderer->render($page->content);
|
|
|
|
// Check if parameters are in the URL
|
|
$this->assertStringContainsString('w=500', $html);
|
|
$this->assertStringContainsString('h=300', $html);
|
|
$this->assertStringContainsString('fit=crop', $html);
|
|
$this->assertStringContainsString('q=50', $html);
|
|
$this->assertStringContainsString('alt="JIT Alt"', $html);
|
|
}
|
|
}
|