/** * @dataProvider parseTagProvider */ public function testLexerTagParsing($cond, $expectedResult) { $provider = new \Webiny\Htpl\TemplateProviders\ArrayProvider(['test' => '<w-if cond="' . $cond . '"></w-if>']); $htpl = new \Webiny\Htpl\Htpl($provider); $result = $htpl->build('test')->getSource(); $this->assertSame($expectedResult . '<?php } ?>', $result); }
public function testLexerTagParsing2() { $provider = new \Webiny\Htpl\TemplateProviders\ArrayProvider(['test' => '<w-else></w-else>']); $htpl = new \Webiny\Htpl\Htpl($provider); $result = $htpl->build('test')->getSource(); $this->assertSame('<?php } else { ?>', $result); }
public function testLexerTagParsing2() { $provider = new \Webiny\Htpl\TemplateProviders\ArrayProvider(['test' => '<w-include file="include.htpl"/>', 'include.htpl' => 'Hello World']); $htpl = new \Webiny\Htpl\Htpl($provider); $result = $htpl->fetch('test'); $this->assertSame('Hello World', $result); }
public function testLexerTagParsingJs() { // htpl instance $tpl = ' <w-minify> <script src="assets/js/skel.min.js"></script> <script src="assets/js/init.js"></script> </w-minify> '; $provider = new \Webiny\Htpl\TemplateProviders\ArrayProvider(['test' => $tpl]); $htpl = new \Webiny\Htpl\Htpl($provider); $htpl->setOptions(['minify' => ['driver' => 'Webiny\\Htpl\\UnitTests\\Mocks\\WMinifyMock']]); $result = $htpl->build('test')->fetch(); $this->assertSame('<script type="text/javascript" src="/mock/min.js"/>', $result); $this->assertSame(['assets/js/skel.min.js', 'assets/js/init.js'], WMinifyMock::$jsFiles); }
public function testWMinifyAbstract() { $tpl = ''; $provider = new \Webiny\Htpl\TemplateProviders\ArrayProvider(['test' => $tpl]); $htpl = new \Webiny\Htpl\Htpl($provider); // register minify providers $minProvider = new \Webiny\Htpl\TemplateProviders\ArrayProvider(['js1.js' => 'var = "foo"; alert(var); ', 'js2.js' => 'var2 = "bar";']); $minCache = new \Webiny\Htpl\Cache\ArrayCache(); $htpl->setOptions(['minify' => ['webRoot' => '/minified/', 'provider' => $minProvider, 'cache' => $minCache]]); $minDriver = new \Webiny\Htpl\Functions\WMinify\WMinify($htpl); $this->assertInstanceOf('\\Webiny\\Htpl\\Htpl', $minDriver->getHtpl()); $this->assertInstanceOf('\\Webiny\\Htpl\\TemplateProviders\\TemplateProviderInterface', $minDriver->getProvider()); $this->assertInstanceOf('\\Webiny\\Htpl\\Cache\\CacheInterface', $minDriver->getCache()); $this->assertSame('/minified/', $minDriver->getWebRoot()); }
<?php $loader = (require __DIR__ . '/../../../vendor/autoload.php'); $loader->add('Webiny\\Htpl\\', __DIR__ . '/../../../src/'); for ($i = 0; $i < 1000; $i++) { // display the template $provider = new \Webiny\Htpl\TemplateProviders\FilesystemProvider([__DIR__ . '/template']); $cache = new \Webiny\Htpl\Cache\FilesystemCache(__DIR__ . '/temp/compiled'); $htpl = new \Webiny\Htpl\Htpl($provider, $cache); $htpl->setForceCompile(false); // assign variables $htpl->assign('entries', include __DIR__ . '/../entries.php'); $htpl->fetch('template.htpl'); }
public function testLexerTagParsingWithKeyNested() { $tpl = '<w-loop items="items" var="var" key="key">'; $tpl .= '<li>'; $tpl .= '{key}=>{var.val}'; $tpl .= '<w-loop items="innerItems" var="iEntry" key="iKey">'; $tpl .= '<span>{key} => {iEntry.name} => {iKey}</span>'; $tpl .= '</w-loop>'; $tpl .= '</li>'; $tpl .= '</w-loop>'; $provider = new \Webiny\Htpl\TemplateProviders\ArrayProvider(['test' => $tpl]); $htpl = new \Webiny\Htpl\Htpl($provider); // source check $data = ['items' => ['A' => ['val' => 'ItemA'], 'B' => ['val' => 'ItemB']], 'innerItems' => ['C' => ['name' => 'ItemC'], 'D' => ['name' => 'ItemD']]]; $expectedResult = '<li>A=>ItemA <span>A => ItemC => C</span><span>A => ItemD => D</span> </li><li>B=>ItemB <span>B => ItemC => C</span><span>B => ItemD => D</span> </li>'; $result = $htpl->build('test', $data)->fetch(); $this->assertSame($expectedResult, trim($result)); }
<?php $loader = (require __DIR__ . '/../../../vendor/autoload.php'); $loader->add('Webiny\\Htpl\\', __DIR__ . '/../../../src/'); //for($i=0;$i<1000; $i++){ // display the template $provider = new \Webiny\Htpl\TemplateProviders\FilesystemProvider([__DIR__ . '/template']); $cache = new \Webiny\Htpl\Cache\FilesystemCache(__DIR__ . '/temp/compiled'); $htpl = new \Webiny\Htpl\Htpl($provider, $cache); $htpl->setForceCompile(false); // assign variables $htpl->assign('arr', include __DIR__ . '/../entries.php'); $htpl->assign('var', 'John Snow'); $htpl->fetch('varTest2.htpl'); //}