Author: dr
Date: Mon Aug  6 16:54:30 2007
New Revision: 5822

Log:
- Implemented tree visualization with the ezcTreeVisitorVisualization class.
- Added the fetchParent() and getRootNode() methods.

Added:
    trunk/Tree/src/interfaces/visitable.php   (with props)
    trunk/Tree/src/interfaces/visitor.php   (with props)
    trunk/Tree/src/visitors/
    trunk/Tree/src/visitors/visualization.php   (with props)
    trunk/Tree/tests/visitor.php   (with props)
Modified:
    trunk/Tree/design/class_diagram.png
    trunk/Tree/src/backends/db.php
    trunk/Tree/src/backends/db_nested_set.php
    trunk/Tree/src/backends/db_parent_child.php
    trunk/Tree/src/backends/memory.php
    trunk/Tree/src/backends/xml.php
    trunk/Tree/src/tree.php
    trunk/Tree/src/tree_autoload.php
    trunk/Tree/src/tree_node.php
    trunk/Tree/tests/suite.php
    trunk/Tree/tests/tree.php

Modified: trunk/Tree/design/class_diagram.png
==============================================================================
Binary files - no diff available.

Modified: trunk/Tree/src/backends/db.php
==============================================================================
--- trunk/Tree/src/backends/db.php [iso-8859-1] (original)
+++ trunk/Tree/src/backends/db.php [iso-8859-1] Mon Aug  6 16:54:30 2007
@@ -79,5 +79,70 @@
 
         return count( $s->fetchAll() ) ? true : false;
     }
+
+    /**
+     * Returns the ID of parent of the node with ID $childId
+     *
+     * @param string $childId
+     * @return string
+     */
+    protected function getParentId( $childId )
+    {
+        $db = $this->dbh;
+        $q = $db->createSelectQuery();
+
+        $q->select( 'id, parent_id' )
+          ->from( $db->quoteIdentifier( $this->indexTableName ) )
+          ->where( $q->expr->eq( 'id', $q->bindValue( $childId ) ) );
+
+        $s = $q->prepare();
+        $s->execute();
+        $row = $s->fetch();
+        return $row['parent_id'];
+    }
+
+    /**
+     * Returns the parent node of the node with ID $id.
+     *
+     * This method returns null if there is no parent node.
+     *
+     * @param string $id
+     * @return ezcTreeNode
+     */
+    public function fetchParent( $id )
+    {
+        $className = $this->properties['nodeClassName'];
+        $parentId = $this->getParentId( $id );
+        return $parentId !== NULL ? new $className( $this, $parentId ) : NULL;
+    }
+
+    /**
+     * Returns the root node
+     *
+     * This methods returns null if there is no root node.
+     *
+     * @return ezcTreeNode
+     */
+    public function getRootNode()
+    {
+        $className = $this->properties['nodeClassName'];
+        $db = $this->dbh;
+
+        // SELECT id
+        // FROM indexTable
+        // WHERE id IS null
+        $q = $db->createSelectQuery();
+        $q->select( 'id' )
+          ->from( $db->quoteIdentifier( $this->indexTableName ) )
+          ->where( $q->expr->isNull( 'parent_id' ) );
+        $s = $q->prepare();
+        $s->execute();
+        $r = $s->fetchAll( PDO::FETCH_ASSOC );
+        if ( count( $r ) )
+        {
+            return new $className( $this, $r[0]['id'] );
+        }
+        return null;
+    }
 }
 ?>

Modified: trunk/Tree/src/backends/db_nested_set.php
==============================================================================
--- trunk/Tree/src/backends/db_nested_set.php [iso-8859-1] (original)
+++ trunk/Tree/src/backends/db_nested_set.php [iso-8859-1] Mon Aug  6 16:54:30 
2007
@@ -53,30 +53,6 @@
         return new ezcTreeDbNestedSet( $dbh, $indexTableName, $store );
     }
 
