82 lines
2.3 KiB
PHP
82 lines
2.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
$content = <<<'EOF'
|
||
|
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Unit;
|
||
|
|
|
||
|
|
use Tests\TestCase;
|
||
|
|
use App\Support\PageRenderer;
|
||
|
|
use Illuminate\Support\Facades\View;
|
||
|
|
use Illuminate\Support\Facades\Config;
|
||
|
|
use Illuminate\Support\Facades\File;
|
||
|
|
|
||
|
|
class PageRendererTest extends TestCase
|
||
|
|
{
|
||
|
|
public function test_it_renders_basic_blocks(): void
|
||
|
|
{
|
||
|
|
$renderer = new PageRenderer();
|
||
|
|
$content = [
|
||
|
|
[
|
||
|
|
'type' => 'heading',
|
||
|
|
'data' => ['text' => 'Hello World']
|
||
|
|
],
|
||
|
|
[
|
||
|
|
'type' => 'text',
|
||
|
|
'data' => ['text' => '<p>This is a paragraph.</p>']
|
||
|
|
]
|
||
|
|
];
|
||
|
|
|
||
|
|
$html = $renderer->render($content);
|
||
|
|
|
||
|
|
$this->assertStringContainsString('<h2>Hello World</h2>', $html);
|
||
|
|
$this->assertStringContainsString('<div><p>This is a paragraph.</p></div>', $html);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_it_supports_theme_overrides(): void
|
||
|
|
{
|
||
|
|
// Setup theme blocks directory
|
||
|
|
$themesPath = base_path('themes');
|
||
|
|
if (! File::exists($themesPath)) {
|
||
|
|
File::makeDirectory($themesPath);
|
||
|
|
}
|
||
|
|
$themeBlocksPath = "{$themesPath}/test-theme/blocks";
|
||
|
|
if (! File::exists($themeBlocksPath)) {
|
||
|
|
File::makeDirectory($themeBlocksPath, 0755, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
File::put("{$themeBlocksPath}/heading.blade.php", "<h1 class='theme-title'>{{ \$text }}</h1>");
|
||
|
|
|
||
|
|
// Add theme to view paths
|
||
|
|
View::addNamespace('themes.test-theme', $themesPath . '/test-theme');
|
||
|
|
Config::set('cms.theme', 'test-theme');
|
||
|
|
|
||
|
|
$renderer = new PageRenderer();
|
||
|
|
$content = [
|
||
|
|
['type' => 'heading', 'data' => ['text' => 'Theme Heading']]
|
||
|
|
];
|
||
|
|
|
||
|
|
$html = $renderer->render($content);
|
||
|
|
|
||
|
|
$this->assertStringContainsString("<h1 class='theme-title'>Theme Heading</h1>", $html);
|
||
|
|
|
||
|
|
// Cleanup
|
||
|
|
File::deleteDirectory($themesPath . '/test-theme');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_it_handles_missing_blocks_gracefully(): void
|
||
|
|
{
|
||
|
|
$renderer = new PageRenderer();
|
||
|
|
$content = [
|
||
|
|
['type' => 'unknown', 'data' => []]
|
||
|
|
];
|
||
|
|
|
||
|
|
$html = $renderer->render($content);
|
||
|
|
|
||
|
|
$this->assertStringContainsString('<!-- Block type [unknown] not found -->', $html);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
EOF;
|
||
|
|
|
||
|
|
file_put_contents('tests/Unit/PageRendererTest.php', $content);
|