Author: dr
Date: Tue Jul 31 09:38:27 2007
New Revision: 5761

Log:
- Fixed node deletion and tests.

Modified:
    trunk/Tree/src/backends/memory.php
    trunk/Tree/src/backends/xml.php
    trunk/Tree/tests/memory_tree.php
    trunk/Tree/tests/suite.php
    trunk/Tree/tests/tree.php

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] Tue Jul 31 09:38:27 2007
@@ -394,11 +394,17 @@
         // locate node to move
         $nodeToDelete = $this->getNodeById( $id );
 
+        // fetch the whole subtree
+        $children = $nodeToDelete->node->fetchSubtree();
+
         // Use the parent to remove the child
         unset( $nodeToDelete->parent->children[$id] );
 
-        // Remove from node list
-        unset( $this->nodeList[$childNode->id] );
+        // Remove the node and all its children
+        foreach( new ezcTreeNodeListIterator( $this, $children ) as $id => 
$data )
+        {
+            unset( $this->nodeList[$id] );
+        }
     }
 
     /**

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] Tue Jul 31 09:38:27 2007
@@ -335,6 +335,16 @@
         $nodeToDelete = $this->getNodeById( $id );
 
         // Use the parent to remove the child
+        $nodeToDelete->removeAttribute( "id" );
+
+        // Remove the ID on all children by hand as this would crash in PHP <= 
5.2.3
+        $children = $nodeToDelete->getElementsByTagName( 'node' );
+        foreach ( $children as $child )
+        {
+            $child->removeAttribute( "id" );
+        }
+
+        // Remove the node itself
         $nodeToDelete->parentNode->removeChild( $nodeToDelete );
 
         if ( !$this->inTransactionCommit )

Modified: trunk/Tree/tests/memory_tree.php
==============================================================================
--- trunk/Tree/tests/memory_tree.php [iso-8859-1] (original)
+++ trunk/Tree/tests/memory_tree.php [iso-8859-1] Tue Jul 31 09:38:27 2007
@@ -36,13 +36,10 @@
 
         return $tree;
     }
-/*
-    public function testCreateXmlTree()
+
+    public function testCreateMemoryTree()
     {
-        $tree = ezcTreeXml::create(
-            $this->tempDir . '/new-tree.xml', 
-            new ezcTreeXmlInternalDataStore()
-        );
+        $tree = ezcTreeMemory::create( new ezcTreeMemoryDataStore() );
         self::assertSame( false, $tree->nodeExists( '1' ) );
         self::assertSame( false, $tree->nodeExists( '3' ) );
 
@@ -60,19 +57,11 @@
         $node3->addChild( $tree->createNode( 4, "Node 3.4" ) );
         self::assertSame( true, $tree->nodeExists( '3' ) );
         self::assertSame( true, $tree->nodeExists( '4' ) );
-
-        self::assertXmlFileEqualsXmlFile(
-            dirname( __FILE__ ) . '/files/create-test.xml', 
-            $this->tempDir . '/new-tree.xml'
-        );
     }
 
-    public function testCreateXmlTreeWithTransaction()
+    public function testCreateMemoryTreeWithTransaction()
     {
-        $tree = ezcTreeXml::create(
-            $this->tempDir . '/new-tree.xml', 
-            new ezcTreeXmlInternalDataStore()
-        );
+        $tree = ezcTreeMemory::create( new ezcTreeMemoryDataStore() );
 
         $tree->setRootNode( $node = $tree->createNode( 1, "Root Node" ) );
         self::assertSame( true, $tree->nodeExists( '1' ) );
@@ -87,13 +76,8 @@
         $tree->commit();
         
         self::assertSame( true, $tree->nodeExists( '3' ) );
+    }
 
-        self::assertXmlFileEqualsXmlFile(
-            dirname( __FILE__ ) . '/files/create-test.xml', 
-            $this->tempDir . '/new-tree.xml'
-        );
-    }
-*/
     public static function suite()
     {
          return new PHPUnit_Framework_TestSuite( "ezcTreeMemoryTest" );

Modified: trunk/Tree/tests/suite.php
==============================================================================
--- trunk/Tree/tests/suite.php [iso-8859-1] (original)
+++ trunk/Tree/tests/suite.php [iso-8859-1] Tue Jul 31 09:38:27 2007
@@ -7,11 +7,6 @@
  * @package Tree
  * @subpackage Tests
  */
-
-/**
- * Require the test classes file
- */
-require 'files/test_classes.php';
 
 /**
  * Require the tests

Modified: trunk/Tree/tests/tree.php
==============================================================================
--- trunk/Tree/tests/tree.php [iso-8859-1] (original)
+++ trunk/Tree/tests/tree.php [iso-8859-1] Tue Jul 31 09:38:27 2007
@@ -7,6 +7,11 @@
  * @package Tree
  * @subpackage Tests
  */
+
+/**
+ * Require the test classes file
+ */
+require_once 'files/test_classes.php';
 
 /**
  * @package Tree
@@ -483,7 +488,6 @@
 
     public function testTreeDeleteNode()
     {
-        $this->markTestSkipped( "Crashes PHP" );
         $tree = $this->setUpTestTree();
 
         self::assertSame( true, $tree->nodeExists( 5 ) );
@@ -504,7 +508,6 @@
 
     public function testTreeDeleteNodeWithTransaction()
     {
-        $this->markTestSkipped( "Crashes PHP" );
         $tree = $this->setUpTestTree();
 
         self::assertSame( true, $tree->nodeExists( 5 ) );


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

Reply via email to