assertFalse($env->isDebug()); $env->addGlobal('global_var', 'Sasae global var'); $env->addGlobal('expect', [ 'ndx_version' => (string)Environment::getIndexVersion(), 'sasae_version' => SasaeEnvironment::getSasaeVersionString(), 'twig_version' => SasaeEnvironment::getTwigVersionString(), ]); $env->addFilter('test_filter', fn($text) => ('filter:' . $text)); $env->addFunction('test_function', fn($text) => ('func:' . $text)); $env->addTest('test_test', fn($text) => $text === 'test'); $rendered = $env->render('test-rendered', [ 'local_var' => 'this var is local', ]); $this->assertEquals(file_get_contents(__DIR__ . '/test-rendered.html'), $rendered); $ctx = $env->load('test-loaded', [ 'context_var' => 'this var is context', 'variant' => 'toString()', ]); $ctx->setVar('simple_set', 'simple set call'); $ctx->setVar('another.context.var.deep', 'applied with fuckery'); $ctx->setVars([ 'context_var2' => 'applied without fuckery', ]); $loaded = $ctx->render([ 'local_var' => 'this var is local', 'variant' => 'render()', ]); $this->assertEquals(file_get_contents(__DIR__ . '/test-loaded-render.html'), $loaded); $this->assertEquals(file_get_contents(__DIR__ . '/test-loaded-string.html'), (string)$ctx); } }