[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/tree/tests/cases/ -> lmbMPTreeTest.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  lmb_require('limb/tree/src/lmbMPTree.class.php');
  10  lmb_require(dirname(__FILE__) . '/lmbTreeTestBase.class.php');
  11  
  12  
  13  class lmbMPTreeTest extends lmbTreeTestBase
  14  {
  15    protected $node_table = 'test_materialized_path_tree';
  16  
  17    function _createTreeImp()
  18    {
  19      return new lmbMPTree($this->node_table, $this->conn,
  20                           array('id' => 'id', 'parent_id' => 'p_parent_id',
  21                                 'level' => 'p_level', 'identifier' => 'p_identifier',
  22                                 'path' => 'p_path'));
  23    }
  24  
  25    function _cleanUp()
  26    {
  27      $this->db->delete($this->node_table);
  28    }
  29  
  30    function _checkProperNesting($nodes, $line='')
  31    {
  32      $this->assertEqual(lmbArrayHelper :: sortArray($nodes, array('path' => 'ASC')),
  33                         $nodes);
  34  
  35      $path = lmbArrayHelper :: getMinColumnValue('path', $nodes, $index);
  36      $parent_paths[] = $this->_getParentPath($path);
  37  
  38      $counter = 0;
  39      foreach($nodes as $id => $node)
  40      {
  41        $parent_path = $this->_getParentPath($node['path']);
  42  
  43        $this->assertTrue(in_array($parent_path, $parent_paths),
  44          'path is improperly nested: ' . $node['path'] . ' , expected parent not found: ' . $parent_path . ' at line: ' . $line);
  45  
  46        $parent_paths[] = $node['path'];
  47      }
  48    }
  49  
  50    function _getParentPath($path)
  51    {
  52      preg_match('~^(.*/)[^/]+/$~', $path, $matches);
  53      return $matches[1];
  54    }
  55  
  56    function testGetChildrenAllowOtherSort()
  57    {
  58      $root_id = $this->imp->initTree();
  59  
  60      $node_1 = $this->imp->createNode($root_id, array('identifier'=>'node_1'));
  61      $node_2_1 = $this->imp->createNode($node_1, array('identifier'=>'aaaaa'));
  62      $node_2_2 = $this->imp->createNode($node_1, array('identifier'=>'ccccc'));
  63      $node_2_3 = $this->imp->createNode($node_1, array('identifier'=>'bbbb'));
  64  
  65      $rs = $this->imp->getChildren($node_1);
  66      $arr = $rs->sort(array('p_identifier' => 'DESC'))->getArray();
  67  
  68      $this->assertEqual(sizeof($arr ), 3);
  69      $this->assertEqual($arr[0]['id'], $node_2_2);
  70      $this->assertEqual($arr[1]['id'], $node_2_3);
  71      $this->assertEqual($arr[2]['id'], $node_2_1);
  72  
  73      $rs = $this->imp->getChildren($node_1);
  74      $arr = $rs->sort(array('p_identifier' => 'ASC'))->getArray();
  75  
  76      $this->assertEqual($arr[0]['id'], $node_2_1);
  77      $this->assertEqual($arr[1]['id'], $node_2_3);
  78      $this->assertEqual($arr[2]['id'], $node_2_2);
  79    }
  80  }
  81  ?>


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