-    /**
-     * Returns the ID of parent of the node with ID $id
-     *
-     * @param string $id
-     * @return string
-     */
-    protected function getParentId( $id )
-    {
-        $db = $this->dbh;
-        $q = $db->createSelectQuery();
-
-        // SELECT id, parent_id
-        // FROM indexTable
-        // WHERE id = $id
-        $q->select( 'id, parent_id' )
-          ->from( $db->quoteIdentifier( $this->indexTableName ) )
-          ->where( $q->expr->eq( 'id', $q->bindValue( $id ) ) );
-
-        $s = $q->prepare();
-        $s->execute();
-        $row = $s->fetch();
-        return $row['parent_id'];
-    }
-
 
     /**
      * Runs SQL to get all the children of the node with ID $nodeId as a PDO

Modified: trunk/Tree/src/backends/db_parent_child.php
==============================================================================
--- trunk/Tree/src/backends/db_parent_child.php [iso-8859-1] (original)
+++ trunk/Tree/src/backends/db_parent_child.php [iso-8859-1] Mon Aug  6 
16:54:30 2007
@@ -52,28 +52,6 @@
     }
 
     /**
-     * Returns the ID of parent of the node with ID $childId
-     *
-     * @param string $childId
-     * @return string
-     */
-    private function getParentId( $childId )
-    {
-        $db = $this->dbh;
-        $q = $db->createSelectQuery();
-
-        $q->select( 'id, parent_id' )
-          ->from( $db->quoteIdentifier( $this->indexTableName ) )
-          ->where( $q->expr->eq( 'id', $q->bindValue( $childId ) ) );
-
-        $s = $q->prepare();
-        $s->execute();
-        $row = $s->fetch();
-        return $row['parent_id'];
-    }
-
-
-    /**
      * Runs SQL to get all the children of the node with ID $nodeId as a PDO
      * result set
      *

Modified: trunk/Tree/src/backends/memory.php
==============================================================================
--- trunk/Tree/src/backends/memory.php [iso-8859-1] (original)
+++ trunk/Tree/src/backends/memory.php [iso-8859-1] Mon Aug  6 16:54:30 2007
@@ -112,6 +112,21 @@
     }
 
     /**
+     * Returns the parent node of the node with ID $id.
+     *
+     * This method returns null if there is no parent node.
+     *
+     * @param string $id
+     * @return ezcTreeNode
+     */
+    public function fetchParent( $id )
+    {
+        $treeNode = $this->getNodeById( $id );
+        $parentNode = $treeNode->parent;
+        return $parentNode !== null ? $parentNode->node : null;
+    }
+
+    /**
      * Returns all the nodes in the path from the root node to the node with ID
      * $id, including those two nodes.
      *
@@ -371,6 +386,22 @@
     }
 
     /**
+     * Returns the root node
+     *
+     * This methods returns null if there is no root node.
+     *
+     * @return ezcTreeNode
+     */
+    public function getRootNode()
+    {
+        if ( $this->rootNode )
+        {
+            return $this->rootNode->node;
+        }
+        return null;
+    }
+
+    /**
      * Adds the node $childNode as child of the node with ID $parentId
      *
      * @param string $parentId
@@ -384,7 +415,7 @@
             return;
         }
 
-        // locate parent node
+        // Locate parent node
         $parentMemoryNode = $this->getNodeById( $parentId );
 
         // Create new node

Modified: trunk/Tree/src/backends/xml.php
==============================================================================
--- trunk/Tree/src/backends/xml.php [iso-8859-1] (original)
+++ trunk/Tree/src/backends/xml.php [iso-8859-1] Mon Aug  6 16:54:30 2007
@@ -185,6 +185,27 @@
     }
 
     /**
+     * Returns the parent node of the node with ID $id.
+     *
+     * This method returns null if there is no parent node.
+     *
+     * @param string $id
+     * @return ezcTreeNode
+     */
+    public function fetchParent( $id )
+    {
+        $className = $this->properties['nodeClassName'];
+        $elem = $this->dom->getElementById( "id$id" );
+        $elem = $elem->parentNode;
+        $parentId = $elem !== null ? substr( $elem->getAttribute( 'id' ), 2 ) 
: null;
+        if ( $parentId === false )
+        {
+            return null;
+        }
+        return new $className( $this, $parentId );
+    }
+
+    /**
      * Returns all the nodes in the path from the root node to the node with ID
      * $id, including those two nodes.
      *
@@ -473,6 +494,29 @@
     }
 
     /**
+     * Returns the root node
+     *
+     * This methods returns null if there is no root node.
+     *
+     * @return ezcTreeNode
+     */
+    public function getRootNode()
+    {
+        $className = $this->properties['nodeClassName'];
+        $document = $this->dom->documentElement;
+
+        foreach ( $document->childNodes as $childNode )
+        {
+            if ( $childNode->nodeType == XML_ELEMENT_NODE && 
$childNode->tagName == 'node' )
+            {
+                $id = substr( $childNode->getAttribute( 'id' ), 2 );
+                return new $className( $this, $id );
+            }
+        }
+        return null;
+    }
+
+    /**
      * Adds the node $childNode as child of the node with ID $parentId
      *
      * @param string $parentId

Added: trunk/Tree/src/interfaces/visitable.php
==============================================================================
--- trunk/Tree/src/interfaces/visitable.php (added)
+++ trunk/Tree/src/interfaces/visitable.php [iso-8859-1] Mon Aug  6 16:54:30 
2007
@@ -1,0 +1,33 @@
+<?php
+/**
+ * File containing the ezcTreeVisitable interface.
+ *
+ * @package Tree
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Interface for visitable tree elements that can be visited
+ * by ezcTreeVisitor implementations for processing using the
+ * Visitor design pattern.
+ *
+ * All elements that will be part of the tree must
+ * implement this interface.
+ *
+ * [EMAIL PROTECTED] http://en.wikipedia.org/wiki/Visitor_pattern Information 
on the Visitor pattern.}
+ *
+ * @package Tree
+ * @version //autogen//
+ */
+interface ezcTreeVisitable
+{
+    /**
+     * Accepts the visitor.
+     *
+     * @param ezcTreeVisitor $visitor
+     */
+    public function accept( ezcTreeVisitor $visitor );
+}
+?>

