From 5d9465870d897ed247d57522989546f3fc929d21 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 11 Jun 2007 15:45:55 +0000 Subject: [PATCH] --- tests/CascadingDeleteTestCase.php | 91 +++++++++++++++++++++++++++++++ tests/run.php | 2 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tests/CascadingDeleteTestCase.php diff --git a/tests/CascadingDeleteTestCase.php b/tests/CascadingDeleteTestCase.php new file mode 100644 index 000000000..6b80eea29 --- /dev/null +++ b/tests/CascadingDeleteTestCase.php @@ -0,0 +1,91 @@ +. + */ + +/** + * Doctrine_CascadingDelete_TestCase + * + * @package Doctrine + * @author Konsta Vesterinen + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_CascadingDelete_TestCase extends Doctrine_UnitTestCase +{ + public function prepareData() + { } + public function prepareTables() + { } + public function testCascadingDeleteEmulation() + { + $r = new ForeignKeyTest; + $r->name = 'Parent'; + $r->Children[0]->name = 'Child 1'; + $this->assertEqual($r->id, null); + $this->assertEqual($r->Children[0]->id, null); + $r->save(); + + $this->assertEqual($r->id, 1); + $this->assertEqual($r->Children[0]->id, 2); + + + $this->connection->clear(); + + $r = $this->connection->query('FROM ForeignKeyTest'); + + $this->assertEqual($r->count(), 2); + + // should delete the first child + $r[0]->delete(); + + $this->connection->clear(); + + $r = $this->connection->query('FROM ForeignKeyTest'); + + $this->assertEqual($r->count(), 0); + } + public function testCascadingDeleteEmulation2() + { + $r = new ForeignKeyTest; + $r->name = 'Parent'; + $r->Children[0]->name = 'Child 1'; + $r->Children[0]->Children[0]->name = 'Child 1 Child 1'; + $r->Children[1]->name = 'Child 2'; + $r->save(); + + $this->connection->clear(); + + $r = $this->connection->query('FROM ForeignKeyTest'); + + $this->assertEqual($r->count(), 4); + + // should delete the children recursively + $r[0]->delete(); + + $this->connection->clear(); + + $r = $this->connection->query('FROM ForeignKeyTest'); + + $this->assertEqual($r->count(), 0); + } +} diff --git a/tests/run.php b/tests/run.php index becdfd57d..2a7553906 100644 --- a/tests/run.php +++ b/tests/run.php @@ -65,7 +65,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests'); // DATABASE ABSTRACTION tests -/** */ + // Connection drivers (not yet fully tested) $test->addTestCase(new Doctrine_Connection_Pgsql_TestCase()); $test->addTestCase(new Doctrine_Connection_Oracle_TestCase());