public function testParse()
 {
     $parser = new ParserTemplateDataSource(new SourceMock('template1.jte'), new SectionParser(), new MarkupParser(new BlockSignatureParser()));
     $data = $parser->getTemplateData('');
     $this->assertArrayHasKey('blocks', $data);
     $this->assertArrayHasKey('head', $data['blocks']);
     $this->assertArrayHasKey('body', $data['blocks']);
     $this->assertArrayHasKey('body_bottom', $data['blocks']);
     $this->assertContains('some php logic;', $data['blocks']['head']['logic']);
     $this->assertContains('<some><markup></markup></some>', $data['blocks']['head']['markup'][0]['value']);
     $this->assertContains('body logic', $data['blocks']['body']['logic']);
     $this->assertContains('body markup', $data['blocks']['body']['markup'][0]['value']);
     $check = false;
     foreach ($data['blocks']['body_bottom']['markup'] as $block) {
         if ($block['type'] == MarkupNodeEnum::NODE_BLOCK && $block['name'] == 'placeholder') {
             $this->assertContains('some text', $block['markup'][0]['value']);
             $this->assertContains('another_placeholder', $block['markup'][1]['name']);
             $check = true;
         }
     }
     if (!$check) {
         $this->assertTrue(false);
     }
     $this->assertArrayHasKey('boot', $data);
     $this->assertContains('$a = true;', $data['boot']);
 }
Ejemplo n.º 2
0
 public function getTemplateData($templateName)
 {
     if ($this->cache->isCacheExists($templateName)) {
         $data = (include $this->cache->getFilePath($templateName));
     } else {
         $data = $this->parser->getTemplateData($templateName);
         $this->cache->save($templateName, '<?php return ' . var_export($data, 1) . ';');
     }
     return $data;
 }
Ejemplo n.º 3
0
 public function testWhitespace()
 {
     $templateParser = new ParserTemplateDataSource(new FileSource(__DIR__ . '/Templates'), new SectionParser(), new MarkupParser(new BlockSignatureParser()));
     $template = new Template('', $templateParser->getTemplateData('whitespace1.jte'));
     $templateFactory = $this->getMock('\\StdClass', ['getTemplate']);
     $templateFactory->expects($this->any())->method('getTemplate')->will($this->returnValue($template));
     $renderer = new Renderer($templateFactory, new EvalLogicProcessor());
     $result = $renderer->render($template, 'test1');
     $this->assertEquals('    hello!', $result);
     $result = $renderer->render($template, 'test2');
     $this->assertEquals("    hello1!\n    hello2!", $result);
     $result = $renderer->render($template, 'test3');
     $this->assertEquals("    hello1!\n    hello2!", $result);
     $result = $renderer->render($template, 'test4');
     $this->assertEquals("        hello1!\n    hello2!\n    hello2!", $result);
     $result = $renderer->render($template, 'test5');
     $this->assertEquals("        hello1!\n    hello2!\n    hello2!", $result);
     $result = $renderer->render($template, 'test6');
     $this->assertEquals("    hello1!\n    hello2!", $result);
     $result = $renderer->render($template, 'test7');
     $this->assertEquals("    hello1!\nhello1!\nhello1!\n    hello2!", $result);
     $result = $renderer->render($template, 'test8');
     $this->assertEquals("    hello1! hello1! hello1!\n    hello2!", $result);
 }