From 212e6a0778a918749c0323eeb2ea9b1feb3ba9b5 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 4 Nov 2008 23:16:42 +0000 Subject: New tests for the ORM_MPTT class. --- core/tests/ORM_MPTT_Test.php | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 core/tests/ORM_MPTT_Test.php (limited to 'core/tests') diff --git a/core/tests/ORM_MPTT_Test.php b/core/tests/ORM_MPTT_Test.php new file mode 100644 index 00000000..208c199f --- /dev/null +++ b/core/tests/ORM_MPTT_Test.php @@ -0,0 +1,72 @@ +type = "photo"; + $album->title = "test"; + $album->name = "test"; + $album->add_to_parent(1); + + $this->assert_equal($album->parent()->right - 2, $album->left); + $this->assert_equal($album->parent()->right - 1, $album->right); + $this->assert_equal($album->parent()->level + 1, $album->level); + $this->assert_equal($album->parent()->id, $album->parent_id); + } + + public function parent_test() { + $album = ORM::factory("item"); + $album->add_to_parent(1); + + $parent = ORM::factory("item", 1); + $this->assert_equal($parent->id, $album->parent()->id); + } + + public function parents_test() { + $outer = ORM::factory("item"); + $outer->add_to_parent(1); + + $inner = ORM::factory("item"); + $inner->add_to_parent($outer->id); + + $parent_ids = array(); + foreach ($inner->parents() as $parent) { + $parent_ids[] = $parent->id; + } + $this->assert_equal(array(1, $outer->id, $inner->id), $parent_ids); + } + + public function children_test() { + $outer = ORM::factory("item"); + $outer->add_to_parent(1); + + $inner1 = ORM::factory("item"); + $inner1->add_to_parent($outer->id); + + $inner2 = ORM::factory("item"); + $inner2->add_to_parent($outer->id); + + $child_ids = array(); + foreach ($outer->children() as $child) { + $child_ids[] = $child->id; + } + $this->assert_equal(array($inner1->id, $inner2->id), $child_ids); + } +} -- cgit v1.2.3