summaryrefslogtreecommitdiff
path: root/core/tests
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2008-12-04 01:12:44 +0000
committerTim Almdal <tnalmdal@shaw.ca>2008-12-04 01:12:44 +0000
commit5c095cbd787bf71e30658536aafdbf8ea837aa1f (patch)
tree670301aa58fca86c16d18f4ea5615fb70e214d73 /core/tests
parent9ae6acdc0ab3f40fa6267161d733e79d4424eb0b (diff)
Add unit tests to test growing and contracting the left and right pointers
Added a delete method to ORM_MPTT that contracts the tree when an item is deleted
Diffstat (limited to 'core/tests')
-rw-r--r--core/tests/ORM_MPTT_Test.php78
1 files changed, 69 insertions, 9 deletions
diff --git a/core/tests/ORM_MPTT_Test.php b/core/tests/ORM_MPTT_Test.php
index 2b334243..34a6ed9d 100644
--- a/core/tests/ORM_MPTT_Test.php
+++ b/core/tests/ORM_MPTT_Test.php
@@ -97,15 +97,15 @@ class ORM_MPTT_Test extends Unit_Test_Case {
public function descendant_test() {
$parent = album::create(1, "parent album", "parent album title");
- photo::create($parent->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
+ photo::create($parent->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
"photo1", "parent album photo");
$album1 = album::create($parent->id, "album1", "album1 title");
- photo::create($album1->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
+ photo::create($album1->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
"photo1", "album1 photo");
$album2 = album::create($parent->id, "album2", "album2 title");
- photo::create($album2->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo2",
+ photo::create($album2->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo2",
"photo2", "album2 photo");
$parent->reload();
@@ -116,15 +116,15 @@ class ORM_MPTT_Test extends Unit_Test_Case {
public function descendant_limit_test() {
$parent = album::create(1, "parent album", "parent album title");
- photo::create($parent->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
+ photo::create($parent->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
"photo1", "parent album photo");
$album1 = album::create($parent->id, "album1", "album1 title");
- photo::create($album1->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
+ photo::create($album1->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
"photo1", "album1 photo");
$album2 = album::create($parent->id, "album2", "album2 title");
- photo::create($album2->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo2",
+ photo::create($album2->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo2",
"photo2", "album2 photo");
$parent->reload();
@@ -133,15 +133,15 @@ class ORM_MPTT_Test extends Unit_Test_Case {
public function descendant_count_test() {
$parent = album::create(1, "parent album", "parent album title");
- photo::create($parent->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
+ photo::create($parent->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
"photo1", "parent album photo");
$album1 = album::create($parent->id, "album1", "album1 title");
- photo::create($album1->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
+ photo::create($album1->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
"photo1", "album1 photo");
$album2 = album::create($parent->id, "album2", "album2 title");
- photo::create($album2->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo2",
+ photo::create($album2->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo2",
"photo2", "album2 photo");
$parent->reload();
@@ -149,4 +149,64 @@ class ORM_MPTT_Test extends Unit_Test_Case {
$this->assert_equal(3, $parent->descendants_count("photo"));
$this->assert_equal(2, $parent->descendants_count("album"));
}
+
+ public function grow_test() {
+ $parent = ORM::factory("item", 1);
+
+ $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);
+
+ $parent->reload();
+ $original_parent_right = $parent->right;
+ $original_right = $outer->right;
+
+ $outer->_grow(2);
+
+ $parent->reload();
+ $this->assert_equal($original_right + 2, $outer->right);
+ $this->assert_equal($original_parent_right + 4, $parent->right);
+ }
+
+ public function contract_test() {
+ $parent = ORM::factory("item", 1);
+ $parent->reload();
+ Kohana::log("debug", "original parent->right: " . $parent->right);
+
+ $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);
+
+ $outer->reload();
+ $parent->reload();
+ $original_parent_right = $parent->right;
+ $original_right = $outer->right;
+
+ $inner3 = ORM::factory("item");
+ $inner3->add_to_parent($outer->id);
+
+ $inner4 = ORM::factory("item");
+ $inner4->add_to_parent($outer->id);
+
+
+ $inner2->delete();
+ $inner4->delete();
+
+ $outer->_grow(-2);
+
+ $outer->reload();
+ $parent->reload();
+ $this->assert_equal($original_right, $outer->right);
+ $this->assert_equal($original_parent_right, $parent->right);
+ }
}