diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-07 08:46:44 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-07 08:46:44 +0000 |
commit | bf7ab8904aa9ccbb201b1ef9634a8b13834e5f6d (patch) | |
tree | d62ae674a2a81696420ef293b0a033605c84da02 /core/tests | |
parent | e40b54a4689f1565e0f76c536d0d4b05b23afc1e (diff) |
Change ORM_MPTT::add_to_parent() to take an ORM instead of an id so
that it's consistent with ORM_MPTT::move_to()
Diffstat (limited to 'core/tests')
-rw-r--r-- | core/tests/Access_Helper_Test.php | 6 | ||||
-rw-r--r-- | core/tests/ORM_MPTT_Test.php | 84 |
2 files changed, 53 insertions, 37 deletions
diff --git a/core/tests/Access_Helper_Test.php b/core/tests/Access_Helper_Test.php index 0f453f15..c924575d 100644 --- a/core/tests/Access_Helper_Test.php +++ b/core/tests/Access_Helper_Test.php @@ -50,7 +50,8 @@ class Access_Helper_Test extends Unit_Test_Case { } public function adding_and_removing_items_adds_ands_removes_rows_test() { - $item = ORM::factory("item")->add_to_parent(1); + $root = ORM::factory("item", 1); + $item = ORM::factory("item")->add_to_parent($root); // Simulate an event access::add_item($item); @@ -70,7 +71,8 @@ class Access_Helper_Test extends Unit_Test_Case { } public function can_allow_deny_and_reset_intent_test() { - $item = ORM::factory("item")->add_to_parent(1); + $root = ORM::factory("item", 1); + $item = ORM::factory("item")->add_to_parent($root); access::add_item($item); $intent = ORM::factory("access_intent")->where("item_id", $item->id)->find(); diff --git a/core/tests/ORM_MPTT_Test.php b/core/tests/ORM_MPTT_Test.php index 03230ad9..b969e287 100644 --- a/core/tests/ORM_MPTT_Test.php +++ b/core/tests/ORM_MPTT_Test.php @@ -19,7 +19,8 @@ */ class ORM_MPTT_Test extends Unit_Test_Case { public function add_to_parent_test() { - $album = ORM::factory("item")->add_to_parent(1); + $root = ORM::factory("item", 1); + $album = ORM::factory("item")->add_to_parent($root); $this->assert_equal($album->parent()->right - 2, $album->left); $this->assert_equal($album->parent()->right - 1, $album->right); @@ -28,11 +29,12 @@ class ORM_MPTT_Test extends Unit_Test_Case { } 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); + $root = ORM::factory("item", 1); + $album1 = ORM::factory("item")->add_to_parent($root); + $album1_1 = ORM::factory("item")->add_to_parent($album1); + $album1_2 = ORM::factory("item")->add_to_parent($album1); + $album1_1_1 = ORM::factory("item")->add_to_parent($album1_1); + $album1_1_2 = ORM::factory("item")->add_to_parent($album1_1); $album1->reload(); $this->assert_equal(9, $album1->right - $album1->left); @@ -42,11 +44,12 @@ class ORM_MPTT_Test extends Unit_Test_Case { } 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); + $root = ORM::factory("item", 1); + $album1 = ORM::factory("item")->add_to_parent($root); + $album1_1 = ORM::factory("item")->add_to_parent($album1); + $album1_2 = ORM::factory("item")->add_to_parent($album1); + $album1_1_1 = ORM::factory("item")->add_to_parent($album1_1); + $album1_1_2 = ORM::factory("item")->add_to_parent($album1_1); $album1_1->delete(); $album1->reload(); @@ -83,15 +86,17 @@ class ORM_MPTT_Test extends Unit_Test_Case { } public function parent_test() { - $album = ORM::factory("item")->add_to_parent(1); + $root = ORM::factory("item", 1); + $album = ORM::factory("item")->add_to_parent($root); $parent = ORM::factory("item", 1); $this->assert_equal($parent->id, $album->parent()->id); } public function parents_test() { - $outer = ORM::factory("item")->add_to_parent(1); - $inner = ORM::factory("item")->add_to_parent($outer->id); + $root = ORM::factory("item", 1); + $outer = ORM::factory("item")->add_to_parent($root); + $inner = ORM::factory("item")->add_to_parent($outer); $parent_ids = array(); foreach ($inner->parents() as $parent) { @@ -101,9 +106,10 @@ class ORM_MPTT_Test extends Unit_Test_Case { } public function children_test() { - $outer = ORM::factory("item")->add_to_parent(1); - $inner1 = ORM::factory("item")->add_to_parent($outer->id); - $inner2 = ORM::factory("item")->add_to_parent($outer->id); + $root = ORM::factory("item", 1); + $outer = ORM::factory("item")->add_to_parent($root); + $inner1 = ORM::factory("item")->add_to_parent($outer); + $inner2 = ORM::factory("item")->add_to_parent($outer); $child_ids = array(); foreach ($outer->children() as $child) { @@ -113,37 +119,41 @@ class ORM_MPTT_Test extends Unit_Test_Case { } public function children_limit_test() { - $outer = ORM::factory("item")->add_to_parent(1); - $inner1 = ORM::factory("item")->add_to_parent($outer->id); - $inner2 = ORM::factory("item")->add_to_parent($outer->id); + $root = ORM::factory("item", 1); + $outer = ORM::factory("item")->add_to_parent($root); + $inner1 = ORM::factory("item")->add_to_parent($outer); + $inner2 = ORM::factory("item")->add_to_parent($outer); $this->assert_equal(array($inner2->id => null), $outer->children(1, 1)->select_list('id')); } public function children_count_test() { - $outer = ORM::factory("item")->add_to_parent(1); - $inner1 = ORM::factory("item")->add_to_parent($outer->id); - $inner2 = ORM::factory("item")->add_to_parent($outer->id); + $root = ORM::factory("item", 1); + $outer = ORM::factory("item")->add_to_parent($root); + $inner1 = ORM::factory("item")->add_to_parent($outer); + $inner2 = ORM::factory("item")->add_to_parent($outer); $this->assert_equal(2, $outer->children_count()); } public function descendant_test() { + $root = ORM::factory("item", 1); + $parent = ORM::factory("item"); $parent->type = "album"; - $parent->add_to_parent(1); + $parent->add_to_parent($root); $photo = ORM::factory("item"); $photo->type = "photo"; - $photo->add_to_parent($parent->id); + $photo->add_to_parent($parent); $album1 = ORM::factory("item"); $album1->type = "album"; - $album1->add_to_parent($parent->id); + $album1->add_to_parent($parent); $photo1 = ORM::factory("item"); $photo1->type = "photo"; - $photo1->add_to_parent($album1->id); + $photo1->add_to_parent($album1); $parent->reload(); @@ -153,31 +163,35 @@ class ORM_MPTT_Test extends Unit_Test_Case { } public function descendant_limit_test() { - $parent = ORM::factory("item")->add_to_parent(1); - $album1 = ORM::factory("item")->add_to_parent($parent->id); - $album2 = ORM::factory("item")->add_to_parent($parent->id); - $album3 = ORM::factory("item")->add_to_parent($parent->id); + $root = ORM::factory("item", 1); + + $parent = ORM::factory("item")->add_to_parent($root); + $album1 = ORM::factory("item")->add_to_parent($parent); + $album2 = ORM::factory("item")->add_to_parent($parent); + $album3 = ORM::factory("item")->add_to_parent($parent); $parent->reload(); $this->assert_equal(2, $parent->descendants(2)->count()); } public function descendant_count_test() { + $root = ORM::factory("item", 1); + $parent = ORM::factory("item"); $parent->type = "album"; - $parent->add_to_parent(1); + $parent->add_to_parent($root); $photo = ORM::factory("item"); $photo->type = "photo"; - $photo->add_to_parent($parent->id); + $photo->add_to_parent($parent); $album1 = ORM::factory("item"); $album1->type = "album"; - $album1->add_to_parent($parent->id); + $album1->add_to_parent($parent); $photo1 = ORM::factory("item"); $photo1->type = "photo"; - $photo1->add_to_parent($album1->id); + $photo1->add_to_parent($album1); $parent->reload(); |