Author: dr
Date: Fri Aug 10 13:31:37 2007
New Revision: 5870
Log:
- Added the fetchDataForNodes() method to ezcTreeNodeList.
Modified:
trunk/Tree/src/tree_node_list.php
trunk/Tree/tests/files/test_classes.php
trunk/Tree/tests/tree_node_list.php
Modified: trunk/Tree/src/tree_node_list.php
==============================================================================
--- trunk/Tree/src/tree_node_list.php [iso-8859-1] (original)
+++ trunk/Tree/src/tree_node_list.php [iso-8859-1] Fri Aug 10 13:31:37 2007
@@ -168,5 +168,27 @@
{
return $this->nodes;
}
+
+ /**
+ * Fetches data for all nodes in the node list
+ *
+ * @param ezcTreeNodeList $nodeList
+ */
+ public function fetchDataForNodes()
+ {
+ // We need to use a little trick to get to the tree object. We can do
+ // that through ezcTreeNode objects that are part of this list. We
+ // can't do that when the list is empty. In that case we just return.
+ if ( count( $this->nodes ) === 0 )
+ {
+ return;
+ }
+ // Find a node in the list
+ reset( $this->nodes );
+ $node = current( $this->nodes );
+ // Grab the tree and use it to fetch data for all nodes from the store
+ $tree = $node->tree;
+ $tree->store->fetchDataForNodes( $this );
+ }
}
?>
Modified: trunk/Tree/tests/files/test_classes.php
==============================================================================
--- trunk/Tree/tests/files/test_classes.php [iso-8859-1] (original)
+++ trunk/Tree/tests/files/test_classes.php [iso-8859-1] Fri Aug 10 13:31:37
2007
@@ -15,11 +15,23 @@
{
$node->data = 'Aluminium';
}
+
+ switch( $node->id )
+ {
+ case 'Aries': $node->data = 'â'; break;
+ case 'Taurus': $node->data = 'â'; break;
+ case 'Gemini': $node->data = 'â'; break;
+ case 'Cancer': $node->data = 'â'; break;
+ }
+ $node->dataFetched = true;
}
public function fetchDataForNodes( ezcTreeNodeList $nodeList )
{
- /* This is a no-op as the data is already in the $node */
+ foreach( $nodeList->getNodes() as $node )
+ {
+ $this->fetchDataForNode( $node );
+ }
}
public function storeDataForNode( ezcTreeNode $node )
Modified: trunk/Tree/tests/tree_node_list.php
==============================================================================
--- trunk/Tree/tests/tree_node_list.php [iso-8859-1] (original)
+++ trunk/Tree/tests/tree_node_list.php [iso-8859-1] Fri Aug 10 13:31:37 2007
@@ -8,6 +8,8 @@
* @subpackage Tests
*/
+require_once 'tree.php';
+
/**
* @package Tree
* @subpackage Tests
@@ -172,6 +174,40 @@
self::assertSame( false, isset( $list['78'] ) );
}
+ public function testFetchAllDataEmptyList()
+ {
+ $list = new ezcTreeNodeList;
+ $list->fetchDataForNodes();
+ self::assertSame( 0, $list->size );
+ }
+
+ public function testFetchAllData()
+ {
+ $tree = ezcTreeMemory::create( new TestTranslateDataStore() );
+
+ $list = new ezcTreeNodeList;
+ $list->addNode( $node = new ezcTreeNode( $tree, 'Aries' ) );
+ $list->addNode( $node = new ezcTreeNode( $tree, 'Taurus' ) );
+ $list->addNode( $node = new ezcTreeNode( $tree, 'Gemini' ) );
+ $list->addNode( $node = new ezcTreeNode( $tree, 'Cancer' ) );
+ foreach( $list->getNodes() as $node )
+ {
+ self::assertSame( false, $node->dataFetched );
+ }
+
+ $list->fetchDataForNodes();
+
+ foreach( $list->getNodes() as $node )
+ {
+ self::assertSame( true, $node->dataFetched );
+ }
+ self::assertSame( 'â', $list['Cancer']->data );
+ }
+
+ public function testSame()
+ {
+ }
+
public static function suite()
{
return new PHPUnit_Framework_TestSuite( "ezcTreeNodeListTest" );
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components