summaryrefslogtreecommitdiff
path: root/core/tests
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-04 05:15:21 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-04 05:15:21 +0000
commit24cbff29cc0cd30ade2064862387d55f96a3ec90 (patch)
treecf9c1d15ac3e8308340a6e78688f0ee1fc588db7 /core/tests
parent5c095cbd787bf71e30658536aafdbf8ea837aa1f (diff)
Replace grow_test and constrict_test with add_hierarchy_test and
delete_hierarchy_test. Our tests will be more robust if we test the public API and not the internal private functions. If we get to the point where we have to test the private functions, we should probably move those functions into their own separate class with a public API.
Diffstat (limited to 'core/tests')
-rw-r--r--core/tests/ORM_MPTT_Test.php94
1 files changed, 29 insertions, 65 deletions
diff --git a/core/tests/ORM_MPTT_Test.php b/core/tests/ORM_MPTT_Test.php
index 34a6ed9d..e92f07fc 100644
--- a/core/tests/ORM_MPTT_Test.php
+++ b/core/tests/ORM_MPTT_Test.php
@@ -19,11 +19,7 @@
*/
class ORM_MPTT_Test extends Unit_Test_Case {
public function add_to_parent_test() {
- $album = ORM::factory("item");
- $album->type = "photo";
- $album->title = "test";
- $album->name = "test";
- $album->add_to_parent(1);
+ $album = ORM::factory("item")->add_to_parent(1);
$this->assert_equal($album->parent()->right - 2, $album->left);
$this->assert_equal($album->parent()->right - 1, $album->right);
@@ -31,6 +27,34 @@ class ORM_MPTT_Test extends Unit_Test_Case {
$this->assert_equal($album->parent()->id, $album->parent_id);
}
+ public function add_hierarchy_test() {
+ $album1 = ORM::factory("item")->add_to_parent(1);
+ $album1_1 = ORM::factory("item")->add_to_parent($album1->id);
+ $album1_2 = ORM::factory("item")->add_to_parent($album1->id);
+ $album1_1_1 = ORM::factory("item")->add_to_parent($album1_1->id);
+ $album1_1_2 = ORM::factory("item")->add_to_parent($album1_1->id);
+
+ $album1->reload();
+ $this->assert_equal(9, $album1->right - $album1->left);
+
+ $album1_1->reload();
+ $this->assert_equal(5, $album1_1->right - $album1_1->left);
+ }
+
+ public function delete_hierarchy_test() {
+ $album1 = ORM::factory("item")->add_to_parent(1);
+ $album1_1 = ORM::factory("item")->add_to_parent($album1->id);
+ $album1_2 = ORM::factory("item")->add_to_parent($album1->id);
+ $album1_1_1 = ORM::factory("item")->add_to_parent($album1_1->id);
+ $album1_1_2 = ORM::factory("item")->add_to_parent($album1_1->id);
+
+ $album1_1->reload()->delete();
+ $album1->reload();
+
+ // Now album1 contains only album1_2
+ $this->assert_equal(3, $album1->right - $album1->left);
+ }
+
public function parent_test() {
$album = ORM::factory("item");
$album->add_to_parent(1);
@@ -149,64 +173,4 @@ 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);
- }
}