Propchange: trunk/Tree/src/interfaces/visitable.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/Tree/src/interfaces/visitor.php
==============================================================================
--- trunk/Tree/src/interfaces/visitor.php (added)
+++ trunk/Tree/src/interfaces/visitor.php [iso-8859-1] Mon Aug  6 16:54:30 2007
@@ -1,0 +1,36 @@
+<?php
+/**
+ * File containing the ezcTreeVisitor interface.
+ *
+ * @package Tree
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Interface for visitor implementations that want to process
+ * a tree using the Visitor design pattern.
+ *
+ * visit() is called on each of the nodes in the tree in a top-down,
+ * depth-first fashion.
+ *
+ * Start the processing of the tree by calling accept() on the tree
+ * passing the visitor object as the sole parameter.
+ *
+ * @package Tree
+ * @version //autogen//
+ */
+interface ezcTreeVisitor
+{
+    /**
+     * Visit the $visitable.
+     *
+     * Each node in the graph is visited once.
+     *
+     * @param ezcTreeVisitable $visitable
+     * @return bool
+     */
+    public function visit( ezcTreeVisitable $visitable );
+}
+?>

Propchange: trunk/Tree/src/interfaces/visitor.php
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/Tree/src/tree.php
==============================================================================
--- trunk/Tree/src/tree.php [iso-8859-1] (original)
+++ trunk/Tree/src/tree.php [iso-8859-1] Mon Aug  6 16:54:30 2007
@@ -22,7 +22,7 @@
  * @package Tree
  * @version //autogentag//
  */
