summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-08-29 12:12:53 -0700
committerBharat Mediratta <bharat@menalto.com>2009-08-29 12:12:53 -0700
commit0d16cc1c106dc324fde59cac54fa82e4a70e04e2 (patch)
treedc8a8984a46f862bc92d84897b631e8b9f5ab5b3
parentd85a8b20bbe0a5be0a03da70354169d41f418d41 (diff)
Clean up the test and get it working.
-rw-r--r--modules/gallery/tests/Item_Helper_Test.php69
1 files changed, 17 insertions, 52 deletions
diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php
index 48fdd962..3f80733f 100644
--- a/modules/gallery/tests/Item_Helper_Test.php
+++ b/modules/gallery/tests/Item_Helper_Test.php
@@ -18,65 +18,30 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Item_Helper_Test extends Unit_Test_Case {
- private $_group;
- private $_album;
- private $_item;
- //private $_user;
- public function teardown() {
- try {
- $this->_group->delete();
- } catch (Exception $e) { }
-
- try {
- $this->_album->delete();
- } catch (Exception $e) { }
-
- //try {
- // $this->_user->delete();
- //} catch (Exception $e) { }
- }
-
- public function setup() {
- }
-
- public function viewable_item_test() {
- $this->_group = group::create("access_test");
+ public function viewable_test() {
$root = ORM::factory("item", 1);
- $this->_album = album::create($root, rand(), "visible_test");
- $this->_user = user::create("visible_test", "Visible Test", "");
- $this->_user->add($this->_group);
- $this->_item = self::_create_random_item($this->_album);
- comment::create($this->_item, $this->_user, "This is a comment");
- access::deny(group::everybody(), "view", $this->_album);
- $active = user::active();
-
- $items = ORM::factory("item")
- ->where("id", $this->_album->id)
- ->find_all();
- print Database::instance()->last_query() . "\n";
- $items = ORM::factory("item")
- ->where("id", $this->_album->id)
- ->viewable()
- ->find_all();
- print Database::instance()->last_query() . "\n";
+ $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());
}
- //public function viewable_one_restrictions_test() {
- // $item = self::create_random_item();
- // $this->assert_true(!empty($item->created));
- // $this->assert_true(!empty($item->updated));
- //}
- //public function viewable_multiple_restrictions_test() {
- // $item = self::create_random_item();
- // $this->assert_true(!empty($item->created));
- // $this->assert_true(!empty($item->updated));
- //}
-
private static function _create_random_item($album) {
+ // Set all required fields (values are irrelevant)
$item = ORM::factory("item");
- /* Set all required fields (values are irrelevant) */
$item->name = rand();
$item->type = "photo";
return $item->add_to_parent($album);