Some checks failed
Deploy Application / deploy (push) Has been cancelled
106 lines
3.5 KiB
PHP
106 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
putenv('APP_DEBUG=true');
|
|
|
|
use App\Framework\View\Dom\Parser\HtmlParser;
|
|
use App\Framework\View\Dom\Transformer\ForTransformer;
|
|
use App\Framework\View\RenderContext;
|
|
use App\Framework\DI\DefaultContainer;
|
|
|
|
echo "=== Testing Navigation Parsing ===\n\n";
|
|
|
|
// Test 1: Parse simple link with placeholder
|
|
echo "Test 1: Parse <a href=\"{{$item['url']}}\">\n";
|
|
$html1 = '<a href="{{' . '$item' . '[\'url\']}}">test</a>';
|
|
$parser = new HtmlParser();
|
|
$doc1 = $parser->parse($html1);
|
|
$body1 = $doc1->getChildren()[0];
|
|
foreach ($body1->getChildren() as $child) {
|
|
if ($child instanceof \App\Framework\View\Dom\ElementNode && $child->getTagName() === 'a') {
|
|
$a1 = $child;
|
|
break;
|
|
}
|
|
}
|
|
if (isset($a1)) {
|
|
$href1 = $a1->getAttribute('href');
|
|
echo " href attribute: [$href1]\n";
|
|
$decoded1 = html_entity_decode($href1, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
|
echo " decoded: [$decoded1]\n";
|
|
echo " contains {{: " . (str_contains($decoded1, '{{') ? 'YES' : 'NO') . "\n\n";
|
|
} else {
|
|
echo " ERROR: Could not find <a> element\n\n";
|
|
}
|
|
|
|
// Test 2: Parse foreach with placeholder
|
|
echo "Test 2: Parse <li foreach=\"\$items as \$item\"><a href=\"{{$item['url']}}\">\n";
|
|
$html2 = '<li foreach="$items as $item"><a href="{{' . '$item' . '[\'url\']}}">test</a></li>';
|
|
$doc2 = $parser->parse($html2);
|
|
$body2 = $doc2->getChildren()[0];
|
|
foreach ($body2->getChildren() as $child) {
|
|
if ($child instanceof \App\Framework\View\Dom\ElementNode && $child->getTagName() === 'li') {
|
|
$li2 = $child;
|
|
break;
|
|
}
|
|
}
|
|
if (isset($li2)) {
|
|
echo " LI foreach: " . ($li2->getAttribute('foreach') ?? 'NULL') . "\n";
|
|
foreach ($li2->getChildren() as $child) {
|
|
if ($child instanceof \App\Framework\View\Dom\ElementNode && $child->getTagName() === 'a') {
|
|
$a2 = $child;
|
|
break;
|
|
}
|
|
}
|
|
if (isset($a2)) {
|
|
$href2 = $a2->getAttribute('href');
|
|
echo " href attribute: [$href2]\n";
|
|
$decoded2 = html_entity_decode($href2, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
|
echo " decoded: [$decoded2]\n";
|
|
echo " contains {{: " . (str_contains($decoded2, '{{') ? 'YES' : 'NO') . "\n\n";
|
|
} else {
|
|
echo " ERROR: Could not find <a> element\n\n";
|
|
}
|
|
} else {
|
|
echo " ERROR: Could not find <li> element\n\n";
|
|
}
|
|
|
|
// Test 3: Test ForTransformer processing
|
|
echo "Test 3: Test ForTransformer with mock data\n";
|
|
$container = new DefaultContainer();
|
|
$transformer = new ForTransformer($container);
|
|
$context = new RenderContext(
|
|
template: 'test',
|
|
metaData: [],
|
|
data: [
|
|
'items' => [
|
|
['url' => '/home', 'name' => 'Home'],
|
|
['url' => '/about', 'name' => 'About'],
|
|
]
|
|
],
|
|
controllerClass: null
|
|
);
|
|
$html3 = '<li foreach="$items as $item"><a href="{{' . '$item' . '[\'url\']}}">test</a></li>';
|
|
$doc3 = $parser->parse($html3);
|
|
$transformer->transform($doc3, $context);
|
|
echo " After transformation:\n";
|
|
$body3 = $doc3->getChildren()[0];
|
|
$children3 = $body3->getChildren();
|
|
echo " Children count: " . count($children3) . "\n";
|
|
foreach ($children3 as $idx => $child) {
|
|
if ($child instanceof \App\Framework\View\Dom\ElementNode) {
|
|
foreach ($child->getChildren() as $grandChild) {
|
|
if ($grandChild instanceof \App\Framework\View\Dom\ElementNode && $grandChild->getTagName() === 'a') {
|
|
$href3 = $grandChild->getAttribute('href');
|
|
echo " Child $idx href: [$href3]\n";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
echo "\n=== Tests Complete ===\n";
|
|
|