-abstract class ezcTree
+abstract class ezcTree implements ezcTreeVisitable
 {
     /**
      * Holds the properties of this class.
@@ -143,6 +143,17 @@
     }
 
     /**
+     * Implements the accept method for visitation
+     *
+     * @param ezcTreeVisitor $visitor
+     */
+    public function accept( ezcTreeVisitor $visitor )
+    {
+        $visitor->visit( $this );
+        $this->getRootNode()->accept( $visitor );
+    }
+
+    /**
      * Returns whether the node with ID $id exists
      *
      * @param string $id
@@ -181,6 +192,14 @@
      * @return ezcTreeNodeList
      */
     abstract public function fetchChildren( $id );
+
+    /**
+     * Returns the parent node of the node with ID $id.
+     *
+     * @param string $id
+     * @return ezcTreeNode
+     */
+    abstract public function fetchParent( $id );
 
     /**
      * Returns all the nodes in the path from the root node to the node with ID
@@ -285,6 +304,13 @@
      * @param ezcTreeNode $node
      */
     abstract public function setRootNode( ezcTreeNode $node );
+
+    /**
+     * Returns the root node
+     *
+     * @return ezcTreenode
+     */
+    abstract public function getRootNode();
 
     /**
      * Adds the node $childNode as child of the node with ID $parentId

Modified: trunk/Tree/src/tree_autoload.php
==============================================================================
--- trunk/Tree/src/tree_autoload.php [iso-8859-1] (original)
+++ trunk/Tree/src/tree_autoload.php [iso-8859-1] Mon Aug  6 16:54:30 2007
@@ -21,6 +21,7 @@
     'ezcTreeDataStore'                          => 
'Tree/interfaces/data_store.php',
     'ezcTreeDb'                                 => 'Tree/backends/db.php',
     'ezcTreeDbDataStore'                        => 'Tree/stores/db.php',
+    'ezcTreeVisitor'                            => 
'Tree/interfaces/visitor.php',
     'ezcTreeXmlDataStore'                       => 'Tree/stores/xml.php',
     'ezcTreeDbExternalTableDataStore'           => 
'Tree/stores/db_external.php',
     'ezcTreeDbNestedSet'                        => 
'Tree/backends/db_nested_set.php',
@@ -32,6 +33,8 @@
     'ezcTreeNodeList'                           => 'Tree/tree_node_list.php',
     'ezcTreeNodeListIterator'                   => 
'Tree/tree_node_list_iterator.php',
     'ezcTreeTransactionItem'                    => 
'Tree/structs/transaction_item.php',
+    'ezcTreeVisitable'                          => 
'Tree/interfaces/visitable.php',
+    'ezcTreeVisitorVisualization'               => 
'Tree/visitors/visualization.php',
     'ezcTreeXml'                                => 'Tree/backends/xml.php',
     'ezcTreeXmlInternalDataStore'               => 
'Tree/stores/xml_internal.php',
 );

Modified: trunk/Tree/src/tree_node.php
==============================================================================
--- trunk/Tree/src/tree_node.php [iso-8859-1] (original)
+++ trunk/Tree/src/tree_node.php [iso-8859-1] Mon Aug  6 16:54:30 2007
@@ -28,7 +28,7 @@
  * @version //autogentag//
  * @mainclass
  */
-class ezcTreeNode
+class ezcTreeNode implements ezcTreeVisitable
 {
     /**
      * Holds the properties of this class.
@@ -140,6 +140,20 @@
     }
 
     /**
+     * Implements the accept method for visitation
+     *
+     * @param ezcTreeVisitor $visitor
+     */
+    public function accept( ezcTreeVisitor $visitor )
+    {
+        $visitor->visit( $this );
+        foreach ( $this->fetchChildren()->getNodes() as $childNode )
+        {
+            $childNode->accept( $visitor );
+        }
+    }
+
+    /**
      * Adds the node $node as child of the current node to the tree
      *
      * @param ezcTreeNode $node
@@ -167,6 +181,17 @@
     public function fetchPath()
     {
         return $this->tree->fetchPath( $this->id );
+    }
+
+    /**
+     * Returns the parent node of this node
+     *
+     * @param string $id
+     * @return ezcTreeNode
+     */
+    public function fetchParent()
+    {
+        return $this->tree->fetchParent( $this->id );
     }
 
     /**

Added: trunk/Tree/src/visitors/visualization.php
==============================================================================
--- trunk/Tree/src/visitors/visualization.php (added)
+++ trunk/Tree/src/visitors/visualization.php [iso-8859-1] Mon Aug  6 16:54:30 
2007
@@ -1,0 +1,111 @@
+<?php
+/**
+ * File containing the ezcTreeVisitorVisualization class.
+ *
+ * @package Tree
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * An implementation of the ezcTreeVisitor interface that
+ * generates GraphViz/dot markup for a tree structure.
+ *
+ * <code>
+ *  $visitor = new ezcTreeVisitorVisualization;
+ *  $tree->accept( $visitor );
+ *  echo (string)$visitor; // print the plot
+ * </code>
+ *
+ * @package Tree
+ * @version //autogen//
+ */
+class ezcTreeVisitorVisualization implements ezcTreeVisitor
+{
+    /**
+     * Holds the displayed strings for each of the nodes.
+     *
+     * @var array(string => string)
+     */
+    protected $nodes = array();
+
+    /**
+     * Holds all the edges of the graph.
+     *
+     * @var array( id => array( ezcTreeNode ) )
+     */
+    protected $edges = array();
+
+    private function createId( ezcTreeNode $node )
+    {
+        return preg_replace( '/[^A-Za-z0-9_]/', '', $node->id ) . '_'. 
base_convert( sprintf( '%u', crc32( $node->id ) ), 16, 36 );
+    }
+
+    /**
+     * Visits the node and sets the the member variables according to the node
+     * type and contents.
+     *
+     * @param ezcTreeVisitable $visitable
+     * @return boolean
+     */
+    public function visit( ezcTreeVisitable $visitable )
+    {
+        if ( $visitable instanceof ezcTree )
+        {
+        }
+
+        if ( $visitable instanceof ezcTreeNode )
+        {
+            $id = $this->createId( $visitable );
+            $this->nodes[$id] = $visitable->id;
+
+            $parent = $visitable->fetchParent();
+            if ( $parent )
+            {
+                $parentId = $this->createId( $parent );
+                $this->edges[$parentId][] = $id;
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Returns a the contents of a graphviz .dot file.
+     *
+     * @return boolean
+     * @ignore
+     */
+    public function __toString()
+    {
+        $dot = "digraph Tree {\n";
+
+        foreach ( $this->nodes as $key => $value )
+        {
+            $dot .= sprintf(
+              "node%s [label=\"%s\"]\n",
+              $key,
+              $value
+            );
+        }
+
+        $dot .= "\n";
+
+        foreach ( $this->edges as $fromNode => $toNodes )
+        {
+            foreach ( $toNodes as $toNode )
+            {
+                $dot .= sprintf(
+                  "node%s -> node%s\n",
+
+                  $fromNode,
+                  $toNode
+                );
+            }
+        }
+
+        return $dot . "}\n";
+    }
+}
+?>

Propchange: trunk/Tree/src/visitors/visualization.php
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/Tree/tests/suite.php
==============================================================================
--- trunk/Tree/tests/suite.php [iso-8859-1] (original)
+++ trunk/Tree/tests/suite.php [iso-8859-1] Mon Aug  6 16:54:30 2007
@@ -15,6 +15,7 @@
 require_once 'tree_node.php';
 require_once 'tree_node_list.php';
 require_once 'tree_node_list_iterator.php';
+require_once 'visitor.php';
 require_once 'memory_tree.php';
 require_once 'xml_tree.php';
 require_once 'db_parent_child_tree.php';
@@ -34,6 +35,7 @@
         $this->addTest( ezcTreeNodeTest::suite() );
         $this->addTest( ezcTreeNodeListTest::suite() );
         $this->addTest( ezcTreeNodeListIteratorTest::suite() );
+        $this->addTest( ezcTreeVisitorTest::suite() );
         $this->addTest( ezcTreeMemoryTest::suite() );
         $this->addTest( ezcTreeXmlTest::suite() );
         $this->addTest( ezcTreeDbParentChildTest::suite() );

Modified: trunk/Tree/tests/tree.php
==============================================================================
--- trunk/Tree/tests/tree.php [iso-8859-1] (original)
+++ trunk/Tree/tests/tree.php [iso-8859-1] Mon Aug  6 16:54:30 2007
@@ -19,6 +19,23 @@
  */
 class ezcTreeTest extends ezcTestCase
 {
+    public function testGetRootNode1()
+    {
+        $tree = $this->setUpTestTree();
+
+        $node = $tree->getRootNode();
+        self::assertType( 'ezcTreeNode', $node );
+        self::assertSame( '1', $node->id );
+        self::assertSame( 'Node 1', $node->data );
+    }
+
+    public function testGetRootNode2()
+    {
+        $tree = $this->setUpEmptyTestTree();
+        $node = $tree->getRootNode();
+        self::assertSame( null, $node );
+    }
+
     public function testTreeFetchById()
     {
         $tree = $this->setUpTestTree();
@@ -464,6 +481,37 @@
         self::assertSame( 2, $nodeList->size );
         self::assertSame( '7', $nodeList['7']->id );
         self::assertSame( '8', $nodeList['8']->id );
+    }
+
+    public function testTreeFetchParentOnNode()
+    {
+        $tree = $this->setUpTestTree();
+
+        $node = $tree->fetchParent( '3' );
+        self::assertType( 'ezcTreeNode', $node );
+        self::assertSame( '1', $node->id );
+        self::assertSame( 'Node 1', $node->data );
+
+        $node = $tree->fetchParent( '1' );
+        self::assertSame( null, $node );
+
+        $node = $tree->fetchParent( '8' );
+        self::assertSame( '6', $node->id );
+    }
+
+    public function testTreeFetchParentOnTree()
+    {
+        $tree = $this->setUpTestTree();
+        $node = $tree->fetchNodeById( '3' )->fetchParent();
+        self::assertType( 'ezcTreeNode', $node );
+        self::assertSame( '1', $node->id );
+        self::assertSame( 'Node 1', $node->data );
+
+        $node = $tree->fetchNodeById( '1' )->fetchParent();
+        self::assertSame( null, $node );
+
+        $node = $tree->fetchNodeById( '8' )->fetchParent();
+        self::assertSame( '6', $node->id );
     }
 
     public function testTreeFetchPathOnNode()

Added: trunk/Tree/tests/visitor.php
==============================================================================
--- trunk/Tree/tests/visitor.php (added)
+++ trunk/Tree/tests/visitor.php [iso-8859-1] Mon Aug  6 16:54:30 2007
@@ -1,0 +1,118 @@
+<?php
+/**
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @version //autogentag//
+ * @filesource
+ * @package Tree
+ * @subpackage Tests
+ */
+
+require_once 'tree.php';
+
+/**
+ * @package Tree
+ * @subpackage Tests
+ */
+class ezcTreeVisitorTest extends ezcTestCase
+{
+    public function setUp()
+    {
+        $this->tree = ezcTreeMemory::create( new ezcTreeMemoryDataStore() );
+    }
+
+    private function addTestData( $tree )
+    {
+        $primates = array(
+            'Hominoidea' => array(
+                'Hylobatidae' => array(
+                    'Hylobates' => array(
+                        'Lar Gibbon',
+                        'Agile Gibbon',
+                        'Müller\'s Bornean Gibbon',
+                        'Silvery Gibbon',
+                        'Pileated Gibbon',
+                        'Kloss\'s Gibbon',
+                    ),
+                    'Hoolock' => array(
+                        'Western Hoolock Gibbon',
+                        'Eastern Hoolock Gibbon',
+                    ),
+                    'Symphalangus' => array(),
+                    'Nomascus' => array(
+                        'Black Crested Gibbon',
+                        'Eastern Black Crested Gibbon',
+                        'White-cheecked Crested Gibbon',
+                        'Yellow-cheecked Gibbon',
+                    ),
+                ),
+                'Hominidae' => array(
+                    'Pongo' => array(
+                        'Bornean Orangutan',
+                        'Sumatran Orangutan',
+                    ), 
+                    'Gorilla' => array(
+                        'Western Gorilla' => array(
+                            'Western Lowland Gorilla',
+                            'Cross River Gorilla',
+                        ),
+                        'Eastern Gorilla' => array(
+                            'Mountain Gorilla',
+                            'Eastern Lowland Gorilla',
+                        ),
+                    ), 
+                    'Homo' => array(
+                        'Homo Sapiens' => array(
+                            'Homo Sapiens Sapiens',
+                            'Homo Superior'
+                        ),
+                    ),
+                    'Pan' => array(
+                        'Common Chimpanzee',
+                        'Bonobo',
+                    ),
+                ),
+            ),
+        );
+
+        $root = $tree->createNode( 'Hominoidea', 'Hominoidea' );
+        $tree->setRootNode( $root );
+
+        $this->addChildren( $root, $primates['Hominoidea'] );
+    }
+
+    private function addChildren( ezcTreeNode $node, array $children )
+    {
+        foreach( $children as $name => $child )
+        {
+            if ( is_array( $child ) )
+            {
+                $newNode = $node->tree->createNode( $name, $name );
+                $node->addChild( $newNode );
+                $this->addChildren( $newNode, $child );
+            }
+            else
+            {
+                $newNode = $node->tree->createNode( $child, $child );
+                $node->addChild( $newNode );
+            }
+        }
+    }
+
+    public function testVisitor1()
+    {
+        $tree = ezcTreeMemory::create( new ezcTreeMemoryDataStore() );
+        $this->addTestData( $tree );
+
+        $visitor = new ezcTreeVisitorVisualization;
+        $tree->accept( $visitor );
+        self::assertSame( 'c422c6271ff3c9a213156e660a1ba8b2', md5( (string) 
$visitor ) );
+    }
+
+    public static function suite()
+    {
+         return new PHPUnit_Framework_TestSuite( "ezcTreeVisitorTest" );
+    }
+}
+
+?>

Propchange: trunk/Tree/tests/visitor.php
------------------------------------------------------------------------------
    svn:eol-style = native


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to