summaryrefslogtreecommitdiff
path: root/core/tests/ORM_MPTT_Test.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-04 05:47:05 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-04 05:47:05 +0000
commit375e7c675ef31c9b3c44292f1577fb5f1cea42a2 (patch)
tree373f2820c669a2c5bf2f7fe51ed9d3e39edfe208 /core/tests/ORM_MPTT_Test.php
parent89a346c1e14be26a9b7ac98c6996e84b537228ea (diff)
Implement ORM_MPTT::delete() properly.
Inline ORM_MPTT::_grow() for now Rewrite ORM_MPTT tests to be domain specific; they no longer use album/photo helpers.
Diffstat (limited to 'core/tests/ORM_MPTT_Test.php')
-rw-r--r--core/tests/ORM_MPTT_Test.php117
1 files changed, 51 insertions, 66 deletions
diff --git a/core/tests/ORM_MPTT_Test.php b/core/tests/ORM_MPTT_Test.php
index e92f07fc..733b30ea 100644
--- a/core/tests/ORM_MPTT_Test.php
+++ b/core/tests/ORM_MPTT_Test.php
@@ -48,7 +48,7 @@ class ORM_MPTT_Test extends Unit_Test_Case {
$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_1->delete();
$album1->reload();
// Now album1 contains only album1_2
@@ -56,19 +56,15 @@ class ORM_MPTT_Test extends Unit_Test_Case {
}
public function parent_test() {
- $album = ORM::factory("item");
- $album->add_to_parent(1);
+ $album = ORM::factory("item")->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);
+ $outer = ORM::factory("item")->add_to_parent(1);
+ $inner = ORM::factory("item")->add_to_parent($outer->id);
$parent_ids = array();
foreach ($inner->parents() as $parent) {
@@ -78,14 +74,9 @@ class ORM_MPTT_Test extends Unit_Test_Case {
}
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);
+ $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);
$child_ids = array();
foreach ($outer->children() as $child) {
@@ -95,82 +86,76 @@ class ORM_MPTT_Test extends Unit_Test_Case {
}
public function children_limit_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);
+ $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);
$this->assert_equal(array($inner2->id => null), $outer->children(1, 1)->select_list('id'));
}
public function children_count_test() {
- $outer = ORM::factory("item");
- $outer->add_to_parent(1);
-
- $inner1 = ORM::factory("item");
- $inner1->add_to_parent($outer->id);
+ $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);
- $inner2 = ORM::factory("item");
- $inner2->add_to_parent($outer->id);
$this->assert_equal(2, $outer->children_count());
}
public function descendant_test() {
- $parent = album::create(1, "parent album", "parent album title");
- photo::create($parent->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
- "photo1", "parent album photo");
+ $parent = ORM::factory("item");
+ $parent->type = "album";
+ $parent->add_to_parent(1);
- $album1 = album::create($parent->id, "album1", "album1 title");
- photo::create($album1->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
- "photo1", "album1 photo");
+ $photo = ORM::factory("item");
+ $photo->type = "photo";
+ $photo->add_to_parent($parent->id);
+
+ $album1 = ORM::factory("item");
+ $album1->type = "album";
+ $album1->add_to_parent($parent->id);
+
+ $photo1 = ORM::factory("item");
+ $photo1->type = "photo";
+ $photo1->add_to_parent($album1->id);
- $album2 = album::create($parent->id, "album2", "album2 title");
- photo::create($album2->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo2",
- "photo2", "album2 photo");
$parent->reload();
- $this->assert_equal(5, $parent->descendants()->count());
- $this->assert_equal(3, $parent->descendants(null, 0, "photo")->count());
- $this->assert_equal(2, $parent->descendants(null, 0, "album")->count());
+ $this->assert_equal(3, $parent->descendants()->count());
+ $this->assert_equal(2, $parent->descendants(null, 0, "photo")->count());
+ $this->assert_equal(1, $parent->descendants(null, 0, "album")->count());
}
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",
- "photo1", "parent album photo");
-
- $album1 = album::create($parent->id, "album1", "album1 title");
- photo::create($album1->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
- "photo1", "album1 photo");
+ $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);
- $album2 = album::create($parent->id, "album2", "album2 title");
- photo::create($album2->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo2",
- "photo2", "album2 photo");
$parent->reload();
-
$this->assert_equal(2, $parent->descendants(2)->count());
}
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",
- "photo1", "parent album photo");
+ $parent = ORM::factory("item");
+ $parent->type = "album";
+ $parent->add_to_parent(1);
+
+ $photo = ORM::factory("item");
+ $photo->type = "photo";
+ $photo->add_to_parent($parent->id);
+
+ $album1 = ORM::factory("item");
+ $album1->type = "album";
+ $album1->add_to_parent($parent->id);
- $album1 = album::create($parent->id, "album1", "album1 title");
- photo::create($album1->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo1",
- "photo1", "album1 photo");
+ $photo1 = ORM::factory("item");
+ $photo1->type = "photo";
+ $photo1->add_to_parent($album1->id);
- $album2 = album::create($parent->id, "album2", "album2 title");
- photo::create($album2->id, DOCROOT . "themes/default/images/thumbnail.jpg", "photo2",
- "photo2", "album2 photo");
$parent->reload();
- $this->assert_equal(5, $parent->descendants_count());
- $this->assert_equal(3, $parent->descendants_count("photo"));
- $this->assert_equal(2, $parent->descendants_count("album"));
+ $this->assert_equal(3, $parent->descendants_count());
+ $this->assert_equal(2, $parent->descendants_count("photo"));
+ $this->assert_equal(1, $parent->descendants_count("album"));
}
}