[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/tests_runner/src/ -> lmbTestTreeNode.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  require_once(dirname(__FILE__) . '/lmbTestTreePath.class.php');
  10  
  11  /**

  12   * abstract class lmbTestTreeNode.

  13   *

  14   * @package tests_runner

  15   * @version $Id: lmbTestTreeNode.class.php 6021 2007-06-28 13:18:44Z pachanga $

  16   */
  17  class lmbTestTreeNode
  18  {
  19    protected $parent;
  20    protected $children = array();
  21  
  22    function setParent($parent)
  23    {
  24      $this->parent = $parent;
  25    }
  26  
  27    function getParent()
  28    {
  29      return $this->parent;
  30    }
  31  
  32    function addChild($child)
  33    {
  34      $child->setParent($this);
  35      $this->children[] = $child;
  36    }
  37  
  38    function getChildren()
  39    {
  40      $this->_loadChildren();
  41      return $this->children;
  42    }
  43  
  44    protected function _loadChildren(){}
  45  
  46    function findChildByPath($path)
  47    {
  48      return $this->_traverseArrayPath(lmbTestTreePath :: toArray($path));
  49    }
  50  
  51    protected function _traverseArrayPath($array_path, &$nodes = array())
  52    {
  53      $nodes[] = $this;
  54  
  55      // return itself in case of / path

  56      if(!$array_path)
  57        return $this;
  58  
  59      if(sizeof($array_path) == 1)
  60      {
  61        $child = $this->_getImmediateChildByIndex(array_shift($array_path));
  62        $nodes[] = $child;
  63        return $child;
  64      }
  65  
  66      $index = array_shift($array_path);
  67  
  68      if(!$child = $this->_getImmediateChildByIndex($index))
  69        return null;
  70  
  71      if($child->isTerminal())
  72        return null;
  73  
  74      return $child->_traverseArrayPath($array_path, $nodes);
  75    }
  76  
  77    protected function _getImmediateChildByIndex($index)
  78    {
  79      $children = $this->getChildren();
  80      if(isset($children[$index]))
  81        return $children[$index];
  82    }
  83  
  84    function isSkipped()
  85    {
  86      return false;
  87    }
  88  
  89    function isTerminal()
  90    {
  91      return false;
  92    }
  93  
  94    function init(){}
  95  
  96    function getTestLabel()
  97    {
  98      return $this->_doCreateTestCase()->getLabel();
  99    }
 100  
 101    function createTestCase()
 102    {
 103      $test = $this->_doCreateTestCase();
 104      $children = $this->getChildren();//getter instead of raw property, since child classes may need customization

 105      foreach($children as $child)
 106      {
 107        if($child->isSkipped())
 108          continue;
 109        $child->init();
 110        $test->addTestCase($child->createTestCase());
 111      }
 112      return $test;
 113    }
 114  
 115    protected function _doCreateTestCase()
 116    {
 117      return new TestSuite();
 118    }
 119  }
 120  
 121  ?>


Generated: Tue Dec 2 03:54:09 2008 Cross-referenced by PHPXref 0.7