Files
plugi/plugi-core/tests/extensions-html-blocks.php
deepDiverPaul 515e4cac1f feat(ext-tracking): Add tracking extension for HTML/JS snippets
Adds a new extension allowing injection of custom code into the page head. Includes an admin interface for saving snippets, secure save routes with CSRF protection, and tests verifying the functionality. Also updates core Extensions.php to support callable HTML blocks for lazy evaluation.
2026-11-30 22:51:03 +01:00

25 lines
969 B
PHP

<?php
use Plugi\Extensions;
require_once __DIR__ . '/../src/Extensions.php';
$callbackValue = '<script>window.tracking = "first";</script>';
Extensions::registerHtmlBlock('<meta name="static" content="unchanged">', 'head');
Extensions::registerHtmlBlock(static function () use (&$callbackValue): string {
return $callbackValue;
}, 'head');
$expected = '<meta name="static" content="unchanged">' . $callbackValue;
if (Extensions::getHtmlBlocks('head') !== $expected) {
throw new RuntimeException('Static and callback HTML blocks should render in registration order.');
}
$callbackValue = '<script>window.tracking = "updated";</script>';
$expected = '<meta name="static" content="unchanged">' . $callbackValue;
if (Extensions::getHtmlBlocks('head') !== $expected) {
throw new RuntimeException('HTML-block callbacks should be evaluated each time their location is retrieved.');
}
fwrite(STDOUT, "PASS: HTML blocks render strings and lazy callbacks.\n");