folderweb/devel/tests/hooks/hooks_add_apply.phpt
Ruben 449e6f8e03 Update framework testing infrastructure and standards
- Add phpt test runner and suite for app functions
- Introduce testing workflow to AGENT.md
- Add tests for cache, content, context, helpers, hooks, plugins,
  rendering
- Mount tests directory in dev container
2026-03-17 12:51:07 +01:00

38 lines
1 KiB
PHP

--TEST--
Hooks: apply passes value through, add registers filters that chain in order
--FILE--
<?php
require '/var/www/app/hooks.php';
// No filters registered — passthrough
echo Hooks::apply(Hook::PROCESS_CONTENT, 'hello') . "\n";
echo Hooks::apply(Hook::TEMPLATE_VARS, 'foo') . "\n";
// Register a filter
Hooks::add(Hook::PROCESS_CONTENT, fn($v) => strtoupper($v));
echo Hooks::apply(Hook::PROCESS_CONTENT, 'hello') . "\n";
// Filters chain: second receives output of first
Hooks::add(Hook::PROCESS_CONTENT, fn($v) => $v . '!');
echo Hooks::apply(Hook::PROCESS_CONTENT, 'hello') . "\n";
// Other hooks are unaffected
echo Hooks::apply(Hook::TEMPLATE_VARS, 'foo') . "\n";
// Extra args are passed through to each filter
Hooks::add(Hook::TEMPLATE_VARS, fn($v, $extra) => "$v:$extra");
echo Hooks::apply(Hook::TEMPLATE_VARS, 'x', 'ctx') . "\n";
// Non-string values pass through too
$arr = ['a' => 1];
echo Hooks::apply(Hook::CONTEXT_READY, $arr) === $arr ? 'array passthrough' : 'fail';
echo "\n";
?>
--EXPECT--
hello
foo
HELLO
HELLO!
foo
x:ctx
array passthrough