From e6d7127f5cce6be38bcdba8c34120dc492b40c2c Mon Sep 17 00:00:00 2001 From: romanb Date: Wed, 11 Jul 2007 15:55:52 +0000 Subject: [PATCH] First tests for NestedSet. --- tests/NestedSet/SingleRootTestCase.php | 75 ++++++++++++++++++++++++++ tests/classes.php | 11 ++++ tests/run.php | 2 + 3 files changed, 88 insertions(+) create mode 100644 tests/NestedSet/SingleRootTestCase.php diff --git a/tests/NestedSet/SingleRootTestCase.php b/tests/NestedSet/SingleRootTestCase.php new file mode 100644 index 000000000..3f74db71b --- /dev/null +++ b/tests/NestedSet/SingleRootTestCase.php @@ -0,0 +1,75 @@ +. + */ + +/** + * Doctrine_Record_State_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_NestedSet_SingleRoot_TestCase extends Doctrine_UnitTestCase +{ + public function prepareTables() + { + $this->tables[] = 'NestedSetTest_SingleRootNode'; + parent::prepareTables(); + } + + public function prepareData() + { + $node = new NestedSetTest_SingleRootNode(); + $node->name = 'root'; + $treeMngr = $this->conn->getTable('NestedSetTest_SingleRootNode')->getTree(); + $treeMngr->createRoot($node); + + $node2 = new NestedSetTest_SingleRootNode(); + $node2->name = 'node2'; + $node2->getNode()->insertAsLastChildOf($node); + } + + public function testGetDescendants() + { + $treeMngr = $this->conn->getTable('NestedSetTest_SingleRootNode')->getTree(); + $root = $treeMngr->fetchRoot(); + $desc = $root->getNode()->getDescendants(); + $this->assertTrue($desc !== false); + $this->assertEqual(1, count($desc)); + $this->assertEqual('node2', $desc[0]['name']); + $this->assertEqual(1, $desc[0]['level']); + } + + public function testGetAncestors() + { + $node = $this->conn->query("SELECT n.* FROM NestedSetTest_SingleRootNode n WHERE n.name = ?", + array('node2'))->getFirst(); + $anc = $node->getNode()->getAncestors(); + $this->assertTrue($anc !== false); + $this->assertEqual(1, count($anc)); + $this->assertEqual('root', $anc[0]['name']); + $this->assertEqual(0, $anc[0]['level']); + } + +} diff --git a/tests/classes.php b/tests/classes.php index 3a7d8e799..4b27c1c22 100644 --- a/tests/classes.php +++ b/tests/classes.php @@ -889,4 +889,15 @@ class ValidatorTest_AddressModel extends Doctrine_Record { } } +class NestedSetTest_SingleRootNode extends Doctrine_Record { + + public function setTableDefinition() { + // Nested set options + $this->option('treeImpl', 'NestedSet'); + + $this->hasColumn('name', 'string', 50, array('notnull')); + } + +} + ?> diff --git a/tests/run.php b/tests/run.php index 0a4c4d5cc..ae3076aee 100644 --- a/tests/run.php +++ b/tests/run.php @@ -331,6 +331,8 @@ $test->addTestCase(new Doctrine_Search_TestCase()); //$test->addTestCase(new Doctrine_AuditLog_TestCase()); +$test->addTestCase(new Doctrine_NestedSet_SingleRoot_TestCase()); + // Cache tests //$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase()); //$test->addTestCase(new Doctrine_Cache_FileTestCase());