diff options
Diffstat (limited to 'modules/gallery/tests')
-rw-r--r-- | modules/gallery/tests/Item_Helper_Test.php | 49 | ||||
-rw-r--r-- | modules/gallery/tests/Item_Model_Test.php | 14 | ||||
-rw-r--r-- | modules/gallery/tests/ORM_MPTT_Test.php | 8 |
3 files changed, 60 insertions, 11 deletions
diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php new file mode 100644 index 00000000..3f80733f --- /dev/null +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -0,0 +1,49 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Item_Helper_Test extends Unit_Test_Case { + + public function viewable_test() { + $root = ORM::factory("item", 1); + $album = album::create($root, rand(), rand(), rand()); + $item = self::_create_random_item($album); + user::set_active(user::guest()); + + // We can see the item when permissions are granted + access::allow(group::everybody(), "view", $album); + $this->assert_equal( + 1, + ORM::factory("item")->viewable()->where("id", $item->id)->count_all()); + + // We can't see the item when permissions are denied + access::deny(group::everybody(), "view", $album); + $this->assert_equal( + 0, + ORM::factory("item")->viewable()->where("id", $item->id)->count_all()); + } + + + private static function _create_random_item($album) { + // Set all required fields (values are irrelevant) + $item = ORM::factory("item"); + $item->name = rand(); + $item->type = "photo"; + return $item->add_to_parent($album); + } +} diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 0940d076..585e247c 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -19,12 +19,12 @@ */ class Item_Model_Test extends Unit_Test_Case { public function saving_sets_created_and_updated_dates_test() { - $item = self::create_random_item(); + $item = self::_create_random_item(); $this->assert_true(!empty($item->created)); $this->assert_true(!empty($item->updated)); } - private function create_random_item() { + private static function _create_random_item() { $item = ORM::factory("item"); /* Set all required fields (values are irrelevant) */ $item->name = rand(); @@ -33,7 +33,7 @@ class Item_Model_Test extends Unit_Test_Case { } public function updating_doesnt_change_created_date_test() { - $item = self::create_random_item(); + $item = self::_create_random_item(); // Force the creation date to something well known $db = Database::instance(); @@ -47,7 +47,7 @@ class Item_Model_Test extends Unit_Test_Case { } public function updating_view_count_only_doesnt_change_updated_date_test() { - $item = self::create_random_item(); + $item = self::_create_random_item(); $item->reload(); $this->assert_same(0, $item->view_count); @@ -64,7 +64,7 @@ class Item_Model_Test extends Unit_Test_Case { public function move_photo_test() { // Create a test photo - $item = self::create_random_item(); + $item = self::_create_random_item(); file_put_contents($item->thumb_path(), "thumb"); file_put_contents($item->resize_path(), "resize"); @@ -128,7 +128,7 @@ class Item_Model_Test extends Unit_Test_Case { public function item_rename_wont_accept_slash_test() { // Create a test photo - $item = self::create_random_item(); + $item = self::_create_random_item(); $new_name = rand() . "/"; @@ -142,7 +142,7 @@ class Item_Model_Test extends Unit_Test_Case { } public function save_original_values_test() { - $item = $this->create_random_item(); + $item = self::_create_random_item(); $item->title = "ORIGINAL_VALUE"; $item->save(); $item->title = "NEW_VALUE"; diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php index 943810c3..f77f1f34 100644 --- a/modules/gallery/tests/ORM_MPTT_Test.php +++ b/modules/gallery/tests/ORM_MPTT_Test.php @@ -177,8 +177,8 @@ class ORM_MPTT_Test extends Unit_Test_Case { $parent->reload(); $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()); + $this->assert_equal(2, $parent->descendants(null, 0, array("type" => "photo"))->count()); + $this->assert_equal(1, $parent->descendants(null, 0, array("type" => "album"))->count()); } public function descendant_limit_test() { @@ -215,7 +215,7 @@ class ORM_MPTT_Test extends Unit_Test_Case { $parent->reload(); $this->assert_equal(3, $parent->descendants_count()); - $this->assert_equal(2, $parent->descendants_count("photo")); - $this->assert_equal(1, $parent->descendants_count("album")); + $this->assert_equal(2, $parent->descendants_count(array("type" => "photo"))); + $this->assert_equal(1, $parent->descendants_count(array("type" => "album"))); } } |