2023-08-24 22:31:36 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Index\Environment;
|
|
|
|
use Index\XString;
|
|
|
|
use Sasae\SasaeContext;
|
|
|
|
use Sasae\SasaeEnvironment;
|
|
|
|
use Sasae\Cache\SasaeFilesystemCache;
|
|
|
|
use Sasae\Extension\SasaeExtension;
|
|
|
|
use Sasae\Loader\SasaeFilesystemLoader;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers SasaeContext
|
|
|
|
* @covers SasaeEnvironment
|
|
|
|
* @covers SasaeExtension
|
|
|
|
* @covers SasaeFilesystemCache
|
|
|
|
* @covers SasaeFilesystemLoader
|
|
|
|
*/
|
|
|
|
final class SasaeTest extends TestCase {
|
|
|
|
public function testEverything(): void {
|
|
|
|
$env = new SasaeEnvironment(
|
2023-08-24 22:57:41 +00:00
|
|
|
__DIR__,
|
|
|
|
['SasaeTest', XString::random(8)]
|
2023-08-24 22:31:36 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->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);
|
|
|
|
}
|
|
|
|
}
|