[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/tests/cases/compiler/compile_tree_node/ -> WactCompileTreeNodeTest.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  require_once('limb/wact/src/WactTemplate.class.php');
  12  
  13  Mock::generate('WactCompileTreeNode', 'MockWactCompileTreeNode');
  14  Mock::generate('WactCodeWriter', 'MockWactCodeWriter');
  15  
  16  if(!class_exists('WactCompileTreeNodeTest'))
  17  {
  18  
  19  class WactCompileTreeNodeTest extends UnitTestCase
  20  {
  21    protected $component;
  22  
  23    function setUp()
  24    {
  25      $this->component = $this->_createNode();
  26    }
  27  
  28    protected function _createNode()
  29    {
  30      return new WactCompileTreeNode(new WactSourceLocation('my_file', 10));
  31    }
  32  
  33    function testGetServerIdAttribute()
  34    {
  35      $this->component->ServerId = 'Test';
  36      $this->assertEqual($this->component->getServerId(), 'Test');
  37    }
  38  
  39    function testGetServerIdGenerated()
  40    {
  41      $id = $this->component->getServerId();
  42      $this->assertEqual($this->component->getServerId(), $id);
  43    }
  44  
  45    function testFindChild()
  46    {
  47      $mock = new MockWactCompileTreeNode();
  48      $mock->setReturnValue('getServerId', 'Test');
  49      $this->component->addChild($mock);
  50      $this->assertIsA($this->component->findChild('Test'), 'MockWactCompileTreeNode');
  51    }
  52  
  53    function testFindChildNotFound()
  54    {
  55      $this->assertFalse($this->component->findChild('Test'));
  56    }
  57  
  58    function testFindChildByClass()
  59    {
  60      $mock = new MockWactCompileTreeNode();
  61      $this->component->addChild($mock);
  62      $this->assertIsA($this->component->findChildByClass('MockWactCompileTreeNode'), 'MockWactCompileTreeNode');
  63    }
  64  
  65    function testFindChildByClassNotFound()
  66    {
  67      $this->assertFalse($this->component->findChildByClass('MockWactCompileTreeNode'));
  68    }
  69  
  70    function testFindUpChild()
  71    {
  72      $child1 = new WactCompileTreeNode();
  73      $child1->ServerId = 'child1';
  74  
  75      $child2 = new WactCompileTreeNode();
  76      $child2->ServerId = 'child2';
  77  
  78      $parent1 = new WactCompileTreeNode();
  79      $parent1->ServerId = 'parent1';
  80      $parent1->addChild($child1);
  81  
  82      $parent2 = new WactCompileTreeNode();
  83      $parent2->ServerId = 'parent2';
  84      $parent2->addChild($child2);
  85  
  86      $this->component->addChild($parent1);
  87      $this->component->addChild($parent2);
  88  
  89      $this->assertReference($parent2->findUpChild('child1'), $child1);
  90    }
  91  
  92    function testFindParentByChilld()
  93    {
  94      $parent = new WactCompileTreeNode();
  95      $parent->addChild($this->component);
  96      $this->assertIsA($this->component->findParentByClass('WactCompileTreeNode'), 'WactCompileTreeNode');
  97    }
  98  
  99    function testFindParentByClassNotFound()
 100    {
 101      $this->assertFalse($this->component->findParentByClass('Test'));
 102    }
 103  
 104    function testRemoveChild()
 105    {
 106      $mock = new MockWactCompileTreeNode();
 107      $mock->setReturnValue('getServerId', 'Test');
 108      $this->component->addChild($mock);
 109      $this->assertIsA($this->component->removeChild('Test'), 'MockWactCompileTreeNode');
 110    }
 111  
 112    function testGetChildren()
 113    {
 114      $mock = new MockWactCompileTreeNode();
 115      $this->component->addChild($mock);
 116      $children = $this->component->getChildren();
 117      $this->assertReference($mock, $children[0]);
 118    }
 119  
 120    function testPrepare()
 121    {
 122      $child = new MockWactCompileTreeNode();
 123      $this->component->addChild($child);
 124      $child->expectCallCount('prepare', 1);
 125      $this->component->prepare();
 126    }
 127  
 128    function testGetDataSource()
 129    {
 130      $parent = new MockWactCompileTreeNode();
 131      $ds = new WactArrayObject();
 132      $parent->setReturnValue('getDataSource', $ds);
 133      $this->component->parent = $parent;
 134      $this->assertIsA($this->component->getDataSource(), 'WactArrayObject');
 135    }
 136  
 137    function testGetParentDataSource() {
 138        /* This test case is broken

 139        $parent = &new MockWactCompileTreeNode($this);

 140        $ds = new WactArrayObject();

 141        $testparent = new MockWactCompileTreeNode($this);

 142        $testparent->expectCallCount('getDataSource', 1);

 143        $mockds->parent = & $testparent;

 144        $parent->setReturnValue('getDataSource', $ds);

 145        $this->component->parent = & $parent;

 146        */
 147    }
 148  
 149    function testGetRootDataSource()
 150    {
 151      $parent = new MockWactCompileTreeNode();
 152      $parent->parent = NULL;
 153      $this->component->parent = $parent;
 154      $this->assertIsA($this->component->getRootDataSource(), 'MockWactCompileTreeNode');
 155    }
 156  
 157    function testgetComponentRefCode()
 158    {
 159      $parent = new MockWactCompileTreeNode();
 160      $parent->setReturnValue('getComponentRefCode', 'Test');
 161      $this->component->parent = $parent;
 162      $this->assertEqual($this->component->getComponentRefCode(), 'Test');
 163    }
 164  
 165    function testGenerateConstructor()
 166    {
 167      $code_writer = new MockWactCodeWriter();
 168      $child = new MockWactCompileTreeNode();
 169      $child->expectCallCount('generateConstructor', 1);
 170      $this->component->addChild($child);
 171      $this->component->generateConstructor($code_writer);
 172    }
 173  
 174    function testGenerateContent()
 175    {
 176      $code_writer = new MockWactCodeWriter();
 177      $child = new MockWactCompileTreeNode();
 178      $child->expectCallCount('generate', 1);
 179      $this->component->addChild($child);
 180      $this->component->generateContent($code_writer);
 181    }
 182  
 183    function testGenerate()
 184    {
 185      $code_writer = new MockWactCodeWriter();
 186      $child = new MockWactCompileTreeNode();
 187      $child->expectCallCount('generate', 1);
 188      $this->component->addChild($child);
 189      $this->component->generate($code_writer);
 190    }
 191  
 192    function testCheckServerIdsOk()
 193    {
 194      $root = new WactCompileTreeNode();
 195      $child1 = new WactCompileTreeNode();
 196      $child1->ServerId = 'id1';
 197  
 198      $child2 = new WactCompileTreeNode();
 199      $child2->ServerId = 'id2';
 200  
 201      $root->addChild($child1);
 202      $root->addChild($child2);
 203  
 204      $root->checkChildrenServerIds();
 205    }
 206  
 207    function testDuplicateServerIdsError()
 208    {
 209      $root = new WactCompileTreeNode();
 210      $child1 = new WactCompileTreeNode(new WactSourceLocation('my_file', 10));
 211      $child1->ServerId = 'my_tag';
 212      $root->addChild($child1);
 213  
 214      $child2 = new WactCompileTreeNode(new WactSourceLocation('my_file2', 15));
 215      $child2->ServerId = 'my_tag';
 216      $root->addChild($child2);
 217  
 218      try
 219      {
 220        $root->checkChildrenServerIds();
 221        $this->assertTrue(false);
 222      }
 223      catch(WactException $e)
 224      {
 225        $this->assertWantedPattern('/Duplicate "id" attribute/', $e->getMessage());
 226        $params = $e->getParams();
 227        $this->assertEqual($params['file'], 'my_file2');
 228        $this->assertEqual($params['line'], 15);
 229        $this->assertEqual($params['duplicate_component_file'], 'my_file');
 230        $this->assertEqual($params['duplicate_component_line'], 10);
 231      }
 232    }
 233  
 234    function testDuplicateIdIsLegalInDifferentBranches()
 235    {
 236      $root = new WactCompileTreeNode();
 237  
 238      $Branch = new WactCompileTreeNode();
 239      $root->addChild($Branch);
 240  
 241      $child1 = new WactCompileTreeNode();
 242      $child1->ServerId = 'my_tag';
 243      $Branch->addChild($child1);
 244  
 245      $child2 = new MockWactCompileTreeNode();
 246      $child2->ServerId = 'my_tag';
 247      $root->addChild($child2);
 248  
 249      $root->checkChildrenServerIds();
 250    }
 251  }
 252  
 253  }
 254  ?>


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