[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/tests/cases/compiler/tag_node/ -> WactTagInfoExtractorTest.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  require_once('limb/wact/src/compiler/templatecompiler.inc.php');
  11  
  12  class MyStubExtractorTag extends WactCompilerTag
  13  {
  14  }
  15  
  16  class WactTagInfoExtractorTest extends UnitTestCase
  17  {
  18    function testWactTagInfoCreation()
  19    {
  20      WactCompiler :: writeFile($file = WACT_CACHE_DIR . '/tag_extractor_file.tag.php', $context = 'whatever');
  21  
  22      $dictionary = new WactTagDictionary();
  23      $extractor = new WactTagInfoExtractor($dictionary, $file);
  24  
  25      $extractor->annotation('tag', 'my_tag');
  26      $extractor->annotation('suppress_attributes', 'attr1 attr2   attr3');
  27      $extractor->annotation('runat', 'client');
  28      $extractor->annotation('runat_as', 'WactFormTag');
  29      $extractor->annotation('req_const_attributes', 'attr1 attr2');
  30      $extractor->annotation('req_attributes', 'attr3');
  31      $extractor->annotation('parent_tag_class', 'WactFormTag');
  32      $extractor->annotation('restrict_self_nesting', null);
  33      $extractor->annotation('forbid_parsing', null);
  34      $extractor->annotation('forbid_end_tag', null);
  35  
  36      $extractor->beginClass('MyStubExtractorTag', 'CompilerTag');
  37  
  38      $tag_info = $dictionary->getWactTagInfo('my_tag');
  39      $this->assertEqual($tag_info->Tag, 'my_tag');
  40      $this->assertEqual($tag_info->TagClass, 'MyStubExtractorTag');
  41      $this->assertEqual($tag_info->SuppressAttributes, array('attr1', 'attr2', 'attr3'));
  42      $this->assertEqual($tag_info->RequiredAttributes, array('attr3'));
  43      $this->assertEqual($tag_info->RequiredConstantAttributes, array('attr1', 'attr2'));
  44      $this->assertEqual($tag_info->ParentTagClass, 'WactFormTag');
  45      $this->assertEqual($tag_info->RestrictSelfNesting, true);
  46      $this->assertEqual($tag_info->Runat, 'client');
  47      $this->assertEqual($tag_info->RunatAs, 'WactFormTag');
  48      $this->assertEqual($tag_info->ForbidParsing, true);
  49      $this->assertEqual($tag_info->ForbidEndTag, true);
  50      $this->assertEqual($tag_info->File, $file);
  51  
  52      unlink(WACT_CACHE_DIR . '/tag_extractor_file.tag.php');
  53    }
  54  
  55    function testExceptionIfFileNotFound()
  56    {
  57      $file = 'my_file';
  58      $dictionary = new WactTagDictionary();
  59      $extractor = new WactTagInfoExtractor($dictionary, $file);
  60      $extractor->annotation('tag', 'my_tag');
  61      try
  62      {
  63        $extractor->beginClass('MyStubExtractorTag', 'CompilerTag');
  64        $this->assertTrue(false);
  65      }
  66      catch(WactException $e)
  67      {
  68        $this->assertWantedPattern('/File not found/', $e->getMessage());
  69        $this->assertEqual($e->getParam('file'), $file);
  70      }
  71    }
  72  
  73    function testAnnotationTagIsRequired()
  74    {
  75      WactCompiler :: writeFile($file = WACT_CACHE_DIR . '/tag_extractor_file.tag.php', $context = 'whatever');
  76  
  77      $dictionary = new WactTagDictionary();
  78      $extractor = new WactTagInfoExtractor($dictionary, $file);
  79  
  80      try
  81      {
  82        $extractor->beginClass('MyStubExtractorTag', 'CompilerTag');
  83        $this->assertTrue(false);
  84      }
  85      catch(WactException $e)
  86      {
  87        $this->assertWantedPattern('/Annotation not found in file/', $e->getMessage());
  88        $this->assertEqual($e->getParam('file'), $file);
  89        $this->assertEqual($e->getParam('annotation'), 'tag');
  90      }
  91  
  92      unlink(WACT_CACHE_DIR . '/tag_extractor_file.tag.php');
  93    }
  94  
  95    function testAllowRegiserTagAliases()
  96    {
  97      WactCompiler :: writeFile($file = WACT_CACHE_DIR . '/tag_extractor_file.tag.php', $context = 'whatever');
  98  
  99      $dictionary = new WactTagDictionary();
 100      $extractor = new WactTagInfoExtractor($dictionary, $file);
 101  
 102      $extractor->annotation('tag', 'my_tag, my_super_tag');
 103      $extractor->annotation('runat', 'server');
 104  
 105      $extractor->beginClass('MyStubExtractorTag', 'CompilerTag');
 106  
 107      $tag_info1 = $dictionary->getWactTagInfo('my_tag');
 108      $this->assertEqual($tag_info1->Runat, 'server');
 109  
 110      $tag_info2 = $dictionary->getWactTagInfo('my_super_tag');
 111      $this->assertEqual($tag_info2->Runat, 'server');
 112  
 113      unlink(WACT_CACHE_DIR . '/tag_extractor_file.tag.php');
 114    }
 115  }
 116  ?>


Generated: Mon Dec 1 03:56:46 2008 Cross-referenced by PHPXref 0.7