Exemplo n.º 1
0
 static function createByAnnotations($file, $class, $annotations)
 {
     if (!isset($annotations['tag'])) {
         throw new lmbMacroException("@tag annotation is missing for class '{$class}'");
     }
     $tag = $annotations['tag'];
     $info = new lmbMacroTagInfo($tag, $class);
     $info->setFile($file);
     if (isset($annotations['forbid_end_tag'])) {
         $info->setForbidEndtag(true);
     }
     if (isset($annotations['restrict_self_nesting'])) {
         $info->setRestrictSelfNesting(true);
     }
     if (isset($annotations['parent_tag_class'])) {
         $info->setParentClass(trim($annotations['parent_tag_class']));
     }
     if (isset($annotations['req_attributes'])) {
         $req_attributes = explode(',', $annotations['req_attributes']);
         $req_attributes = array_map('trim', $req_attributes);
         $info->setRequiredAttributes($req_attributes);
     }
     if (isset($annotations['aliases'])) {
         $filter_aliases = explode(',', $annotations['aliases']);
         $filter_aliases = array_map('trim', $filter_aliases);
         $info->setAliases($filter_aliases);
     }
     return $info;
 }
    function testLoad()
    {
        $rnd = mt_rand();
        $content1 = <<<EOD
<?php
/**
 * @tag foo_{$rnd}
 */
class Foo{$rnd}Tag extends lmbMacroTag{}
EOD;
        $content2 = <<<EOD
<?php
/**
 * @tag bar_{$rnd}
 */
class Bar{$rnd}Tag extends lmbMacroTag{}
EOD;
        file_put_contents($file1 = LIMB_VAR_DIR . '/tpl/tags/foo_' . $rnd . '.tag.php', $content1);
        file_put_contents($file2 = LIMB_VAR_DIR . '/tpl/tags/subfolder/bar_' . $rnd . '.tag.php', $content2);
        $tag_info1 = new lmbMacroTagInfo("foo_{$rnd}", "Foo{$rnd}Tag");
        $tag_info1->setFile($file1);
        $tag_info2 = new lmbMacroTagInfo("bar_{$rnd}", "Bar{$rnd}Tag");
        $tag_info2->setFile($file2);
        $config = $this->_createMacroConfig();
        $config->tags_scan_dirs = array(LIMB_VAR_DIR . '/tpl/tags/');
        $dictionary = new lmbMacroTagDictionary();
        $dictionary->load($config);
        $this->assertEqual($dictionary->findTagInfo("foo_{$rnd}")->getTag(), $tag_info1->getTag());
        $this->assertEqual($dictionary->findTagInfo("bar_{$rnd}")->getTag(), $tag_info2->getTag());
    }
Exemplo n.º 3
0
 function testRestrictSelfNesting()
 {
     $tag_info = new lmbMacroTagInfo('CompilerTag', 'whatever');
     $tag_info->setRestrictSelfNesting(true);
     $node = new lmbMacroTag(new lmbMacroSourceLocation('my_file', 13), 'whatever', $tag_info);
     $parent = new lmbMacroTag(new lmbMacroSourceLocation('my_file', 10), 'whatEver', $tag_info);
     $node->setParent($parent);
     try {
         $node->preParse(new MockMacroCompiler());
         $this->assertTrue(false);
     } catch (lmbMacroException $e) {
         $this->assertPattern('/Tag cannot be nested within the same tag/', $e->getMessage());
         $this->assertEqual($e->getParam('same_tag_file'), 'my_file');
         $this->assertEqual($e->getParam('same_tag_line'), 10);
     }
 }
        $code->writeHtml('bar');
    }
}
class MacroTagZooTest extends lmbMacroTag
{
    // note that we overrided _generateContent since generate() methods pregenerates dynamic attributes
    function _generateContent($code)
    {
        $code->writePHP('echo ' . $this->getEscaped('attr') . ';');
    }
}
$foo_info = new lmbMacroTagInfo('foo', 'MacroTagFooTest');
$foo_info->setFile(__FILE__);
$bar_info = new lmbMacroTagInfo('bar', 'MacroTagBarTest');
$bar_info->setFile(__FILE__);
$zoo_info = new lmbMacroTagInfo('zoo', 'MacroTagZooTest');
$zoo_info->setFile(__FILE__);
lmbMacroTagDictionary::instance()->register($foo_info);
lmbMacroTagDictionary::instance()->register($bar_info);
lmbMacroTagDictionary::instance()->register($zoo_info);
class lmbMacroTagAcceptanceTest extends lmbBaseMacroTest
{
    function testTemplateRendering()
    {
        $code = '<h1>{{foo/}}{{bar/}}</h1>';
        $tpl = $this->_createMacroTemplate($code, 'tpl.html');
        $out = $tpl->render();
        $this->assertEqual($out, '<h1>foo!bar</h1>');
    }
    function testTagsInsideXmlBlock_WithOtherPhpBlockNearby()
    {