public function testInstall()
 {
     $compiler = new Compiler();
     $templateMacroset = TemplateMacroSet::install($compiler);
     $compilerClass = new ReflectionClass('Latte\\Compiler');
     $compilerProperty = $compilerClass->getProperty('macros');
     $compilerProperty->setAccessible(TRUE);
     $templateMacrosetClass = new ReflectionClass('Latte\\Macros\\MacroSet');
     $templateMacrosetProperty = $templateMacrosetClass->getProperty('macros');
     $templateMacrosetProperty->setAccessible(TRUE);
     $compilerMacros = $compilerProperty->getValue($compiler);
     $templateMacrosetMacros = $templateMacrosetProperty->getValue($templateMacroset);
     $this->assertArrayHasKey('template', $templateMacrosetMacros);
     $this->assertInstanceOf('Nedryse\\Latte\\Macros\\TemplateMacroSet', $templateMacrosetMacros['template'][0][0]);
     $this->assertSame('macroTemplate', $templateMacrosetMacros['template'][0][1]);
     $this->assertNull($templateMacrosetMacros['template'][1]);
     $this->assertNull($templateMacrosetMacros['template'][2]);
     $this->assertArrayHasKey('_', $templateMacrosetMacros);
     $this->assertInstanceOf('Nedryse\\Latte\\Macros\\TemplateMacroSet', $templateMacrosetMacros['_'][0][0]);
     $this->assertSame('macroTranslate', $templateMacrosetMacros['_'][0][1]);
     $this->assertInstanceOf('Nedryse\\Latte\\Macros\\TemplateMacroSet', $templateMacrosetMacros['_'][1][0]);
     $this->assertSame('macroTranslate', $templateMacrosetMacros['_'][0][1]);
     $this->assertNull($templateMacrosetMacros['_'][2]);
     $this->assertArrayHasKey('template', $compilerMacros);
     $this->assertInstanceOf('Nedryse\\Latte\\Macros\\TemplateMacroSet', $compilerMacros['template'][0]);
     $this->assertArrayHasKey('_', $compilerMacros);
     $this->assertInstanceOf('Nedryse\\Latte\\Macros\\TemplateMacroSet', $compilerMacros['_'][0]);
 }
 /**
  * Recursively replace {:placeholder} in template
  * with the content of same-named variable in arguments
  * Missed placeholders are replaced by NULL
  *
  * @param string $template text with {:placeholders}
  * @param array $arguments
  * @return void
  */
 public static function template($template, $arguments = array())
 {
     return preg_replace_callback(self::$regexp, function ($matches) use($arguments) {
         $replacement = isset($arguments[$matches[1]]) ? $arguments[$matches[1]] : NULL;
         return TemplateMacroSet::template($replacement, $arguments);
     }, $template);
 }
 public function testMacroTranslateNotPair()
 {
     $returnValue = '<?php echo Latte\\Runtime\\Filters::escapeHtml(Nedryse\\Latte\\Macros\\TemplateMacroSet::template(call_user_func_array(array($template, \'translate\'), array_merge(array(%node.word), $_args = ((is_array(current($_args = array(\'notempty\'))) === TRUE) ? current($_args) : $_args))), array_merge($template->getParameters(), get_defined_vars(), $_args)), ENT_NOQUOTES) ?>';
     /* @var $macroNodeMock MacroNode */
     $macroNodeMock = $this->getMockBuilder('Latte\\MacroNode')->disableOriginalConstructor()->getMock();
     $macroNodeMock->closing = FALSE;
     $macroNodeMock->args = 'notempty';
     /* @var $phpWriterMock PhpWriter */
     $phpWriterMock = $this->getMockBuilder('Latte\\PhpWriter')->disableOriginalConstructor()->getMock();
     $phpWriterMock->expects($this->once())->method('write')->with($this->equalTo('echo %modify(Nedryse\\Latte\\Macros\\TemplateMacroSet::template(call_user_func_array(array($template, \'translate\'), array_merge(array(%node.word), $_args = ((is_array(current($_args = %node.array)) === TRUE) ? current($_args) : $_args))), array_merge($template->getParameters(), get_defined_vars(), $_args)))'))->will($this->returnValue($returnValue));
     /* @var $compilerMock Compiler */
     $compilerMock = $this->getMock('Latte\\Compiler');
     /* @var $templateMacroSetMock TemplateMacroSet */
     $templateMacroSet = new TemplateMacroSet($compilerMock);
     $this->assertSame($returnValue, $templateMacroSet->macroTranslate($macroNodeMock, $phpWriterMock));
 }
 /**
  * @dataProvider translateDataProvider
  */
 public function testTranslate($translated, $latteTpl, $expected, $arguments)
 {
     $translatorMock = $this->getMockForAbstractClass('Nette\\Localization\\ITranslator');
     $translatorMock->expects($this->any())->method('translate')->will($this->returnValue($translated));
     $latte = new Latte\Engine();
     $latte->addFilter('translate', array($translatorMock, 'translate'));
     $latte->onCompile[] = function ($engine) {
         Nedryse\Latte\Macros\TemplateMacroSet::install($engine->getCompiler());
     };
     $name = tempnam(sys_get_temp_dir(), 'name');
     file_put_contents($name, $latteTpl);
     $this->assertSame($expected, $latte->renderToString($name, $arguments));
     unlink($name);
 }