diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-10-22 13:09:20 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-10-22 13:11:03 -0700 |
commit | 3c936d661a088fb43b47eb5b208958180e8f65eb (patch) | |
tree | 1a117dc1bfe54bec44f664cbd7c5f8c93aa5e993 /modules/gallery/tests | |
parent | 4cb9ec1d6d37b49ebafc68d0a94d794a1acb8b28 (diff) |
Change the name of identity library from Identity to IdentityProvider. Create a helper class called identity to simplify call the Identity Provider. Move the contents of MY_Session.php to the new helper class and remove the MY_Session class
Diffstat (limited to 'modules/gallery/tests')
-rw-r--r-- | modules/gallery/tests/Access_Helper_Test.php | 144 | ||||
-rw-r--r-- | modules/gallery/tests/Albums_Controller_Test.php | 4 | ||||
-rw-r--r-- | modules/gallery/tests/Item_Helper_Test.php | 6 | ||||
-rw-r--r-- | modules/gallery/tests/Photos_Controller_Test.php | 6 |
4 files changed, 80 insertions, 80 deletions
diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index dac431a7..e9e5cb26 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -22,7 +22,7 @@ class Access_Helper_Test extends Unit_Test_Case { public function teardown() { try { - $group = Identity::lookup_group_by_name("access_test"); + $group = identity::lookup_group_by_name("access_test"); if (!empty($group)) { $group->delete(); } @@ -33,7 +33,7 @@ class Access_Helper_Test extends Unit_Test_Case { } catch (Exception $e) { } try { - $user = Identity::lookup_user_by_name("access_test"); + $user = identity::lookup_user_by_name("access_test"); if (!empty($user)) { $user->delete(); } @@ -41,16 +41,16 @@ class Access_Helper_Test extends Unit_Test_Case { // Reset some permissions that we mangle below $root = ORM::factory("item", 1); - access::allow(Identity::everybody(), "view", $root); + access::allow(identity::everybody(), "view", $root); } public function setup() { - Session::set_active_user(Identity::guest()); + identity::set_active_user(identity::guest()); } public function groups_and_permissions_are_bound_to_columns_test() { access::register_permission("access_test", "Access Test"); - $group = Identity::create_group("access_test"); + $group = identity::create_group("access_test"); // We have a new column for this perm / group combo $fields = Database::instance()->list_fields("access_caches"); @@ -65,17 +65,17 @@ class Access_Helper_Test extends Unit_Test_Case { } public function user_can_access_test() { - $access_test = Identity::create_group("access_test"); + $access_test = identity::create_group("access_test"); $root = ORM::factory("item", 1); access::allow($access_test, "view", $root); $item = album::create($root, rand(), "test album"); - access::deny(Identity::everybody(), "view", $item); - access::deny(Identity::registered_users(), "view", $item); + access::deny(identity::everybody(), "view", $item); + access::deny(identity::registered_users(), "view", $item); - $user = Identity::create_user("access_test", "Access Test", ""); + $user = identity::create_user("access_test", "Access Test", ""); foreach ($user->groups as $group) { $user->remove($group); } @@ -89,10 +89,10 @@ class Access_Helper_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $item = album::create($root, rand(), "test album"); - access::deny(Identity::everybody(), "view", $item); - access::deny(Identity::registered_users(), "view", $item); + access::deny(identity::everybody(), "view", $item); + access::deny(identity::registered_users(), "view", $item); - $user = Identity::create_user("access_test", "Access Test", ""); + $user = identity::create_user("access_test", "Access Test", ""); foreach ($user->groups as $group) { $user->remove($group); } @@ -121,11 +121,11 @@ class Access_Helper_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $album = album::create($root, rand(), "test album"); - access::allow(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $album); $photo = photo::create($album, MODPATH . "gallery/images/gallery.png", "", ""); - $this->assert_true($photo->__get("view_" . Identity::everybody()->id)); + $this->assert_true($photo->__get("view_" . identity::everybody()->id)); } public function can_allow_deny_and_reset_intent_test() { @@ -134,23 +134,23 @@ class Access_Helper_Test extends Unit_Test_Case { $intent = ORM::factory("access_intent")->where("item_id", $album)->find(); // Allow - access::allow(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $album); $this->assert_same(access::ALLOW, $intent->reload()->view_1); // Deny - access::deny(Identity::everybody(), "view", $album); + access::deny(identity::everybody(), "view", $album); $this->assert_same( access::DENY, ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); // Allow again. If the initial value was allow, then the first Allow clause above may not // have actually changed any values. - access::allow(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $album); $this->assert_same( access::ALLOW, ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); - access::reset(Identity::everybody(), "view", $album); + access::reset(identity::everybody(), "view", $album); $this->assert_same( null, ORM::factory("access_intent")->where("item_id", $album)->find()->view_1); @@ -158,7 +158,7 @@ class Access_Helper_Test extends Unit_Test_Case { public function cant_reset_root_item_test() { try { - access::reset(Identity::everybody(), "view", ORM::factory("item", 1)); + access::reset(identity::everybody(), "view", ORM::factory("item", 1)); } catch (Exception $e) { return; } @@ -167,17 +167,17 @@ class Access_Helper_Test extends Unit_Test_Case { public function can_view_item_test() { $root = ORM::factory("item", 1); - access::allow(Identity::everybody(), "view", $root); - $this->assert_true(access::group_can(Identity::everybody(), "view", $root)); + access::allow(identity::everybody(), "view", $root); + $this->assert_true(access::group_can(identity::everybody(), "view", $root)); } public function can_always_fails_on_unloaded_items_test() { $root = ORM::factory("item", 1); - access::allow(Identity::everybody(), "view", $root); - $this->assert_true(access::group_can(Identity::everybody(), "view", $root)); + access::allow(identity::everybody(), "view", $root); + $this->assert_true(access::group_can(identity::everybody(), "view", $root)); $bogus = ORM::factory("item", -1); - $this->assert_false(access::group_can(Identity::everybody(), "view", $bogus)); + $this->assert_false(access::group_can(identity::everybody(), "view", $bogus)); } public function cant_view_child_of_hidden_parent_test() { @@ -185,21 +185,21 @@ class Access_Helper_Test extends Unit_Test_Case { $album = album::create($root, rand(), "test album"); $root->reload(); - access::deny(Identity::everybody(), "view", $root); - access::reset(Identity::everybody(), "view", $album); + access::deny(identity::everybody(), "view", $root); + access::reset(identity::everybody(), "view", $album); $album->reload(); - $this->assert_false(access::group_can(Identity::everybody(), "view", $album)); + $this->assert_false(access::group_can(identity::everybody(), "view", $album)); } public function view_permissions_propagate_down_test() { $root = ORM::factory("item", 1); $album = album::create($root, rand(), "test album"); - access::allow(Identity::everybody(), "view", $root); - access::reset(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $root); + access::reset(identity::everybody(), "view", $album); $album->reload(); - $this->assert_true(access::group_can(Identity::everybody(), "view", $album)); + $this->assert_true(access::group_can(identity::everybody(), "view", $album)); } public function can_toggle_view_permissions_propagate_down_test() { @@ -214,18 +214,18 @@ class Access_Helper_Test extends Unit_Test_Case { $album3->reload(); $album4->reload(); - access::allow(Identity::everybody(), "view", $root); - access::deny(Identity::everybody(), "view", $album1); - access::reset(Identity::everybody(), "view", $album2); - access::reset(Identity::everybody(), "view", $album3); - access::reset(Identity::everybody(), "view", $album4); + access::allow(identity::everybody(), "view", $root); + access::deny(identity::everybody(), "view", $album1); + access::reset(identity::everybody(), "view", $album2); + access::reset(identity::everybody(), "view", $album3); + access::reset(identity::everybody(), "view", $album4); $album4->reload(); - $this->assert_false(access::group_can(Identity::everybody(), "view", $album4)); + $this->assert_false(access::group_can(identity::everybody(), "view", $album4)); - access::allow(Identity::everybody(), "view", $album1); + access::allow(identity::everybody(), "view", $album1); $album4->reload(); - $this->assert_true(access::group_can(Identity::everybody(), "view", $album4)); + $this->assert_true(access::group_can(identity::everybody(), "view", $album4)); } public function revoked_view_permissions_cant_be_allowed_lower_down_test() { @@ -234,29 +234,29 @@ class Access_Helper_Test extends Unit_Test_Case { $album2 = album::create($album1, rand(), "test album"); $root->reload(); - access::deny(Identity::everybody(), "view", $root); - access::allow(Identity::everybody(), "view", $album2); + access::deny(identity::everybody(), "view", $root); + access::allow(identity::everybody(), "view", $album2); $album1->reload(); - $this->assert_false(access::group_can(Identity::everybody(), "view", $album1)); + $this->assert_false(access::group_can(identity::everybody(), "view", $album1)); $album2->reload(); - $this->assert_false(access::group_can(Identity::everybody(), "view", $album2)); + $this->assert_false(access::group_can(identity::everybody(), "view", $album2)); } public function can_edit_item_test() { $root = ORM::factory("item", 1); - access::allow(Identity::everybody(), "edit", $root); - $this->assert_true(access::group_can(Identity::everybody(), "edit", $root)); + access::allow(identity::everybody(), "edit", $root); + $this->assert_true(access::group_can(identity::everybody(), "edit", $root)); } public function non_view_permissions_propagate_down_test() { $root = ORM::factory("item", 1); $album = album::create($root, rand(), "test album"); - access::allow(Identity::everybody(), "edit", $root); - access::reset(Identity::everybody(), "edit", $album); - $this->assert_true(access::group_can(Identity::everybody(), "edit", $album)); + access::allow(identity::everybody(), "edit", $root); + access::reset(identity::everybody(), "edit", $album); + $this->assert_true(access::group_can(identity::everybody(), "edit", $album)); } public function non_view_permissions_can_be_revoked_lower_down_test() { @@ -276,36 +276,36 @@ class Access_Helper_Test extends Unit_Test_Case { $outer->reload(); $inner->reload(); - access::allow(Identity::everybody(), "edit", $root); - access::deny(Identity::everybody(), "edit", $outer); - access::allow(Identity::everybody(), "edit", $inner); + access::allow(identity::everybody(), "edit", $root); + access::deny(identity::everybody(), "edit", $outer); + access::allow(identity::everybody(), "edit", $inner); // Outer album is not editable, inner one is. - $this->assert_false(access::group_can(Identity::everybody(), "edit", $outer_photo)); - $this->assert_true(access::group_can(Identity::everybody(), "edit", $inner_photo)); + $this->assert_false(access::group_can(identity::everybody(), "edit", $outer_photo)); + $this->assert_true(access::group_can(identity::everybody(), "edit", $inner_photo)); } public function i_can_edit_test() { // Create a new user that belongs to no groups - $user = Identity::create_user("access_test", "Access Test", ""); + $user = identity::create_user("access_test", "Access Test", ""); foreach ($user->groups as $group) { $user->remove($group); } $user->save(); - Session::set_active_user($user); + identity::set_active_user($user); // This user can't edit anything $root = ORM::factory("item", 1); $this->assert_false(access::can("edit", $root)); // Now add them to a group that has edit permission - $group = Identity::create_group("access_test"); + $group = identity::create_group("access_test"); $group->add($user); $group->save(); access::allow($group, "edit", $root); - $user = Identity::lookup_user($user->id); // reload() does not flush related columns - Session::set_active_user($user); + $user = identity::lookup_user($user->id); // reload() does not flush related columns + identity::set_active_user($user); // And verify that the user can edit. $this->assert_true(access::can("edit", $root)); @@ -317,16 +317,16 @@ class Access_Helper_Test extends Unit_Test_Case { $this->assert_false(file_exists($album->file_path() . "/.htaccess")); - access::deny(Identity::everybody(), "view", $album); + access::deny(identity::everybody(), "view", $album); $this->assert_true(file_exists($album->file_path() . "/.htaccess")); - access::allow(Identity::everybody(), "view", $album); + access::allow(identity::everybody(), "view", $album); $this->assert_false(file_exists($album->file_path() . "/.htaccess")); - access::deny(Identity::everybody(), "view", $album); + access::deny(identity::everybody(), "view", $album); $this->assert_true(file_exists($album->file_path() . "/.htaccess")); - access::reset(Identity::everybody(), "view", $album); + access::reset(identity::everybody(), "view", $album); $this->assert_false(file_exists($album->file_path() . "/.htaccess")); } @@ -338,44 +338,44 @@ class Access_Helper_Test extends Unit_Test_Case { $this->assert_false(file_exists($album->resize_path() . "/.htaccess")); $this->assert_false(file_exists($album->thumb_path() . "/.htaccess")); - access::deny(Identity::everybody(), "view_full", $album); + access::deny(identity::everybody(), "view_full", $album); $this->assert_true(file_exists($album->file_path() . "/.htaccess")); $this->assert_false(file_exists($album->resize_path() . "/.htaccess")); $this->assert_false(file_exists($album->thumb_path() . "/.htaccess")); - access::allow(Identity::everybody(), "view_full", $album); + access::allow(identity::everybody(), "view_full", $album); $this->assert_false(file_exists($album->file_path() . "/.htaccess")); $this->assert_false(file_exists($album->resize_path() . "/.htaccess")); $this->assert_false(file_exists($album->thumb_path() . "/.htaccess")); - access::deny(Identity::everybody(), "view_full", $album); + access::deny(identity::everybody(), "view_full", $album); $this->assert_true(file_exists($album->file_path() . "/.htaccess")); $this->assert_false(file_exists($album->resize_path() . "/.htaccess")); $this->assert_false(file_exists($album->thumb_path() . "/.htaccess")); - access::reset(Identity::everybody(), "view_full", $album); + access::reset(identity::everybody(), "view_full", $album); $this->assert_false(file_exists($album->file_path() . "/.htaccess")); $this->assert_false(file_exists($album->resize_path() . "/.htaccess")); $this->assert_false(file_exists($album->thumb_path() . "/.htaccess")); } public function moved_items_inherit_new_permissions_test() { - Session::set_active_user(Identity::lookup_user_by_name("admin")); + identity::set_active_user(identity::lookup_user_by_name("admin")); $root = ORM::factory("item", 1); $public_album = album::create($root, rand(), "public album"); $public_photo = photo::create($public_album, MODPATH . "gallery/images/gallery.png", "", ""); - access::allow(Identity::everybody(), "view", $public_album); + access::allow(identity::everybody(), "view", $public_album); $root->reload(); // Account for MPTT changes $private_album = album::create($root, rand(), "private album"); - access::deny(Identity::everybody(), "view", $private_album); + access::deny(identity::everybody(), "view", $private_album); $private_photo = photo::create($private_album, MODPATH . "gallery/images/gallery.png", "", ""); // Make sure that we now have a public photo and private photo. - $this->assert_true(access::group_can(Identity::everybody(), "view", $public_photo)); - $this->assert_false(access::group_can(Identity::everybody(), "view", $private_photo)); + $this->assert_true(access::group_can(identity::everybody(), "view", $public_photo)); + $this->assert_false(access::group_can(identity::everybody(), "view", $private_photo)); // Swap the photos item::move($public_photo, $private_album); @@ -391,7 +391,7 @@ class Access_Helper_Test extends Unit_Test_Case { $public_photo->reload(); // Make sure that the public_photo is now private, and the private_photo is now public. - $this->assert_false(access::group_can(Identity::everybody(), "view", $public_photo)); - $this->assert_true(access::group_can(Identity::everybody(), "view", $private_photo)); + $this->assert_false(access::group_can(identity::everybody(), "view", $public_photo)); + $this->assert_true(access::group_can(identity::everybody(), "view", $private_photo)); } } diff --git a/modules/gallery/tests/Albums_Controller_Test.php b/modules/gallery/tests/Albums_Controller_Test.php index fa46d924..b85b5258 100644 --- a/modules/gallery/tests/Albums_Controller_Test.php +++ b/modules/gallery/tests/Albums_Controller_Test.php @@ -45,7 +45,7 @@ class Albums_Controller_Test extends Unit_Test_Case { $_POST["csrf"] = access::csrf_token(); $_POST["slug"] = "new_name"; $_POST["_method"] = "put"; - access::allow(Identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", $root); ob_start(); $controller->_update($this->_album); @@ -69,7 +69,7 @@ class Albums_Controller_Test extends Unit_Test_Case { $_POST["name"] = "new name"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; - access::allow(Identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", $root); try { $controller->_update($this->_album); diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index fc01db91..a364423a 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -23,16 +23,16 @@ class Item_Helper_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $album = album::create($root, rand(), rand(), rand()); $item = self::_create_random_item($album); - Session::set_active_user(Identity::guest()); + identity::set_active_user(identity::guest()); // We can see the item when permissions are granted - access::allow(Identity::everybody(), "view", $album); + access::allow(identity::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(Identity::everybody(), "view", $album); + access::deny(identity::everybody(), "view", $album); $this->assert_equal( 0, ORM::factory("item")->viewable()->where("id", $item->id)->count_all()); diff --git a/modules/gallery/tests/Photos_Controller_Test.php b/modules/gallery/tests/Photos_Controller_Test.php index 59c3f78a..2e5d7fe3 100644 --- a/modules/gallery/tests/Photos_Controller_Test.php +++ b/modules/gallery/tests/Photos_Controller_Test.php @@ -31,7 +31,7 @@ class Photos_Controller_Test extends Unit_Test_Case { $root = ORM::factory("item", 1); $photo = photo::create( $root, MODPATH . "gallery/tests/test.jpg", "test.jpeg", - "test", "test", Session::active_user()->id, "slug"); + "test", "test", identity::active_user()->id, "slug"); $orig_name = $photo->name; $_POST["filename"] = "test.jpeg"; @@ -40,7 +40,7 @@ class Photos_Controller_Test extends Unit_Test_Case { $_POST["description"] = "new description"; $_POST["slug"] = "new-slug"; $_POST["csrf"] = access::csrf_token(); - access::allow(Identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", $root); ob_start(); $controller->_update($photo); @@ -64,7 +64,7 @@ class Photos_Controller_Test extends Unit_Test_Case { $_POST["name"] = "new name"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; - access::allow(Identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", $root); try { $controller->_update($photo); |