From 0e3327bca70623175791ee41085d55d0cb13fe5b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 3 Jan 2010 20:30:35 -0800 Subject: Simplify the REST API code. Here's what I did: 1) Simplify gallery_rest to return flat models, no children and do no validation for now. 2) Flatten the REST replies and use HTTP codes to indicate success/failure instead of additional status messages. 3) Use the message and error code support in the base Exception class, instead of brewing our own in Rest_Exception. 4) Get rid of rest::success() and rest::fail() -- we only need rest::reply() since all failures are covered by throwing an exception. 5) Get rid of /rest/access_key and just use /rest for authentication. 6) Inline and simplify rest::normalize_request since we only use it once 7) Change rest::set_active_user to succeed or throw an exception 8) Extract Rest_Exception::sendHeaders into rest::send_headers() Here's what's currently broken: 1) Data validation. There currently is none 2) Logging. That's gone too 3) image block and tag code is broken 4) Tests are broken 5) No movie support --- modules/gallery/tests/Gallery_Rest_Helper_Test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Gallery_Rest_Helper_Test.php b/modules/gallery/tests/Gallery_Rest_Helper_Test.php index cd0aabae..c5c8a890 100644 --- a/modules/gallery/tests/Gallery_Rest_Helper_Test.php +++ b/modules/gallery/tests/Gallery_Rest_Helper_Test.php @@ -136,7 +136,8 @@ class Gallery_Rest_Helper_Test extends Unit_Test_Case { try { gallery_rest::put($request); } catch (Rest_Exception $e) { - $this->assert_equal("400 Bad request", $e->getMessage()); + $this->assert_equal("Bad request", $e->getMessage()); + $this->assert_equal(400, $e->getCode()); } catch (Exception $e) { $this->assert_false(true, $e->__toString()); } -- cgit v1.2.3 From 6e73b08595c8fc3a2473eb38d6b51db558b21bb4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 17 Jan 2010 20:37:57 -0800 Subject: Mostly conver to model based validation. Not all tests pass yet. --- modules/gallery/tests/Access_Helper_Test.php | 110 +++++++++++---------------- 1 file changed, 44 insertions(+), 66 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index 084bfb47..ac41743a 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -40,8 +40,7 @@ class Access_Helper_Test extends Unit_Test_Case { } catch (Exception $e) { } // Reset some permissions that we mangle below - $root = ORM::factory("item", 1); - access::allow(identity::everybody(), "view", $root); + access::allow(identity::everybody(), "view", item::root()); } public function setup() { @@ -67,15 +66,14 @@ class Access_Helper_Test extends Unit_Test_Case { public function user_can_access_test() { $access_test = identity::create_group("access_test"); - $root = ORM::factory("item", 1); - access::allow($access_test, "view", $root); + access::allow($access_test, "view", item::root()); - $item = album::create($root, rand(), "test album"); + $item = test::random_album(); 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", "*****", "user@user.com"); foreach ($user->groups() as $group) { $user->remove($group); } @@ -86,13 +84,12 @@ class Access_Helper_Test extends Unit_Test_Case { } public function user_can_no_access_test() { - $root = ORM::factory("item", 1); - $item = album::create($root, rand(), "test album"); + $item = test::random_album(); 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", "*****", "user@user.com"); foreach ($user->groups() as $group) { $user->remove($group); } @@ -102,8 +99,7 @@ class Access_Helper_Test extends Unit_Test_Case { } public function adding_and_removing_items_adds_ands_removes_rows_test() { - $root = ORM::factory("item", 1); - $item = album::create($root, rand(), "test album"); + $item = test::random_album(); // New rows exist $this->assert_true(ORM::factory("access_cache")->where("item_id", "=", $item->id)->find()->loaded()); @@ -118,19 +114,16 @@ class Access_Helper_Test extends Unit_Test_Case { } public function new_photos_inherit_parent_permissions_test() { - $root = ORM::factory("item", 1); - - $album = album::create($root, rand(), "test album"); + $album = test::random_album(); access::allow(identity::everybody(), "view", $album); - $photo = photo::create($album, MODPATH . "gallery/images/gallery.png", "", ""); + $photo = test::random_photo($album); $this->assert_true($photo->__get("view_" . identity::everybody()->id)); } public function can_allow_deny_and_reset_intent_test() { - $root = ORM::factory("item", 1); - $album = album::create($root, rand(), "test album"); + $album = test::random_album(); $intent = ORM::factory("access_intent")->where("item_id", "=", $album->id)->find(); // Allow @@ -166,23 +159,21 @@ 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", item::root()); + $this->assert_true(access::group_can(identity::everybody(), "view", item::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", item::root()); + $this->assert_true(access::group_can(identity::everybody(), "view", item::root())); $bogus = ORM::factory("item", -1); $this->assert_false(access::group_can(identity::everybody(), "view", $bogus)); } public function cant_view_child_of_hidden_parent_test() { - $root = ORM::factory("item", 1); - $album = album::create($root, rand(), "test album"); + $root = item::root(); + $album = test::random_album(); $root->reload(); access::deny(identity::everybody(), "view", $root); @@ -193,28 +184,26 @@ class Access_Helper_Test extends Unit_Test_Case { } public function view_permissions_propagate_down_test() { - $root = ORM::factory("item", 1); - $album = album::create($root, rand(), "test album"); + $album = test::random_album(); - access::allow(identity::everybody(), "view", $root); + access::allow(identity::everybody(), "view", item::root()); access::reset(identity::everybody(), "view", $album); $album->reload(); $this->assert_true(access::group_can(identity::everybody(), "view", $album)); } public function can_toggle_view_permissions_propagate_down_test() { - $root = ORM::factory("item", 1); - $album1 = album::create($root, rand(), "test album"); - $album2 = album::create($album1, rand(), "test album"); - $album3 = album::create($album2, rand(), "test album"); - $album4 = album::create($album3, rand(), "test album"); + $album1 = test::random_album(item::root()); + $album2 = test::random_album($album1); + $album3 = test::random_album($album2); + $album4 = test::random_album($album3); $album1->reload(); $album2->reload(); $album3->reload(); $album4->reload(); - access::allow(identity::everybody(), "view", $root); + access::allow(identity::everybody(), "view", item::root()); access::deny(identity::everybody(), "view", $album1); access::reset(identity::everybody(), "view", $album2); access::reset(identity::everybody(), "view", $album3); @@ -229,9 +218,9 @@ class Access_Helper_Test extends Unit_Test_Case { } public function revoked_view_permissions_cant_be_allowed_lower_down_test() { - $root = ORM::factory("item", 1); - $album1 = album::create($root, rand(), "test album"); - $album2 = album::create($album1, rand(), "test album"); + $root = item::root(); + $album1 = test::random_album($root); + $album2 = test::random_album($album1); $root->reload(); access::deny(identity::everybody(), "view", $root); @@ -245,38 +234,30 @@ class Access_Helper_Test extends Unit_Test_Case { } public function can_edit_item_test() { - $root = ORM::factory("item", 1); + $root = item::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"); + $album = test::random_album(); - access::allow(identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", item::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() { - $root = ORM::factory("item", 1); - $outer = album::create($root, rand(), "test album"); - $outer_photo = ORM::factory("item"); - $outer_photo->type = "photo"; - $outer_photo->add_to_parent($outer); - access::add_item($outer_photo); - - $inner = album::create($outer, rand(), "test album"); - $inner_photo = ORM::factory("item"); - $inner_photo->type = "photo"; - $inner_photo->add_to_parent($inner); - access::add_item($inner_photo); + $outer = test::random_album(); + $outer_photo = test::random_photo($outer); + + $inner = test::random_album($outer); + $inner_photo = test::random_photo($inner); $outer->reload(); $inner->reload(); - access::allow(identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", item::root()); access::deny(identity::everybody(), "edit", $outer); access::allow(identity::everybody(), "edit", $inner); @@ -287,7 +268,7 @@ class Access_Helper_Test extends Unit_Test_Case { 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", "*****", "user@user.com"); foreach ($user->groups() as $group) { $user->remove($group); } @@ -295,7 +276,7 @@ class Access_Helper_Test extends Unit_Test_Case { identity::set_active_user($user); // This user can't edit anything - $root = ORM::factory("item", 1); + $root = item::root(); $this->assert_false(access::can("edit", $root)); // Now add them to a group that has edit permission @@ -312,8 +293,7 @@ class Access_Helper_Test extends Unit_Test_Case { } public function everybody_view_permission_maintains_htaccess_files_test() { - $root = ORM::factory("item", 1); - $album = album::create($root, rand(), "test album"); + $album = test::random_album(); $this->assert_false(file_exists($album->file_path() . "/.htaccess")); @@ -331,8 +311,7 @@ class Access_Helper_Test extends Unit_Test_Case { } public function everybody_view_full_permission_maintains_htaccess_files_test() { - $root = ORM::factory("item", 1); - $album = album::create($root, rand(), "test album"); + $album = test::random_album(); $this->assert_false(file_exists($album->file_path() . "/.htaccess")); $this->assert_false(file_exists($album->resize_path() . "/.htaccess")); @@ -362,16 +341,15 @@ class Access_Helper_Test extends Unit_Test_Case { public function moved_items_inherit_new_permissions_test() { 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", "", ""); + $public_album = test::random_album(); + $public_photo = test::random_photo($public_album); access::allow(identity::everybody(), "view", $public_album); - $root->reload(); // Account for MPTT changes + item::root()->reload(); // Account for MPTT changes - $private_album = album::create($root, rand(), "private album"); + $private_album = test::random_album(); access::deny(identity::everybody(), "view", $private_album); - $private_photo = photo::create($private_album, MODPATH . "gallery/images/gallery.png", "", ""); + $private_photo = test::random_photo($private_album); // Make sure that we now have a public photo and private photo. $this->assert_true(access::group_can(identity::everybody(), "view", $public_photo)); -- cgit v1.2.3 From 9ddb961a91f99ccc043981bbe8c8a661f9646563 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 17 Jan 2010 20:53:32 -0800 Subject: Partially updated for model based validation. --- modules/gallery/tests/Item_Model_Test.php | 74 ++++++++++--------------------- 1 file changed, 24 insertions(+), 50 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index bf5fca1a..a3f590a1 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -19,20 +19,13 @@ */ class Item_Model_Test extends Unit_Test_Case { public function saving_sets_created_and_updated_dates_test() { - $item = self::_create_random_item(); + $item = test::random_photo(); $this->assert_true(!empty($item->created)); $this->assert_true(!empty($item->updated)); } - private static function _create_random_item($root=null, $rand=null) { - $root = $root ? $root : ORM::factory("item", 1); - $rand = $rand ? $rand : rand(); - $item = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand); - return $item; - } - public function updating_doesnt_change_created_date_test() { - $item = self::_create_random_item(); + $item = test::random_photo(); // Force the creation date to something well known db::build() @@ -50,7 +43,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 = test::random_photo(); $item->reload(); $this->assert_same(0, $item->view_count); @@ -69,8 +62,7 @@ class Item_Model_Test extends Unit_Test_Case { } public function rename_photo_test() { - // Create a test photo - $item = self::_create_random_item(); + $item = test::random_photo(); file_put_contents($item->thumb_path(), "thumb"); file_put_contents($item->resize_path(), "resize"); @@ -93,10 +85,8 @@ class Item_Model_Test extends Unit_Test_Case { } public function rename_album_test() { - // Create an album with a photo in it - $root = ORM::factory("item", 1); - $album = album::create($root, rand(), rand(), rand()); - $photo = self::_create_random_item($album); + $album = test::random_album(); + $photo = test::random_photo($album); file_put_contents($photo->thumb_path(), "thumb"); file_put_contents($photo->resize_path(), "resize"); @@ -130,8 +120,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 = test::random_photo(); $new_name = rand() . "/"; @@ -146,8 +135,8 @@ class Item_Model_Test extends Unit_Test_Case { public function item_rename_fails_with_existing_name_test() { // Create a test photo - $item = self::_create_random_item(); - $item2 = self::_create_random_item(); + $item = test::random_photo(); + $item2 = test::random_photo(); $new_name = $item2->name; @@ -163,7 +152,7 @@ class Item_Model_Test extends Unit_Test_Case { } public function save_original_values_test() { - $item = self::_create_random_item(); + $item = test::random_photo_unsaved(); $item->title = "ORIGINAL_VALUE"; $item->save(); $item->title = "NEW_VALUE"; @@ -173,7 +162,7 @@ class Item_Model_Test extends Unit_Test_Case { } public function urls_are_rawurlencoded_test() { - $item = self::_create_random_item(); + $item = test::random_photo_unsaved(); $item->slug = "foo bar"; $item->name = "foo bar.jpg"; $item->save(); @@ -183,18 +172,16 @@ class Item_Model_Test extends Unit_Test_Case { } public function move_album_test() { - // Create an album with a photo in it - $root = ORM::factory("item", 1); - $album2 = album::create($root, rand(), rand(), rand()); - $album = album::create($album2, rand(), rand(), rand()); - $photo = self::_create_random_item($album); + $album2 = test::random_album(); + $album = test::random_album($album2); + $photo = test::random_photo($album); file_put_contents($photo->thumb_path(), "thumb"); file_put_contents($photo->resize_path(), "resize"); file_put_contents($photo->file_path(), "file"); // Now move the album - $album->move_to($root); + $album->move_to(item::root()); $photo->reload(); // Expected: @@ -212,11 +199,9 @@ class Item_Model_Test extends Unit_Test_Case { } public function move_photo_test() { - // Create an album with a photo in it - $root = ORM::factory("item", 1); - $album2 = album::create($root, rand(), rand(), rand()); - $album = album::create($album2, rand(), rand(), rand()); - $photo = self::_create_random_item($album); + $album2 = test::random_album(); + $album = test::random_album($album2); + $photo = test::random_photo($album); file_put_contents($photo->thumb_path(), "thumb"); file_put_contents($photo->resize_path(), "resize"); @@ -241,32 +226,23 @@ class Item_Model_Test extends Unit_Test_Case { } public function move_album_fails_invalid_target_test() { - // Create an album with a photo in it - $root = ORM::factory("item", 1); - $name = rand(); - $album = album::create($root, $name, $name, $name); - $source = album::create($album, $name, $name, $name); + $album = test::random_album(); + $source = test::random_album($album); try { - $source->move_to($root); + $source->move_to(item::root()); } catch (Exception $e) { // pass $this->assert_true(strpos($e->getMessage(), "INVALID_MOVE_TARGET_EXISTS") !== false, "incorrect exception."); return; } - - $this->assert_false(true, "Item_Model::rename should not accept / characters"); } public function move_photo_fails_invalid_target_test() { - // Create an album with a photo in it - $root = ORM::factory("item", 1); - $photo_name = rand(); - $photo1 = self::_create_random_item($root, $photo_name); - $name = rand(); - $album = album::create($root, $name, $name, $name); - $photo2 = self::_create_random_item($album, $photo_name); + $photo1 = test::random_photo(); + $album = test::random_album(); + $photo2 = test::random_photo($album); try { $photo2->move_to($root); @@ -276,7 +252,5 @@ class Item_Model_Test extends Unit_Test_Case { "incorrect exception."); return; } - - $this->assert_false(true, "Item_Model::rename should not accept / characters"); } } -- cgit v1.2.3 From b35a3c8b81cc4867fc6143b3a401937b20ea82e2 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 17 Jan 2010 20:54:08 -0800 Subject: Fix rename_photo_test(). --- modules/gallery/tests/Item_Model_Test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index a3f590a1..52e0f799 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -72,7 +72,8 @@ class Item_Model_Test extends Unit_Test_Case { $new_name = rand(); // Now rename it - $item->rename($new_name)->save(); + $item->name = $new_name; + $item->save(); // Expected: the name changed, the name is now baked into all paths, and all files were moved. $this->assert_equal($new_name, $item->name); -- cgit v1.2.3 From 710e472edc95dd4b7a192348e11b81636ac83e52 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 17 Jan 2010 21:03:15 -0800 Subject: Fix rename_album_test() --- modules/gallery/tests/Item_Model_Test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 52e0f799..a2720f7d 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -88,6 +88,7 @@ class Item_Model_Test extends Unit_Test_Case { public function rename_album_test() { $album = test::random_album(); $photo = test::random_photo($album); + $album->reload(); file_put_contents($photo->thumb_path(), "thumb"); file_put_contents($photo->resize_path(), "resize"); @@ -98,7 +99,8 @@ class Item_Model_Test extends Unit_Test_Case { $new_album_name = rand(); // Now rename the album - $album->rename($new_album_name)->save(); + $album->name = $new_album_name; + $album->save(); $photo->reload(); // Expected: -- cgit v1.2.3 From 06541f0e2a5cb9ee78b6b1553dd522dcc33a1b3d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 17 Jan 2010 21:49:48 -0800 Subject: Fix item_rename_fails_with_existing_name_test() -- broken because of http://dev.kohanaphp.com/issues/2504 --- modules/gallery/tests/Item_Model_Test.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index a2720f7d..c4e150a6 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -141,17 +141,16 @@ class Item_Model_Test extends Unit_Test_Case { $item = test::random_photo(); $item2 = test::random_photo(); - $new_name = $item2->name; - try { - $item->rename($new_name)->save(); - } catch (Exception $e) { - // pass - $this->assert_true(strpos($e->getMessage(), "INVALID_RENAME_FILE_EXISTS") !== false, - "incorrect exception."); + $item->name = $item2->name; + $item->validate(); // @todo: switch this to save() once + // http://dev.kohanaphp.com/issues/2504 is fixed. + } catch (ORM_Validation_Exception $e) { + $this->assert_true(in_array("conflict", $e->validation->errors())); return; } - $this->assert_false(true, "Item_Model::rename should fail."); + + $this->assert_false(true, "rename should conflict"); } public function save_original_values_test() { -- cgit v1.2.3 From 31ecb009bac2d9177329aafb9596fbfa65bd6a04 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 17 Jan 2010 23:45:18 -0800 Subject: Get rid of urls_are_rawurlencoded_test -- it's no longer necessary since we can't have unsafe slugs. Add basic_validation_test. --- modules/gallery/tests/Item_Model_Test.php | 40 +++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index c4e150a6..ea6c2af6 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -163,16 +163,6 @@ class Item_Model_Test extends Unit_Test_Case { $this->assert_same("NEW_VALUE", $item->title); } - public function urls_are_rawurlencoded_test() { - $item = test::random_photo_unsaved(); - $item->slug = "foo bar"; - $item->name = "foo bar.jpg"; - $item->save(); - - $this->assert_equal("foo%20bar", $item->relative_url()); - $this->assert_equal("foo%20bar.jpg", $item->relative_path()); - } - public function move_album_test() { $album2 = test::random_album(); $album = test::random_album($album2); @@ -255,4 +245,34 @@ class Item_Model_Test extends Unit_Test_Case { return; } } + + public function basic_validation_test() { + $item = ORM::factory("item"); + $item->album_cover_item_id = rand(); // invalid + $item->description = str_repeat("x", 70000); // invalid + $item->name = null; + $item->parent_id = rand(); + $item->slug = null; + $item->sort_column = "bogus"; + $item->sort_order = "bogus"; + $item->title = null; + $item->type = "bogus"; + try { + $item->save(); + } catch (ORM_Validation_Exception $e) { + $this->assert_same(array("description" => "length", + "name" => "required", + "slug" => "required", + "title" => "required", + "album_cover_item_id" => "invalid_item", + "parent_id" => "invalid", + "sort_column" => "invalid", + "sort_order" => "invalid", + "type" => "invalid"), + $e->validation->errors()); + return; + } + + $this->assert_false(true, "Shouldn't get here"); + } } -- cgit v1.2.3 From 53735f6b166fe823f5606e6f3cf527d98105593c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 17 Jan 2010 23:50:42 -0800 Subject: Convert a $root to item::root() to fix a test. --- modules/gallery/tests/Item_Model_Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index ea6c2af6..c1df70c6 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -237,7 +237,7 @@ class Item_Model_Test extends Unit_Test_Case { $photo2 = test::random_photo($album); try { - $photo2->move_to($root); + $photo2->move_to(item::root()); } catch (Exception $e) { // pass $this->assert_true(strpos($e->getMessage(), "INVALID_MOVE_TARGET_EXISTS") !== false, -- cgit v1.2.3 From dc286cc2bd96a70505c16487905b4aae761feeff Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 09:00:14 -0800 Subject: Add a test to verify that bug #2504 is still around. When this test starts failing, the bug is fixed and we can go fix our code that works around it. --- modules/gallery/tests/Kohana_Bug_Test.php | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 modules/gallery/tests/Kohana_Bug_Test.php (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Kohana_Bug_Test.php b/modules/gallery/tests/Kohana_Bug_Test.php new file mode 100644 index 00000000..61f5d69e --- /dev/null +++ b/modules/gallery/tests/Kohana_Bug_Test.php @@ -0,0 +1,38 @@ +name = rand(); + $group->save(); // this save works + + try { + $group->name = null; // now I change to an illegal value + $group->save(); // this passes, but it shouldn't. My model is broken! + + // This is the normal state when the bug is not fixed. + } catch (ORM_Validation_Exception $e) { + // When this triggers, the bug is fixed. Find any references to ticket #2504 in the code + // and update those accordingly + $this->assert_true(false, "Bug #2504 has been fixed"); + } + } +} -- cgit v1.2.3 From 92ed5d45e6e81b39f4d6b8621c36b597a1b315d8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 12:56:49 -0800 Subject: In item_rename_fails_with_existing_name_test switch validate() to save() now that Kohana ticket #2504 is resolved. --- modules/gallery/tests/Item_Model_Test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index b41740d6..12f69a34 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -143,8 +143,7 @@ class Item_Model_Test extends Unit_Test_Case { try { $item->name = $item2->name; - $item->validate(); // @todo: switch this to save() once - // http://dev.kohanaphp.com/issues/2504 is fixed. + $item->save(); } catch (ORM_Validation_Exception $e) { $this->assert_true(in_array("conflict", $e->validation->errors())); return; -- cgit v1.2.3 From b93000c0ce6fc2fd90df0e4a3e427d15cb262117 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 17:20:12 -0800 Subject: Kohana ticket #2504 is resolved, so this test is no longer necessary. --- modules/gallery/tests/Kohana_Bug_Test.php | 38 ------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 modules/gallery/tests/Kohana_Bug_Test.php (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Kohana_Bug_Test.php b/modules/gallery/tests/Kohana_Bug_Test.php deleted file mode 100644 index 61f5d69e..00000000 --- a/modules/gallery/tests/Kohana_Bug_Test.php +++ /dev/null @@ -1,38 +0,0 @@ -name = rand(); - $group->save(); // this save works - - try { - $group->name = null; // now I change to an illegal value - $group->save(); // this passes, but it shouldn't. My model is broken! - - // This is the normal state when the bug is not fixed. - } catch (ORM_Validation_Exception $e) { - // When this triggers, the bug is fixed. Find any references to ticket #2504 in the code - // and update those accordingly - $this->assert_true(false, "Bug #2504 has been fixed"); - } - } -} -- cgit v1.2.3 From 38c13760afaae693af245e814b6bbe76c20fcae4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 20:14:09 -0800 Subject: Switch to using test::random_name() to avoid integer names. Fix up rename_photo_test. --- modules/gallery/tests/Item_Model_Test.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 12f69a34..542cf371 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -63,16 +63,14 @@ class Item_Model_Test extends Unit_Test_Case { public function rename_photo_test() { $item = test::random_photo(); + $original_name = $item->name; file_put_contents($item->thumb_path(), "thumb"); file_put_contents($item->resize_path(), "resize"); file_put_contents($item->file_path(), "file"); - $original_name = $item->name; - $new_name = rand(); - // Now rename it - $item->name = $new_name; + $item->name = ($new_name = test::random_name($item)); $item->save(); // Expected: the name changed, the name is now baked into all paths, and all files were moved. @@ -96,7 +94,7 @@ class Item_Model_Test extends Unit_Test_Case { $original_album_name = $album->name; $original_photo_name = $photo->name; - $new_album_name = rand(); + $new_album_name = test::random_name(); // Now rename the album $album->name = $new_album_name; @@ -125,7 +123,7 @@ class Item_Model_Test extends Unit_Test_Case { public function item_rename_wont_accept_slash_test() { $item = test::random_photo(); - $new_name = rand() . "/"; + $new_name = test::random_name() . "/"; try { $item->rename($new_name)->save(); -- cgit v1.2.3 From 677fb080026612725d9ed317b5ff6732e00f6514 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 21:12:26 -0800 Subject: Updated tests to match what the expected new API for moving items. Now to move an item, you just change its parent_id. --- modules/gallery/tests/Item_Model_Test.php | 82 +++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 26 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 542cf371..b2193e90 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -127,9 +127,8 @@ class Item_Model_Test extends Unit_Test_Case { try { $item->rename($new_name)->save(); - } catch (Exception $e) { - // pass - return; + } catch (ORM_Validation_Exception $e) { + $this->assert_equals(array("name" => "no_slashes"), $e->validation->errors()); } $this->assert_false(true, "Item_Model::rename should not accept / characters"); } @@ -170,14 +169,18 @@ class Item_Model_Test extends Unit_Test_Case { file_put_contents($photo->file_path(), "file"); // Now move the album - $album->move_to(item::root()); + $album->parent_id = item::root()->id; + $album->save(); $photo->reload(); // Expected: - // * the album dirs are all moved + // * album is not inside album2 anymore // * the photo's paths are all inside the albums paths // * the photo files are all still intact and accessible + $this->assert_same(null, strpos($album->relative_path(), $album2->relative_path()), + $album2->relative_path() . " should not be in: " . $album->relative_path()); + $this->assert_same(0, strpos($photo->file_path(), $album->file_path())); $this->assert_same(0, strpos($photo->thumb_path(), dirname($album->thumb_path()))); $this->assert_same(0, strpos($photo->resize_path(), dirname($album->resize_path()))); @@ -188,26 +191,26 @@ class Item_Model_Test extends Unit_Test_Case { } public function move_photo_test() { + $album1 = test::random_album(); + $photo = test::random_photo($album1); + $album2 = test::random_album(); - $album = test::random_album($album2); - $photo = test::random_photo($album); file_put_contents($photo->thumb_path(), "thumb"); file_put_contents($photo->resize_path(), "resize"); file_put_contents($photo->file_path(), "file"); - // Now move the album - $photo->move_to($album2); - $photo->reload(); + // Now move the photo + $photo->parent_id = $album2->id; + $photo->save(); // Expected: - // * the album dirs are all moved - // * the photo's paths are all inside the albums paths + // * the photo's paths are inside the album2 not album1 // * the photo files are all still intact and accessible - $this->assert_same(0, strpos($photo->file_path(), $album->file_path())); - $this->assert_same(0, strpos($photo->thumb_path(), dirname($album->thumb_path()))); - $this->assert_same(0, strpos($photo->resize_path(), dirname($album->resize_path()))); + $this->assert_same(0, strpos($photo->file_path(), $album2->file_path())); + $this->assert_same(0, strpos($photo->thumb_path(), dirname($album2->thumb_path()))); + $this->assert_same(0, strpos($photo->resize_path(), dirname($album2->resize_path()))); $this->assert_equal("thumb", file_get_contents($photo->thumb_path())); $this->assert_equal("resize", file_get_contents($photo->resize_path())); @@ -216,33 +219,60 @@ class Item_Model_Test extends Unit_Test_Case { public function move_album_fails_invalid_target_test() { $album = test::random_album(); - $source = test::random_album($album); + $source = test::random_album_unsaved($album); + $source->name = $album->name; + $source->save(); + + // $source and $album have the same name, so if we move $source into the root they should + // conflict. try { - $source->move_to(item::root()); - } catch (Exception $e) { - // pass - $this->assert_true(strpos($e->getMessage(), "INVALID_MOVE_TARGET_EXISTS") !== false, - "incorrect exception."); - return; + $source->parent_id = item::root()->id; + $source->save(); + $this->assert_true(false, "Shouldn't get here"); + } catch (ORM_Validation_Exception $e) { + $this->assert_equal( + array("name" => "conflict", "slug" => "conflict"), $e->validation->errors()); } } public function move_photo_fails_invalid_target_test() { $photo1 = test::random_photo(); $album = test::random_album(); - $photo2 = test::random_photo($album); + $photo2 = test::random_photo_unsaved($album); + $photo2->name = $photo1->name; + $photo2->save(); + + // $photo1 and $photo2 have the same name, so if we move $photo1 into the root they should + // conflict. try { - $photo2->move_to(item::root()); + $photo2->parent_id = item::root()->id; + $photo2->save(); + $this->assert_true(false, "Shouldn't get here"); } catch (Exception $e) { // pass - $this->assert_true(strpos($e->getMessage(), "INVALID_MOVE_TARGET_EXISTS") !== false, - "incorrect exception."); + $this->assert_equal( + array("name" => "conflict", "slug" => "conflict"), $e->validation->errors()); return; } } + public function move_album_inside_descendent_fails_test() { + $album = test::random_album(); + $album2 = test::random_album($album); + $album3 = test::random_album($album2); + + try { + $album->parent_id = $album3->id; + $album->save(); + $this->assert_true(false, "Shouldn't get here"); + } catch (ORM_Validation_Exception $e) { + $this->assert_equal(array("parent_id" => "invalid"), $e->validation->errors()); + } + } + + public function basic_validation_test() { $item = ORM::factory("item"); $item->album_cover_item_id = rand(); // invalid -- cgit v1.2.3 From b4e6834a28e557c3143f5f3cc91144d1565c18f0 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 21:14:43 -0800 Subject: Added move_album_fails_wrong_target_type_test() --- modules/gallery/tests/Item_Model_Test.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index b2193e90..abe872d2 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -217,7 +217,7 @@ class Item_Model_Test extends Unit_Test_Case { $this->assert_equal("file", file_get_contents($photo->file_path())); } - public function move_album_fails_invalid_target_test() { + public function move_album_fails_conflicting_target_test() { $album = test::random_album(); $source = test::random_album_unsaved($album); $source->name = $album->name; @@ -236,7 +236,23 @@ class Item_Model_Test extends Unit_Test_Case { } } - public function move_photo_fails_invalid_target_test() { + public function move_album_fails_wrong_target_type_test() { + $album = test::random_album(); + $photo = test::random_photo(); + + // $source and $album have the same name, so if we move $source into the root they should + // conflict. + + try { + $album->parent_id = $photo->id; + $album->save(); + $this->assert_true(false, "Shouldn't get here"); + } catch (ORM_Validation_Exception $e) { + $this->assert_equal(array("parent_id" => "invalid"), $e->validation->errors()); + } + } + + public function move_photo_fails_conflicting_target_test() { $photo1 = test::random_photo(); $album = test::random_album(); $photo2 = test::random_photo_unsaved($album); -- cgit v1.2.3 From cfc0f3d0c0935839e9eedd11322e35e9baaca0df Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 22:51:40 -0800 Subject: Minor test cleanup. --- modules/gallery/tests/Item_Model_Test.php | 48 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index abe872d2..5a59e6d0 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -122,15 +122,14 @@ class Item_Model_Test extends Unit_Test_Case { public function item_rename_wont_accept_slash_test() { $item = test::random_photo(); - - $new_name = test::random_name() . "/"; - try { - $item->rename($new_name)->save(); + $item->name = test::random_name() . "/"; + $item->save(); } catch (ORM_Validation_Exception $e) { - $this->assert_equals(array("name" => "no_slashes"), $e->validation->errors()); + $this->assert_equal(array("name" => "no_slashes"), $e->validation->errors()); + return; } - $this->assert_false(true, "Item_Model::rename should not accept / characters"); + $this->assert_true(false, "Shouldn't get here"); } public function item_rename_fails_with_existing_name_test() { @@ -161,16 +160,16 @@ class Item_Model_Test extends Unit_Test_Case { public function move_album_test() { $album2 = test::random_album(); - $album = test::random_album($album2); - $photo = test::random_photo($album); + $album1 = test::random_album($album2); + $photo = test::random_photo($album1); file_put_contents($photo->thumb_path(), "thumb"); file_put_contents($photo->resize_path(), "resize"); file_put_contents($photo->file_path(), "file"); // Now move the album - $album->parent_id = item::root()->id; - $album->save(); + $album1->parent_id = item::root()->id; + $album1->save(); $photo->reload(); // Expected: @@ -178,12 +177,10 @@ class Item_Model_Test extends Unit_Test_Case { // * the photo's paths are all inside the albums paths // * the photo files are all still intact and accessible - $this->assert_same(null, strpos($album->relative_path(), $album2->relative_path()), - $album2->relative_path() . " should not be in: " . $album->relative_path()); - - $this->assert_same(0, strpos($photo->file_path(), $album->file_path())); - $this->assert_same(0, strpos($photo->thumb_path(), dirname($album->thumb_path()))); - $this->assert_same(0, strpos($photo->resize_path(), dirname($album->resize_path()))); + $this->assert_false(test::starts_with($album2->file_path(), $album1->file_path())); + $this->assert_true(test::starts_with($photo->file_path(), $album1->file_path())); + $this->assert_true(test::starts_with($photo->thumb_path(), dirname($album1->thumb_path()))); + $this->assert_true(test::starts_with($photo->resize_path(), dirname($album1->resize_path()))); $this->assert_equal("thumb", file_get_contents($photo->thumb_path())); $this->assert_equal("resize", file_get_contents($photo->resize_path())); @@ -229,11 +226,12 @@ class Item_Model_Test extends Unit_Test_Case { try { $source->parent_id = item::root()->id; $source->save(); - $this->assert_true(false, "Shouldn't get here"); } catch (ORM_Validation_Exception $e) { $this->assert_equal( array("name" => "conflict", "slug" => "conflict"), $e->validation->errors()); + return; } + $this->assert_true(false, "Shouldn't get here"); } public function move_album_fails_wrong_target_type_test() { @@ -246,10 +244,11 @@ class Item_Model_Test extends Unit_Test_Case { try { $album->parent_id = $photo->id; $album->save(); - $this->assert_true(false, "Shouldn't get here"); } catch (ORM_Validation_Exception $e) { $this->assert_equal(array("parent_id" => "invalid"), $e->validation->errors()); + return; } + $this->assert_true(false, "Shouldn't get here"); } public function move_photo_fails_conflicting_target_test() { @@ -265,27 +264,28 @@ class Item_Model_Test extends Unit_Test_Case { try { $photo2->parent_id = item::root()->id; $photo2->save(); - $this->assert_true(false, "Shouldn't get here"); } catch (Exception $e) { // pass $this->assert_equal( array("name" => "conflict", "slug" => "conflict"), $e->validation->errors()); return; } + $this->assert_true(false, "Shouldn't get here"); } public function move_album_inside_descendent_fails_test() { - $album = test::random_album(); - $album2 = test::random_album($album); + $album1 = test::random_album(); + $album2 = test::random_album($album1); $album3 = test::random_album($album2); try { - $album->parent_id = $album3->id; - $album->save(); - $this->assert_true(false, "Shouldn't get here"); + $album1->parent_id = $album3->id; + $album1->save(); } catch (ORM_Validation_Exception $e) { $this->assert_equal(array("parent_id" => "invalid"), $e->validation->errors()); + return; } + $this->assert_true(false, "Shouldn't get here"); } -- cgit v1.2.3 From 9eedf5c2072ee508d539e3e25ce4f02eff746476 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 22:55:16 -0800 Subject: switch to test::starts_with(). --- modules/gallery/tests/Item_Model_Test.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 5a59e6d0..5294836d 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -111,9 +111,9 @@ class Item_Model_Test extends Unit_Test_Case { $this->assert_equal($new_album_name, basename(dirname($album->thumb_path()))); $this->assert_equal($new_album_name, basename(dirname($album->resize_path()))); - $this->assert_same(0, strpos($photo->file_path(), $album->file_path())); - $this->assert_same(0, strpos($photo->thumb_path(), dirname($album->thumb_path()))); - $this->assert_same(0, strpos($photo->resize_path(), dirname($album->resize_path()))); + $this->assert_true(test::starts_with($photo->file_path(), $album->file_path())); + $this->assert_true(test::starts_with($photo->thumb_path(), dirname($album->thumb_path()))); + $this->assert_true(test::starts_with($photo->resize_path(), dirname($album->resize_path()))); $this->assert_equal("thumb", file_get_contents($photo->thumb_path())); $this->assert_equal("resize", file_get_contents($photo->resize_path())); @@ -205,9 +205,9 @@ class Item_Model_Test extends Unit_Test_Case { // * the photo's paths are inside the album2 not album1 // * the photo files are all still intact and accessible - $this->assert_same(0, strpos($photo->file_path(), $album2->file_path())); - $this->assert_same(0, strpos($photo->thumb_path(), dirname($album2->thumb_path()))); - $this->assert_same(0, strpos($photo->resize_path(), dirname($album2->resize_path()))); + $this->assert_true(test::starts_with($photo->file_path(), $album2->file_path())); + $this->assert_true(test::starts_with($photo->thumb_path(), dirname($album2->thumb_path()))); + $this->assert_true(test::starts_with($photo->resize_path(), dirname($album2->resize_path()))); $this->assert_equal("thumb", file_get_contents($photo->thumb_path())); $this->assert_equal("resize", file_get_contents($photo->resize_path())); -- cgit v1.2.3 From cc61e7a3e0a0004196617ffacc6519e9b6d79139 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 23:11:02 -0800 Subject: Update for model based validation. Use test helper. Reduce the code size greatly! --- modules/gallery/tests/ORM_MPTT_Test.php | 148 ++++++++++---------------------- 1 file changed, 47 insertions(+), 101 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php index 69b6bea9..30adf2a0 100644 --- a/modules/gallery/tests/ORM_MPTT_Test.php +++ b/modules/gallery/tests/ORM_MPTT_Test.php @@ -19,19 +19,8 @@ */ class ORM_MPTT_Test extends Unit_Test_Case { - private function create_item_and_add_to_parent($parent) { - $album = album::create($parent, rand(), "test album"); - return $album; - } - public function add_to_parent_test() { - $root = ORM::factory("item", 1); - $album = ORM::factory("item"); - $album->type = "album"; - $album->rand_key = ((float)mt_rand()) / (float)mt_getrandmax(); - $album->sort_column = "weight"; - $album->sort_order = "ASC"; - $album->add_to_parent($root); + $album = test::random_album(); $this->assert_equal($album->parent()->right_ptr - 2, $album->left_ptr); $this->assert_equal($album->parent()->right_ptr - 1, $album->right_ptr); @@ -40,12 +29,11 @@ class ORM_MPTT_Test extends Unit_Test_Case { } public function add_hierarchy_test() { - $root = ORM::factory("item", 1); - $album1 = self::create_item_and_add_to_parent($root); - $album1_1 = self::create_item_and_add_to_parent($album1); - $album1_2 = self::create_item_and_add_to_parent($album1); - $album1_1_1 = self::create_item_and_add_to_parent($album1_1); - $album1_1_2 = self::create_item_and_add_to_parent($album1_1); + $album1 = test::random_album(); + $album1_1 = test::random_album($album1); + $album1_2 = test::random_album($album1); + $album1_1_1 = test::random_album($album1_1); + $album1_1_2 = test::random_album($album1_1); $album1->reload(); $this->assert_equal(9, $album1->right_ptr - $album1->left_ptr); @@ -55,12 +43,11 @@ class ORM_MPTT_Test extends Unit_Test_Case { } public function delete_hierarchy_test() { - $root = ORM::factory("item", 1); - $album1 = self::create_item_and_add_to_parent($root); - $album1_1 = self::create_item_and_add_to_parent($album1); - $album1_2 = self::create_item_and_add_to_parent($album1); - $album1_1_1 = self::create_item_and_add_to_parent($album1_1); - $album1_1_2 = self::create_item_and_add_to_parent($album1_1); + $album1 = test::random_album(); + $album1_1 = test::random_album($album1); + $album1_2 = test::random_album($album1); + $album1_1_1 = test::random_album($album1_1); + $album1_1_2 = test::random_album($album1_1); $album1_1->delete(); $album1->reload(); @@ -70,12 +57,11 @@ class ORM_MPTT_Test extends Unit_Test_Case { } public function move_to_test() { - $root = ORM::factory("item", 1); - $album1 = album::create($root, "move_to_test_1", "move_to_test_1"); - $album1_1 = album::create($album1, "move_to_test_1_1", "move_to_test_1_1"); - $album1_2 = album::create($album1, "move_to_test_1_2", "move_to_test_1_2"); - $album1_1_1 = album::create($album1_1, "move_to_test_1_1_1", "move_to_test_1_1_1"); - $album1_1_2 = album::create($album1_1, "move_to_test_1_1_2", "move_to_test_1_1_2"); + $album1 = test::random_album(); + $album1_1 = test::random_album($album1); + $album1_2 = test::random_album($album1); + $album1_1_1 = test::random_album($album1_1); + $album1_1_2 = test::random_album($album1_1); $album1_2->reload(); $album1_1_1->reload(); @@ -89,39 +75,37 @@ class ORM_MPTT_Test extends Unit_Test_Case { $this->assert_equal(3, $album1_2->right_ptr - $album1_2->left_ptr); $this->assert_equal( - array($album1_1_2->id => "move_to_test_1_1_2"), + array($album1_1_2->id => $album1_1_2->name), $album1_1->children()->select_list()); $this->assert_equal( - array($album1_1_1->id => "move_to_test_1_1_1"), + array($album1_1_1->id => $album1_1_1->name), $album1_2->children()->select_list()); } public function cant_move_parent_into_own_subtree_test() { - $album1 = album::create(item::root(), "move_to_test", "move_to_test"); - $album2 = album::create($album1, "move_to_test", "move_to_test"); - $album3 = album::create($album2, "move_to_test", "move_to_test"); + $album1 = test::random_album(item::root()); + $album2 = test::random_album($album1); + $album3 = test::random_album($album2); try { $album1->move_to($album3); - $self->assert_true(false, "We should be unable to move an item inside its own hierarchy"); + $this->assert_true(false, "We should be unable to move an item inside its own hierarchy"); } catch (Exception $e) { // pass } } public function parent_test() { - $root = ORM::factory("item", 1); - $album = self::create_item_and_add_to_parent($root); + $album = test::random_album(); $parent = ORM::factory("item", 1); $this->assert_equal($parent->id, $album->parent()->id); } public function parents_test() { - $root = ORM::factory("item", 1); - $outer = self::create_item_and_add_to_parent($root); - $inner = self::create_item_and_add_to_parent($outer); + $outer = test::random_album(); + $inner = test::random_album($outer); $parent_ids = array(); foreach ($inner->parents() as $parent) { @@ -131,10 +115,9 @@ class ORM_MPTT_Test extends Unit_Test_Case { } public function children_test() { - $root = ORM::factory("item", 1); - $outer = self::create_item_and_add_to_parent($root); - $inner1 = self::create_item_and_add_to_parent($outer); - $inner2 = self::create_item_and_add_to_parent($outer); + $outer = test::random_album(); + $inner1 = test::random_album($outer); + $inner2 = test::random_album($outer); $child_ids = array(); foreach ($outer->children() as $child) { @@ -144,48 +127,27 @@ class ORM_MPTT_Test extends Unit_Test_Case { } public function children_limit_test() { - $root = ORM::factory("item", 1); - $outer = self::create_item_and_add_to_parent($root); - $inner1 = self::create_item_and_add_to_parent($outer); - $inner2 = self::create_item_and_add_to_parent($outer); + $outer = test::random_album(); + $inner1 = test::random_album($outer); + $inner2 = test::random_album($outer); $this->assert_equal(array($inner2->id => $inner2->name), $outer->children(1, 1)->select_list('id')); } public function children_count_test() { - $root = ORM::factory("item", 1); - $outer = self::create_item_and_add_to_parent($root); - $inner1 = self::create_item_and_add_to_parent($outer); - $inner2 = self::create_item_and_add_to_parent($outer); + $outer = test::random_album(); + $inner1 = test::random_album($outer); + $inner2 = test::random_album($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->rand_key = ((float)mt_rand()) / (float)mt_getrandmax(); - $parent->sort_column = "weight"; - $parent->sort_order = "ASC"; - $parent->add_to_parent($root); - - $photo = ORM::factory("item"); - $photo->type = "photo"; - $photo->add_to_parent($parent); - - $album1 = ORM::factory("item"); - $album1->type = "album"; - $album1->rand_key = ((float)mt_rand()) / (float)mt_getrandmax(); - $album1->sort_column = "weight"; - $album1->sort_order = "ASC"; - $album1->add_to_parent($parent); - - $photo1 = ORM::factory("item"); - $photo1->type = "photo"; - $photo1->add_to_parent($album1); + $parent = test::random_album(); + $photo = test::random_photo($parent); + $album1 = test::random_album($parent); + $photo1 = test::random_photo($album1); $parent->reload(); @@ -195,36 +157,20 @@ class ORM_MPTT_Test extends Unit_Test_Case { } public function descendant_limit_test() { - $root = ORM::factory("item", 1); - - $parent = self::create_item_and_add_to_parent($root); - $album1 = self::create_item_and_add_to_parent($parent); - $album2 = self::create_item_and_add_to_parent($parent); - $album3 = self::create_item_and_add_to_parent($parent); - + $parent = test::random_album(); + $album1 = test::random_album($parent); + $album2 = test::random_album($parent); + $album3 = test::random_album($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($root); - - $photo = ORM::factory("item"); - $photo->type = "photo"; - $photo->add_to_parent($parent); - - $album1 = ORM::factory("item"); - $album1->type = "album"; - $album1->add_to_parent($parent); - - $photo1 = ORM::factory("item"); - $photo1->type = "photo"; - $photo1->add_to_parent($album1); - + $parent = test::random_album(); + $photo = test::random_photo($parent); + $album1 = test::random_album($parent); + $photo1 = test::random_photo($album1); $parent->reload(); $this->assert_equal(3, $parent->descendants_count()); -- cgit v1.2.3 From c6bd3c5b2629012a7c100658705a254bda19877b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 23:23:31 -0800 Subject: Updated for model based validation. change_album_no_csrf_fails_test() had been broken since we got rid of REST_Controller, but was poorly written so we didn't realize it. Boo. --- modules/gallery/tests/Albums_Controller_Test.php | 32 ++++++++++-------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Albums_Controller_Test.php b/modules/gallery/tests/Albums_Controller_Test.php index 4d8935cd..8ba2c7bc 100644 --- a/modules/gallery/tests/Albums_Controller_Test.php +++ b/modules/gallery/tests/Albums_Controller_Test.php @@ -24,16 +24,11 @@ class Albums_Controller_Test extends Unit_Test_Case { public function teardown() { list($_POST, $_SERVER) = $this->_save; - if (isset($this->_album)) { - $this->_album->delete(); - } } public function change_album_test() { $controller = new Albums_Controller(); - $root = ORM::factory("item", 1); - $this->_album = album::create($root, "test", "test", "test"); - $orig_name = $this->_album->name; + $album = test::random_album(); // Randomize to avoid conflicts. $new_dirname = "new_name_" . rand(); @@ -45,36 +40,35 @@ class Albums_Controller_Test extends Unit_Test_Case { $_POST["direction"] = "ASC"; $_POST["csrf"] = access::csrf_token(); $_POST["slug"] = "new-name"; - access::allow(identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", item::root()); ob_start(); - $controller->update($this->_album->id); - $this->_album->reload(); + $controller->update($album->id); + $album->reload(); $results = ob_get_contents(); ob_end_clean(); - $this->assert_equal( - json_encode(array("result" => "success")), - $results); - $this->assert_equal($new_dirname, $this->_album->name); - $this->assert_equal("new title", $this->_album->title); - $this->assert_equal("new description", $this->_album->description); + $this->assert_equal(json_encode(array("result" => "success")), $results); + $this->assert_equal($new_dirname, $album->name); + $this->assert_equal("new title", $album->title); + $this->assert_equal("new description", $album->description); } public function change_album_no_csrf_fails_test() { $controller = new Albums_Controller(); - $root = ORM::factory("item", 1); - $this->_album = album::create($root, "test", "test", "test"); + $album = test::random_album(); + $_POST["name"] = "new name"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; - access::allow(identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", item::root()); try { - $controller->_update($this->_album); + $controller->update($album->id); $this->assert_true(false, "This should fail"); } catch (Exception $e) { // pass + $this->assert_same("@todo FORBIDDEN", $e->getMessage()); } } } -- cgit v1.2.3 From f0215052086f2031ddaadbaf715ca9a5d202f691 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 23:24:06 -0800 Subject: No longer necessary; all relevant album helper code is now in the model. --- modules/gallery/tests/Album_Helper_Test.php | 88 ----------------------------- 1 file changed, 88 deletions(-) delete mode 100644 modules/gallery/tests/Album_Helper_Test.php (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Album_Helper_Test.php b/modules/gallery/tests/Album_Helper_Test.php deleted file mode 100644 index ef0905da..00000000 --- a/modules/gallery/tests/Album_Helper_Test.php +++ /dev/null @@ -1,88 +0,0 @@ -assert_equal(VARPATH . "albums/$rand", $album->file_path()); - $this->assert_equal(VARPATH . "thumbs/$rand/.album.jpg", $album->thumb_path()); - $this->assert_true(is_dir(VARPATH . "thumbs/$rand"), "missing thumb dir"); - - // It's unclear that a resize makes sense for an album. But we have one. - $this->assert_equal(VARPATH . "resizes/$rand/.album.jpg", $album->resize_path()); - $this->assert_true(is_dir(VARPATH . "resizes/$rand"), "missing resizes dir"); - - $this->assert_equal(1, $album->parent_id); // MPTT tests will cover other hierarchy checks - $this->assert_equal($rand, $album->name); - $this->assert_equal($rand, $album->title); - $this->assert_equal($rand, $album->description); - } - - public function create_conflicting_album_test() { - $rand = "name_" . rand(); - $root = ORM::factory("item", 1); - $album1 = album::create($root, $rand, $rand, $rand); - $album2 = album::create($root, $rand, $rand, $rand); - $this->assert_true($album1->name != $album2->name); - } - - public function thumb_url_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - $album = album::create($root, $rand, $rand, $rand); - $this->assert_equal( - "http://./var/thumbs/$rand/.album.jpg?m={$album->updated}", $album->thumb_url()); - } - - public function resize_url_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - $album = album::create($root, $rand, $rand, $rand); - $this->assert_equal("http://./var/resizes/$rand/.album.jpg?m={$album->updated}", $album->resize_url()); - } - - public function create_album_shouldnt_allow_names_with_slash_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - try { - $album = album::create($root, $rand . "/", $rand, $rand); - } catch (Exception $e) { - // pass - return; - } - - $this->assert_true(false, "Shouldn't create an album with / in the name"); - } - - public function create_album_silently_trims_trailing_periods_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - try { - $album = album::create($root, $rand . "..", $rand, $rand); - } catch (Exception $e) { - $this->assert_equal("@todo NAME_CANNOT_END_IN_PERIOD", $e->getMessage()); - return; - } - - $this->assert_true(false, "Shouldn't create an album with trailing . in the name"); - } -} -- cgit v1.2.3 From e06ceebaa6b9631ce27939beae477e684f949352 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 23:25:09 -0800 Subject: No longer necessary; all photo and movie helper code is now in the model. --- modules/gallery/tests/Movie_Helper_Test.php | 56 ------------ modules/gallery/tests/Photo_Helper_Test.php | 130 ---------------------------- 2 files changed, 186 deletions(-) delete mode 100644 modules/gallery/tests/Movie_Helper_Test.php delete mode 100644 modules/gallery/tests/Photo_Helper_Test.php (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Movie_Helper_Test.php b/modules/gallery/tests/Movie_Helper_Test.php deleted file mode 100644 index 23544934..00000000 --- a/modules/gallery/tests/Movie_Helper_Test.php +++ /dev/null @@ -1,56 +0,0 @@ -assert_true(false, "Shouldn't create a movie with / in the name"); - } - - public function create_movie_shouldnt_allow_names_with_trailing_periods_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - try { - $movie = movie::create($root, MODPATH . "gallery/tests/test.flv", "$rand.flv.", $rand, $rand); - } catch (Exception $e) { - $this->assert_equal("@todo NAME_CANNOT_END_IN_PERIOD", $e->getMessage()); - return; - } - - $this->assert_true(false, "Shouldn't create a movie with trailing . in the name"); - } - - public function create_movie_creates_reasonable_slug_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - $album = album::create($root, $rand, $rand, $rand); - $movie = movie::create( - $album, MODPATH . "gallery/tests/test.flv", "This (is) my file%name.flv", $rand, $rand); - - $this->assert_equal("This-is-my-file-name", $movie->slug); - } -} diff --git a/modules/gallery/tests/Photo_Helper_Test.php b/modules/gallery/tests/Photo_Helper_Test.php deleted file mode 100644 index 97923f90..00000000 --- a/modules/gallery/tests/Photo_Helper_Test.php +++ /dev/null @@ -1,130 +0,0 @@ -assert_equal(VARPATH . "albums/$rand.jpg", $photo->file_path()); - $this->assert_equal(VARPATH . "thumbs/{$rand}.jpg", $photo->thumb_path()); - $this->assert_equal(VARPATH . "resizes/{$rand}.jpg", $photo->resize_path()); - - $this->assert_true(is_file($photo->file_path()), "missing: {$photo->file_path()}"); - $this->assert_true(is_file($photo->resize_path()), "missing: {$photo->resize_path()}"); - $this->assert_true(is_file($photo->thumb_path()), "missing: {$photo->thumb_path()}"); - - $this->assert_equal($root->id, $photo->parent_id); // MPTT tests cover other hierarchy checks - $this->assert_equal("$rand.jpg", $photo->name); - $this->assert_equal($rand, $photo->title); - $this->assert_equal($rand, $photo->description); - $this->assert_equal("image/jpeg", $photo->mime_type); - $this->assert_equal($image_info[0], $photo->width); - $this->assert_equal($image_info[1], $photo->height); - - $this->assert_equal($photo->parent()->right_ptr - 2, $photo->left_ptr); - $this->assert_equal($photo->parent()->right_ptr - 1, $photo->right_ptr); - } - - public function create_conflicting_photo_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - $photo1 = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand); - $photo2 = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand); - $this->assert_true($photo1->name != $photo2->name); - } - - public function create_photo_with_no_extension_test() { - $root = ORM::factory("item", 1); - try { - photo::create($root, "/tmp", "name", "title", "description"); - $this->assert_false("should fail with an exception"); - } catch (Exception $e) { - // pass - } - } - - public function thumb_url_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - $photo = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand); - $this->assert_equal("http://./var/thumbs/{$rand}.jpg?m={$photo->updated}", $photo->thumb_url()); - } - - public function resize_url_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - $album = album::create($root, $rand, $rand, $rand); - $photo = photo::create($album, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand); - - $this->assert_equal( - "http://./var/resizes/{$rand}/{$rand}.jpg?m={$photo->updated}", $photo->resize_url()); - } - - public function file_url_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - $album = album::create($root, $rand, $rand, $rand); - $photo = photo::create($album, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", $rand, $rand); - - $this->assert_equal( - "http://./var/albums/{$rand}/{$rand}.jpg?m={$photo->updated}", $photo->file_url()); - } - - public function create_photo_creates_reasonable_slug_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - $album = album::create($root, $rand, $rand, $rand); - $photo = photo::create( - $album, MODPATH . "gallery/tests/test.jpg", "This (is) my file%name.jpg", $rand, $rand); - - $this->assert_equal("This-is-my-file-name", $photo->slug); - } - - public function create_photo_shouldnt_allow_names_with_slash_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - try { - $photo = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand/.jpg", $rand, $rand); - } catch (Exception $e) { - // pass - return; - } - - $this->assert_true(false, "Shouldn't create a photo with / in the name"); - } - - public function create_photo_silently_trims_trailing_periods_test() { - $rand = rand(); - $root = ORM::factory("item", 1); - try { - $photo = photo::create($root, MODPATH . "gallery/tests/test.jpg", "$rand.jpg.", $rand, $rand); - } catch (Exception $e) { - $this->assert_equal("@todo NAME_CANNOT_END_IN_PERIOD", $e->getMessage()); - return; - } - - $this->assert_true(false, "Shouldn't create a photo with trailing . in the name"); - } -} -- cgit v1.2.3 From 2687762aec243d157f38de765f4b5c8465fc23ec Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 23:38:18 -0800 Subject: Update for model validation. Move the url safe tests into Item_Model_Test. --- modules/gallery/tests/Item_Helper_Test.php | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index f0c653c0..b3896c7a 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -20,9 +20,8 @@ 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); + $album = test::random_album(); + $item = test::random_photo($album); identity::set_active_user(identity::guest()); // We can see the item when permissions are granted @@ -38,33 +37,8 @@ class Item_Helper_Test extends Unit_Test_Case { ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all()); } - public function validate_url_safe_test() { - $input = new MockInput(); - $input->value = "Ab_cd-ef-d9"; - item::validate_url_safe($input); - $this->assert_true(!isset($input->not_url_safe)); - - $input->value = "ab&cd"; - item::validate_url_safe($input); - $this->assert_equal(1, $input->not_url_safe); - } - public function convert_filename_to_slug_test() { $this->assert_equal("foo", item::convert_filename_to_slug("{[foo]}")); $this->assert_equal("foo-bar", item::convert_filename_to_slug("{[foo!@#!$@#^$@($!(@bar]}")); } - - 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); - } } - -class MockInput { - function add_error($error, $value) { - $this->$error = $value; - } -} \ No newline at end of file -- cgit v1.2.3 From 4418993db96a6d9c4444957b78588b4ce01556f4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 23:38:39 -0800 Subject: Add slug_is_url_safe_test() --- modules/gallery/tests/Item_Model_Test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 5294836d..afb131fc 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -318,4 +318,20 @@ class Item_Model_Test extends Unit_Test_Case { $this->assert_false(true, "Shouldn't get here"); } + + public function slug_is_url_safe_test() { + $album = test::random_album_unsaved(); + + try { + $album->slug = "illegal chars! !@#@#$!@~"; + $album->save(); + $this->assert_true(false, "Shouldn't be able to save"); + } catch (ORM_Validation_Exception $e) { + $this->assert_same(array("slug" => "not_url_safe"), $e->validation->errors()); + } + + // This should work + $album->slug = "the_quick_brown_fox"; + $album->save(); + } } -- cgit v1.2.3 From c059a444c77c0adc6d003b8ece38ba654e4f45f0 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 23:49:00 -0800 Subject: Updated for model based validation. Fixed change_photo_no_csrf_fails_test() which has been broken since we deleted Rest_Controller. --- modules/gallery/tests/Photos_Controller_Test.php | 28 ++++++++++-------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Photos_Controller_Test.php b/modules/gallery/tests/Photos_Controller_Test.php index b6c6df47..31e0bc21 100644 --- a/modules/gallery/tests/Photos_Controller_Test.php +++ b/modules/gallery/tests/Photos_Controller_Test.php @@ -29,19 +29,14 @@ class Photos_Controller_Test extends Unit_Test_Case { public function change_photo_test() { $controller = new Photos_Controller(); - $root = ORM::factory("item", 1); - $photo = photo::create( - $root, MODPATH . "gallery/tests/test.jpg", "test.jpeg", - "test", "test", identity::active_user()->id, "slug"); - $orig_name = $photo->name; + $photo = test::random_photo(); - $_POST["filename"] = "test.jpeg"; - $_POST["name"] = "new name"; + $_POST["filename"] = "new name.jpg"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; $_POST["slug"] = "new-slug"; $_POST["csrf"] = access::csrf_token(); - access::allow(identity::everybody(), "edit", $root); + access::allow(identity::everybody(), "edit", item::root()); ob_start(); $controller->update($photo->id); @@ -53,26 +48,25 @@ class Photos_Controller_Test extends Unit_Test_Case { $this->assert_equal("new-slug", $photo->slug); $this->assert_equal("new title", $photo->title); $this->assert_equal("new description", $photo->description); - - // We don't change the name, yet. - $this->assert_equal($orig_name, $photo->name); + $this->assert_equal("new name.jpeg", $photo->name); } public function change_photo_no_csrf_fails_test() { $controller = new Photos_Controller(); - $root = ORM::factory("item", 1); - $photo = photo::create( - $root, MODPATH . "gallery/tests/test.jpg", "test.jpg", "test", "test"); - $_POST["name"] = "new name"; + $photo = test::random_photo(); + + $_POST["filename"] = "new name.jpg"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; - access::allow(identity::everybody(), "edit", $root); + $_POST["slug"] = "new slug"; + access::allow(identity::everybody(), "edit", item::root()); try { - $controller->_update($photo); + $controller->update($photo); $this->assert_true(false, "This should fail"); } catch (Exception $e) { // pass + $this->assert_same("@todo FORBIDDEN", $e->getMessage()); } } } -- cgit v1.2.3 From f95442c314f84004c48758579f076ae209aace43 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 19 Jan 2010 01:17:29 -0800 Subject: Rewrite the tests entirely to cover the new REST code. --- modules/gallery/tests/Gallery_Rest_Helper_Test.php | 347 ++++++++------------- 1 file changed, 138 insertions(+), 209 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Gallery_Rest_Helper_Test.php b/modules/gallery/tests/Gallery_Rest_Helper_Test.php index dac221b3..35fd0daf 100644 --- a/modules/gallery/tests/Gallery_Rest_Helper_Test.php +++ b/modules/gallery/tests/Gallery_Rest_Helper_Test.php @@ -17,262 +17,191 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Gallery_Rest_Helper_Test extends Unit_Test_Case { +class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function setup() { $this->_save = array($_GET, $_POST, $_SERVER, $_FILES); - $this->_saved_active_user = identity::active_user(); } public function teardown() { list($_GET, $_POST, $_SERVER, $_FILES) = $this->_save; - identity::set_active_user($this->_saved_active_user); - if (!empty($this->_user)) { - try { - $this->_user->delete(); - } catch (Exception $e) { } - } } - private function _create_user() { - if (empty($this->_user)) { - $this->_user = identity::create_user("access_test" . rand(), "Access Test", "password"); - $key = ORM::factory("user_access_token"); - $key->access_key = md5($this->_user->name . rand()); - $key->user_id = $this->_user->id; - $key->save(); - identity::set_active_user($this->_user); - } - return $this->_user; + public function resolve_test() { + $album = test::random_album(); + $resolved = rest::resolve(rest::url("gallery", $album->relative_url())); + $this->assert_equal($album->id, $resolved->id); } - private function _create_album($parent=null) { - $album_name = "rest_album_" . rand(); - if (empty($parent)) { - $parent = ORM::factory("item", 1); - } - return album::create($parent, $album_name, $album_name, $album_name); - } + public function get_scope_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $photo2 = test::random_photo($album2); + $album1->reload(); - private function _create_image($parent=null) { - $filename = MODPATH . "gallery/tests/test.jpg"; - $image_name = "rest_image_" . rand(); - if (empty($parent)) { - $parent = ORM::factory("item", 1); - } - return photo::create($parent, $filename, "$image_name.jpg", $image_name); - } + // No scope is the same as "direct" + $request->url = rest::url("gallery", $album1->relative_url()); + $request->params = new stdClass(); + $this->assert_equal_array( + array("resource" => $album1->as_array(), + "members" => array( + rest::url("gallery", $photo1->relative_url()), + rest::url("gallery", $album2->relative_url()))), + gallery_rest::get($request)); - public function gallery_rest_get_album_test() { - $album = $this->_create_album(); - $child = $this->_create_album($album); - $photo = $this->_create_image($child); - $child->reload(); - $request = (object)array("arguments" => explode("/", $child->relative_url())); + $request->url = rest::url("gallery", $album1->relative_url()); + $request->params->scope = "direct"; + $this->assert_equal_array( + array("resource" => $album1->as_array(), + "members" => array( + rest::url("gallery", $photo1->relative_url()), + rest::url("gallery", $album2->relative_url()))), + gallery_rest::get($request)); - $this->assert_equal( - json_encode(array("status" => "OK", - "resource" => - array("type" => $child->type, - "name" => $child->name, - "path" => $child->relative_url(), - "parent_path" => $album->relative_url(), - "title" => $child->title, - "thumb_url" => $child->thumb_url(), - "thumb_size" => array("height" => $child->thumb_height, - "width" => $child->thumb_width), - "resize_url" => $child->resize_url(), - "resize_size" => array("height" => 0, - "width" => 0), - "url" => $child->file_url(), - "size" => array("height" => $child->height, - "width" => $child->width), - "description" => $child->description, - "slug" => $child->slug, - "children" => array(array( - "type" => "photo", - "has_children" => false, - "path" => $photo->relative_url(), - "thumb_url" => $photo->thumb_url(), - "thumb_dimensions" => array( - "width" => (string)$photo->thumb_width, - "height" => (string)$photo->thumb_height), - "has_thumb" => true, - "title" => $photo->title))))), + $request->url = rest::url("gallery", $album1->relative_url()); + $request->params->scope = "all"; + $this->assert_equal_array( + array("resource" => $album1->as_array(), + "members" => array( + rest::url("gallery", $photo1->relative_url()), + rest::url("gallery", $album2->relative_url()), + rest::url("gallery", $photo2->relative_url()))), gallery_rest::get($request)); } - public function gallery_rest_get_photo_test() { - $child = $this->_create_album(); - $photo = $this->_create_image($child); - $request = (object)array("arguments" => explode("/", $photo->relative_url())); - - $this->assert_equal( - json_encode(array("status" => "OK", - "resource" => - array("type" => $photo->type, - "name" => $photo->name, - "path" => $photo->relative_url(), - "parent_path" => $child->relative_url(), - "title" => $photo->title, - "thumb_url" => $photo->thumb_url(), - "thumb_size" => array("height" => (string)$photo->thumb_height, - "width" => (string)$photo->thumb_width), - "resize_url" => $photo->resize_url(), - "resize_size" => array("height" => $photo->resize_height, - "width" => $photo->resize_width), - "url" => $photo->file_url(), - "size" => array("height" => (string)$photo->height, - "width" => (string)$photo->width), - "description" => $photo->description, - "slug" => $photo->slug))), + public function get_children_like_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $photo2 = test::random_photo_unsaved($album1); + $photo2->name = "foo.jpg"; + $photo2->save(); + $album1->reload(); + + $request->url = rest::url("gallery", $album1->relative_url()); + $request->params->name = "foo"; + $this->assert_equal_array( + array("resource" => $album1->as_array(), + "members" => array( + rest::url("gallery", $photo2->relative_url()))), gallery_rest::get($request)); } - public function gallery_rest_put_album_no_path_test() { - $request = (object)array("description" => "Updated description", - "title" => "Updated Title", - "name" => "new name"); + public function get_children_type_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $album1->reload(); - try { - gallery_rest::put($request); - } catch (Rest_Exception $e) { - $this->assert_equal("Bad request", $e->getMessage()); - $this->assert_equal(400, $e->getCode()); - } catch (Exception $e) { - $this->assert_false(true, $e->__toString()); - } + $request->url = rest::url("gallery", $album1->relative_url()); + $request->params->type = "album"; + $this->assert_equal_array( + array("resource" => $album1->as_array(), + "members" => array( + rest::url("gallery", $album2->relative_url()))), + gallery_rest::get($request)); } - public function gallery_rest_put_album_not_found_test() { - $photo = $this->_create_image(); - $request = (object)array("arguments" => explode("/", $photo->relative_url() . rand()), - "description" => "Updated description", - "title" => "Updated Title", - "name" => "new name"); + public function update_album_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); - try { - gallery_rest::put($request); - } catch (Kohana_404_Exception $k404) { - } catch (Exception $e) { - $this->assert_false(true, $e->__toString()); - } + $request->url = rest::url("gallery", $album1->relative_url()); + $request->params->title = "my new title"; + + $this->assert_equal_array( + array("url" => rest::url("gallery", $album1->relative_url())), + gallery_rest::put($request)); + $this->assert_equal("my new title", $album1->reload()->title); } - public function gallery_rest_put_album_no_edit_permission_test() { - $child = $this->_create_album(); - $this->_create_user(); - $request = (object)array("arguments" => explode("/", $child->relative_url()), - "description" => "Updated description", - "title" => "Updated Title", - "name" => "new name"); + public function update_album_illegal_value_fails_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); + + $request->url = rest::url("gallery", $album1->relative_url()); + $request->params->title = "my new title"; + $request->params->slug = "not url safe"; try { gallery_rest::put($request); - } catch (Kohana_404_Exception $k404) { - } catch (Exception $e) { - $this->assert_false(true, $e->__toString()); + } catch (ORM_Validation_Exception $e) { + $this->assert_equal(array("slug" => "not_url_safe"), $e->validation->errors()); + return; } + $this->assert_true(false, "Shouldn't get here"); } - public function gallery_rest_put_album_rename_conflict_test() { - $child = $this->_create_album(); - $sibling = $this->_create_image(); - $this->_create_user(); - access::allow(identity::registered_users(), "edit", $child); - $request = (object)array("arguments" => explode("/", $child->relative_url()), - "description" => "Updated description", - "title" => "Updated Title", - "name" => $sibling->name); - - $this->assert_equal( - json_encode(array("status" => "VALIDATE_ERROR", - "fields" => array("slug" => "Duplicate Internet address"))), - gallery_rest::put($request)); - } - - public function gallery_rest_put_album_test() { - $child = $this->_create_album(); - $sibling = $this->_create_image(); - $this->_create_user(); - access::allow(identity::registered_users(), "edit", $child); + public function add_album_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); - $new_name = "new_album_name" . rand(); - $request = (object)array("arguments" => explode("/", $child->relative_url()), - "description" => "Updated description", - "title" => "Updated Title", - "name" => $new_name); + $request->url = rest::url("gallery", $album1->relative_url()); + $request->params->type = "album"; + $request->params->name = "my album"; + $request->params->title = "my album"; + $response = gallery_rest::post($request); + $new_album = rest::resolve($response["url"]); - $this->assert_equal(json_encode(array("status" => "OK")), gallery_rest::put($request)); - $child->reload(); - $this->assert_equal("Updated description", $child->description); - $this->assert_equal("Updated Title", $child->title); - $this->assert_equal($new_name, $child->name); + $this->assert_true($new_album->is_album()); + $this->assert_equal($album1->id, $new_album->parent_id); } - public function gallery_rest_put_photo_test() { - $child = $this->_create_album(); - $photo = $this->_create_image($child); - $this->_create_user(); - access::allow(identity::registered_users(), "edit", $child); + public function add_album_illegal_value_fails_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); - $request = (object)array("arguments" => explode("/", $photo->relative_url()), - "description" => "Updated description", - "title" => "Updated Title", - "name" => "new name"); + $request->url = rest::url("gallery", $album1->relative_url()); + $request->params->type = "album"; + $request->params->name = "my album"; + $request->params->title = "my album"; + $request->params->slug = "not url safe"; - $this->assert_equal(json_encode(array("status" => "OK")), gallery_rest::put($request)); - $photo->reload(); - $this->assert_equal("Updated description", $photo->description); - $this->assert_equal("Updated Title", $photo->title); - $this->assert_equal("new name", $photo->name); + try { + gallery_rest::post($request); + } catch (ORM_Validation_Exception $e) { + $this->assert_equal(array("slug" => "not_url_safe"), $e->validation->errors()); + return; + } + $this->assert_true(false, "Shouldn't get here"); } - public function gallery_rest_delete_album_test() { - $album = $this->_create_album(); - $child = $this->_create_album($album); - $this->_create_user(); - access::allow(identity::registered_users(), "edit", $album); - $request = (object)array("arguments" => explode("/", $child->relative_url())); + public function add_photo_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); + + $request->url = rest::url("gallery", $album1->relative_url()); + $request->params->type = "photo"; + $request->params->name = "my photo.jpg"; + $request->file = MODPATH . "gallery/tests/test.jpg"; + $response = gallery_rest::post($request); + $new_photo = rest::resolve($response["url"]); - $this->assert_equal(json_encode(array("status" => "OK", - "resource" => array( - "parent_path" => $album->relative_url()))), - gallery_rest::delete($request)); - $child->reload(); - $this->assert_false($child->loaded()); + $this->assert_true($new_photo->is_photo()); + $this->assert_equal($album1->id, $new_photo->parent_id); } - public function gallery_rest_delete_photo_test() { - $album = $this->_create_album(); - $photo = $this->_create_image($album); - $this->_create_user(); - access::allow(identity::registered_users(), "edit", $album); + public function delete_album_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); - $request = (object)array("arguments" => explode("/", $photo->relative_url())); + $request->url = rest::url("gallery", $album1->relative_url()); + gallery_rest::delete($request); - $this->assert_equal(json_encode(array("status" => "OK", - "resource" => array( - "parent_path" => $album->relative_url()))), - gallery_rest::delete($request)); - $photo->reload(); - $this->assert_false($photo->loaded()); + $album1->reload(); + $this->assert_false($album1->loaded()); } - public function gallery_rest_post_album_test() { - $album = $this->_create_album(); - $this->_create_user(); - access::allow(identity::registered_users(), "edit", $album); + public function delete_album_fails_without_permission_test() { + $album1 = test::random_album(); - $new_path = $album->relative_url() . "/new%20child"; - $request = (object)array("arguments" => explode("/", $new_path)); - - $this->assert_equal(json_encode(array("status" => "OK", "path" => $new_path)), - gallery_rest::post($request)); - $album = ORM::factory("item") - ->where("relative_url_cache", "=", $new_path) - ->find(); - $this->assert_true($album->loaded()); - $this->assert_equal("new child", $album->slug); + $request->url = rest::url("gallery", $album1->relative_url()); + try { + gallery_rest::delete($request); + } catch (Exception $e) { + $this->assert_equal("@todo FORBIDDEN", $e->getMessage()); + return; + } + $this->assert_true(false, "Shouldn't get here"); } } -- cgit v1.2.3 From c590fed132b07647c38b1d5b4a93ffe30b6ac4bf Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 19 Jan 2010 01:33:57 -0800 Subject: Change rest::url() to take a module name and a resource. The module does the rest. This function is symmetrical to rest::resolve. --- modules/gallery/helpers/gallery_rest.php | 28 ++++--------- modules/gallery/tests/Gallery_Rest_Helper_Test.php | 46 +++++++++++----------- modules/rest/helpers/rest.php | 12 ++++-- modules/tag/helpers/tag_rest.php | 15 ++++--- modules/tag/helpers/tags_rest.php | 6 +-- 5 files changed, 50 insertions(+), 57 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/helpers/gallery_rest.php b/modules/gallery/helpers/gallery_rest.php index 827da122..5fd73a2e 100644 --- a/modules/gallery/helpers/gallery_rest.php +++ b/modules/gallery/helpers/gallery_rest.php @@ -17,25 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ - -// @todo Add logging - -// Validation questions -// -// We need to be able to properly validate anything we want to enter here. But all of our -// validation currently happens at the controller / form level, and we're not using the same -// controllers or forms. -// -// Possible solutions: -// 1) Move validation into the model and use it both here and in the regular controllers. But -// if we do that, how do we translate validation failures into a user-consumable output which -// we need so that we can return proper error responses to form submissions? -// -// 2) Create some kind of validation helper that can validate every field. Wait, isn't this -// just like #1 except in a helper instead of in the model? - class gallery_rest_Core { - /** * For items that are collections, you can specify the following additional query parameters to * query the collection. You can specify them in any combination. @@ -90,7 +72,7 @@ class gallery_rest_Core { $members = array(); foreach ($orm->find_all() as $child) { - $members[] = url::abs_site("rest/gallery/" . $child->relative_url()); + $members[] = rest::url("gallery", $child); } return array("resource" => $item->as_array(), "members" => $members); @@ -114,7 +96,7 @@ class gallery_rest_Core { } $item->save(); - return array("url" => url::abs_site("/rest/gallery/" . $item->relative_url())); + return array("url" => rest::url("gallery", $item)); } static function post($request) { @@ -150,7 +132,7 @@ class gallery_rest_Core { throw new Rest_Exception("Invalid type: $params->type", 400); } - return array("url" => url::abs_site("/rest/gallery/" . $item->relative_url())); + return array("url" => rest::url("gallery", $item)); } static function delete($request) { @@ -163,4 +145,8 @@ class gallery_rest_Core { static function resolve($path) { return url::get_item_from_uri($path); } + + static function url($item) { + return url::abs_site("rest/gallery/" . $item->relative_url()); + } } diff --git a/modules/gallery/tests/Gallery_Rest_Helper_Test.php b/modules/gallery/tests/Gallery_Rest_Helper_Test.php index 35fd0daf..dcd9a9db 100644 --- a/modules/gallery/tests/Gallery_Rest_Helper_Test.php +++ b/modules/gallery/tests/Gallery_Rest_Helper_Test.php @@ -28,7 +28,7 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function resolve_test() { $album = test::random_album(); - $resolved = rest::resolve(rest::url("gallery", $album->relative_url())); + $resolved = rest::resolve(rest::url("gallery", $album)); $this->assert_equal($album->id, $resolved->id); } @@ -40,32 +40,32 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1->reload(); // No scope is the same as "direct" - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); $request->params = new stdClass(); $this->assert_equal_array( array("resource" => $album1->as_array(), "members" => array( - rest::url("gallery", $photo1->relative_url()), - rest::url("gallery", $album2->relative_url()))), + rest::url("gallery", $photo1), + rest::url("gallery", $album2))), gallery_rest::get($request)); - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); $request->params->scope = "direct"; $this->assert_equal_array( array("resource" => $album1->as_array(), "members" => array( - rest::url("gallery", $photo1->relative_url()), - rest::url("gallery", $album2->relative_url()))), + rest::url("gallery", $photo1), + rest::url("gallery", $album2))), gallery_rest::get($request)); - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); $request->params->scope = "all"; $this->assert_equal_array( array("resource" => $album1->as_array(), "members" => array( - rest::url("gallery", $photo1->relative_url()), - rest::url("gallery", $album2->relative_url()), - rest::url("gallery", $photo2->relative_url()))), + rest::url("gallery", $photo1), + rest::url("gallery", $album2), + rest::url("gallery", $photo2))), gallery_rest::get($request)); } @@ -77,12 +77,12 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { $photo2->save(); $album1->reload(); - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); $request->params->name = "foo"; $this->assert_equal_array( array("resource" => $album1->as_array(), "members" => array( - rest::url("gallery", $photo2->relative_url()))), + rest::url("gallery", $photo2))), gallery_rest::get($request)); } @@ -92,12 +92,12 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album2 = test::random_album($album1); $album1->reload(); - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); $request->params->type = "album"; $this->assert_equal_array( array("resource" => $album1->as_array(), "members" => array( - rest::url("gallery", $album2->relative_url()))), + rest::url("gallery", $album2))), gallery_rest::get($request)); } @@ -105,11 +105,11 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); $request->params->title = "my new title"; $this->assert_equal_array( - array("url" => rest::url("gallery", $album1->relative_url())), + array("url" => rest::url("gallery", $album1)), gallery_rest::put($request)); $this->assert_equal("my new title", $album1->reload()->title); } @@ -118,7 +118,7 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); $request->params->title = "my new title"; $request->params->slug = "not url safe"; @@ -135,7 +135,7 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); $request->params->type = "album"; $request->params->name = "my album"; $request->params->title = "my album"; @@ -150,7 +150,7 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); $request->params->type = "album"; $request->params->name = "my album"; $request->params->title = "my album"; @@ -170,7 +170,7 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); $request->params->type = "photo"; $request->params->name = "my photo.jpg"; $request->file = MODPATH . "gallery/tests/test.jpg"; @@ -185,7 +185,7 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); gallery_rest::delete($request); $album1->reload(); @@ -195,7 +195,7 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function delete_album_fails_without_permission_test() { $album1 = test::random_album(); - $request->url = rest::url("gallery", $album1->relative_url()); + $request->url = rest::url("gallery", $album1); try { gallery_rest::delete($request); } catch (Exception $e) { diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php index 423765bb..93ad2bd3 100644 --- a/modules/rest/helpers/rest.php +++ b/modules/rest/helpers/rest.php @@ -75,10 +75,14 @@ class rest_Core { /** * Return an absolute url used for REST resource location. * @param string module name (eg, "gallery", "tags") - * @param string relative path (eg "Family/Weddings.jpg") - * @return string complete url + * @param object resource */ - static function url($module, $path) { - return url::abs_site("rest/$module/$path"); + static function url($module, $resource) { + $class = "{$module}_rest"; + if (!method_exists($class, "url")) { + throw new Exception("@todo MISSING REST CLASS: $class"); + } + + return call_user_func(array($class, "url"), $resource); } } diff --git a/modules/tag/helpers/tag_rest.php b/modules/tag/helpers/tag_rest.php index 0aac5291..a4eaee90 100644 --- a/modules/tag/helpers/tag_rest.php +++ b/modules/tag/helpers/tag_rest.php @@ -22,10 +22,10 @@ class tag_rest_Core { $tag = rest::resolve($request->url); $items = array(); foreach ($tag->items() as $item) { - $items[] = url::abs_site("rest/gallery/" . $item->relative_url()); + $items[] = rest::url("gallery", $item); } - return rest::reply(array("resource" => $tag->as_array(), "members" => $items)); + return array("resource" => $tag->as_array(), "members" => $items); } static function post($request) { @@ -38,7 +38,7 @@ class tag_rest_Core { access::required("edit", $item); tag::add($item, $tag->name); - return rest::reply(array("url" => url::abs_site("rest/tag/" . rawurlencode($tag->name)))); + return array("url" => rest::url("tag", $tag)); } static function put($request) { @@ -61,7 +61,7 @@ class tag_rest_Core { } $tag->save(); - return rest::reply(array("url" => url::abs_site("rest/tag/" . rawurlencode($tag->name)))); + return array("url" => rest::url("tag", $tag)); } static function delete($request) { @@ -70,7 +70,6 @@ class tag_rest_Core { if (empty($request->params->url)) { // Delete the tag $tag->delete(); - return rest::reply(); } else { // Remove an item from the tag $item = rest::resolve($request->params->url); @@ -78,7 +77,7 @@ class tag_rest_Core { $tag->save(); tag::compact(); - return rest::reply(array("url" => url::abs_site("rest/tag/" . rawurlencode($tag->name)))); + return array("url" => rest::url("tag", $tag)); } } @@ -90,4 +89,8 @@ class tag_rest_Core { return $tag; } + + static function url($item) { + return url::abs_site("rest/tag/" . rawurlencode($tag->name)); + } } diff --git a/modules/tag/helpers/tags_rest.php b/modules/tag/helpers/tags_rest.php index 7f0ed66a..dd23e97f 100644 --- a/modules/tag/helpers/tags_rest.php +++ b/modules/tag/helpers/tags_rest.php @@ -21,9 +21,9 @@ class tags_rest_Core { static function get($request) { $tags = array(); foreach (ORM::factory("tag")->find_all() as $tag) { - $tags[$tag->name] = url::abs_site("rest/tags/" . rawurlencode($tag->name)); + $tags[$tag->name] = rest::url("tags", $tag); } - return rest::reply(array("members" => $tags)); + return array("members" => $tags); } static function post($request) { @@ -43,6 +43,6 @@ class tags_rest_Core { $tag->save(); } - return rest::reply(array("url" => url::abs_site("rest/tag/" . rawurlencode($tag->name)))); + return array("url" => rest::url("tag", $tag)); } } -- cgit v1.2.3 From 512910962d62a2011d7770da1b6e68bd6bbad983 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 19 Jan 2010 19:24:46 -0800 Subject: Change "dirname" to "name" in the edit album form. I'd rather have consistency between field names than deal with underlying issues with Forge bitching about the "name" property. --- modules/gallery/controllers/albums.php | 5 +---- modules/gallery/helpers/album.php | 4 ++-- modules/gallery/tests/Albums_Controller_Test.php | 6 +++--- 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 7658a913..a378f3ee 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -141,15 +141,12 @@ class Albums_Controller extends Items_Controller { $album->description = $form->edit_item->description->value; $album->sort_column = $form->edit_item->sort_order->column->value; $album->sort_order = $form->edit_item->sort_order->direction->value; - $album->name = $form->edit_item->dirname->value; + $album->name = $form->edit_item->inputs["name"]->value; $album->slug = $form->edit_item->slug->value; $album->validate(); } catch (ORM_Validation_Exception $e) { // Translate ORM validation errors into form error messages foreach ($e->validation->errors() as $key => $error) { - if ($key == "name") { - $key = "dirname"; - } $form->edit_item->inputs[$key]->add_error($error, 1); } $valid = false; diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index e99770e9..55282252 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -52,7 +52,7 @@ class album_Core { $group->input("title")->label(t("Title"))->value($parent->title); $group->textarea("description")->label(t("Description"))->value($parent->description); if ($parent->id != 1) { - $group->input("dirname")->label(t("Directory Name"))->value($parent->name) + $group->input("name")->label(t("Directory Name"))->value($parent->name) ->rules("required") ->error_messages( "conflict", t("There is already a movie, photo or album with this name")) @@ -65,7 +65,7 @@ class album_Core { "not_url_safe", t("The internet address should contain only letters, numbers, hyphens and underscores")); } else { - $group->hidden("dirname")->value($parent->name); + $group->hidden("name")->value($parent->name); $group->hidden("slug")->value($parent->slug); } diff --git a/modules/gallery/tests/Albums_Controller_Test.php b/modules/gallery/tests/Albums_Controller_Test.php index 8ba2c7bc..26dc2571 100644 --- a/modules/gallery/tests/Albums_Controller_Test.php +++ b/modules/gallery/tests/Albums_Controller_Test.php @@ -31,9 +31,9 @@ class Albums_Controller_Test extends Unit_Test_Case { $album = test::random_album(); // Randomize to avoid conflicts. - $new_dirname = "new_name_" . rand(); + $new_name = "new_name_" . rand(); - $_POST["dirname"] = $new_dirname; + $_POST["name"] = $new_name; $_POST["title"] = "new title"; $_POST["description"] = "new description"; $_POST["column"] = "weight"; @@ -49,7 +49,7 @@ class Albums_Controller_Test extends Unit_Test_Case { ob_end_clean(); $this->assert_equal(json_encode(array("result" => "success")), $results); - $this->assert_equal($new_dirname, $album->name); + $this->assert_equal($new_name, $album->name); $this->assert_equal("new title", $album->title); $this->assert_equal("new description", $album->description); } -- cgit v1.2.3 From e02675b730fb814105e1cb9dceb0e25fdcbd3e27 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 19 Jan 2010 19:31:01 -0800 Subject: Change "filename" to "name" in the edit album form. I'd rather have consistency between field names than deal with underlying issues with Forge bitching about the "name" property. --- modules/gallery/controllers/movies.php | 5 +---- modules/gallery/controllers/photos.php | 5 +---- modules/gallery/helpers/movie.php | 2 +- modules/gallery/helpers/photo.php | 2 +- modules/gallery/tests/Photos_Controller_Test.php | 4 ++-- 5 files changed, 6 insertions(+), 12 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 0908e281..b51282b3 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -66,14 +66,11 @@ class Movies_Controller extends Items_Controller { $movie->title = $form->edit_item->title->value; $movie->description = $form->edit_item->description->value; $movie->slug = $form->edit_item->slug->value; - $movie->name = $form->edit_item->filename->value; + $movie->name = $form->edit_item->inputs["name"]->value; $movie->validate(); } catch (ORM_Validation_Exception $e) { // Translate ORM validation errors into form error messages foreach ($e->validation->errors() as $key => $error) { - if ($key == "name") { - $key = "filename"; - } $form->edit_item->inputs[$key]->add_error($error, 1); } $valid = false; diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 98f2126d..b5da3884 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -66,14 +66,11 @@ class Photos_Controller extends Items_Controller { $photo->title = $form->edit_item->title->value; $photo->description = $form->edit_item->description->value; $photo->slug = $form->edit_item->slug->value; - $photo->name = $form->edit_item->filename->value; + $photo->name = $form->edit_item->inputs["name"]->value; $photo->validate(); } catch (ORM_Validation_Exception $e) { // Translate ORM validation errors into form error messages foreach ($e->validation->errors() as $key => $error) { - if ($key == "name") { - $key = "filename"; - } $form->edit_item->inputs[$key]->add_error($error, 1); } $valid = false; diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index b2e846d3..b07a9e69 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -30,7 +30,7 @@ class movie_Core { $group = $form->group("edit_item")->label(t("Edit Movie")); $group->input("title")->label(t("Title"))->value($movie->title); $group->textarea("description")->label(t("Description"))->value($movie->description); - $group->input("filename")->label(t("Filename"))->value($movie->name) + $group->input("name")->label(t("Filename"))->value($movie->name) ->error_messages( "conflict", t("There is already a movie, photo or album with this name")) ->error_messages("no_slashes", t("The movie name can't contain a \"/\"")) diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index cb94772e..9bd277bc 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -30,7 +30,7 @@ class photo_Core { $group = $form->group("edit_item")->label(t("Edit Photo")); $group->input("title")->label(t("Title"))->value($photo->title); $group->textarea("description")->label(t("Description"))->value($photo->description); - $group->input("filename")->label(t("Filename"))->value($photo->name) + $group->input("name")->label(t("Filename"))->value($photo->name) ->error_messages("conflict", t("There is already a movie, photo or album with this name")) ->error_messages("no_slashes", t("The photo name can't contain a \"/\"")) ->error_messages("no_trailing_period", t("The photo name can't end in \".\"")) diff --git a/modules/gallery/tests/Photos_Controller_Test.php b/modules/gallery/tests/Photos_Controller_Test.php index 31e0bc21..f548b40d 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 { $controller = new Photos_Controller(); $photo = test::random_photo(); - $_POST["filename"] = "new name.jpg"; + $_POST["name"] = "new name.jpg"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; $_POST["slug"] = "new-slug"; @@ -55,7 +55,7 @@ class Photos_Controller_Test extends Unit_Test_Case { $controller = new Photos_Controller(); $photo = test::random_photo(); - $_POST["filename"] = "new name.jpg"; + $_POST["name"] = "new name.jpg"; $_POST["title"] = "new title"; $_POST["description"] = "new description"; $_POST["slug"] = "new slug"; -- cgit v1.2.3 From e39c8df19fc0dadcfe65cb8a3ed6529648c6c9cf Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 19 Jan 2010 21:20:36 -0800 Subject: Fix some validation checks to check to see if the original was loaded before deciding whether or not we changed a value. Change valid_name to be cascading, not parallel. --- modules/gallery/models/item.php | 18 +++++------------- modules/gallery/tests/Item_Model_Test.php | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index a7f73d0e..58ff86ed 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -782,21 +782,15 @@ class Item_Model extends ORM_MPTT { if (strpos($this->name, "/") !== false) { $v->add_error("name", "no_slashes"); return; - } - - if (rtrim($this->name, ".") !== $this->name) { + } else if (rtrim($this->name, ".") !== $this->name) { $v->add_error("name", "no_trailing_period"); - return; - } - - if ($this->is_movie() || $this->is_photo()) { - if ($this->loaded()) { + } else if ($this->is_movie() || $this->is_photo()) { + if ($this->original()->loaded()) { // Existing items can't change their extension $new_ext = pathinfo($this->name, PATHINFO_EXTENSION); $old_ext = pathinfo($this->original()->name, PATHINFO_EXTENSION); if (strcasecmp($new_ext, $old_ext)) { $v->add_error("name", "illegal_data_file_extension"); - return; } } else { // New items must have an extension @@ -804,9 +798,7 @@ class Item_Model extends ORM_MPTT { $v->add_error("name", "illegal_data_file_extension"); } } - } - - if (db::build() + } else if (db::build() ->from("items") ->where("parent_id", "=", $this->parent_id) ->where("name", "=", $this->name) @@ -908,7 +900,7 @@ class Item_Model extends ORM_MPTT { * This field cannot be changed after it's been set. */ public function read_only(Validation $v, $field) { - if ($this->loaded() && $this->original()->$field != $this->$field) { + if ($this->original()->loaded() && $this->original()->$field != $this->$field) { $v->add_error($field, "read_only"); } } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index afb131fc..284491a0 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -320,9 +320,8 @@ class Item_Model_Test extends Unit_Test_Case { } public function slug_is_url_safe_test() { - $album = test::random_album_unsaved(); - try { + $album = test::random_album_unsaved(); $album->slug = "illegal chars! !@#@#$!@~"; $album->save(); $this->assert_true(false, "Shouldn't be able to save"); @@ -334,4 +333,17 @@ class Item_Model_Test extends Unit_Test_Case { $album->slug = "the_quick_brown_fox"; $album->save(); } + + public function cant_change_item_type_test() { + $photo = test::random_photo(); + try { + $photo->type = "movie"; + $photo->mime_type = "video/x-flv"; + $photo->save(); + } catch (ORM_Validation_Exception $e) { + $this->assert_same(array("type" => "read_only"), $e->validation->errors()); + return; // pass + } + $this->assert_true(false, "Shouldn't get here"); + } } -- cgit v1.2.3 From 76da85a1a08cdf065bf186c81ea444d03d6f8935 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 19 Jan 2010 22:38:19 -0800 Subject: Extend Gallery_Unit_Test_Case instead of Unit_Test_Case. --- modules/akismet/tests/Akismet_Helper_Test.php | 2 +- modules/comment/tests/Comment_Event_Test.php | 2 +- modules/comment/tests/Comment_Helper_Test.php | 2 +- modules/comment/tests/Comment_Model_Test.php | 2 +- modules/digibug/tests/Digibug_Controller_Test.php | 2 +- modules/exif/tests/Exif_Test.php | 2 +- modules/gallery/tests/Access_Helper_Test.php | 2 +- modules/gallery/tests/Albums_Controller_Test.php | 2 +- modules/gallery/tests/Cache_Test.php | 2 +- modules/gallery/tests/Controller_Auth_Test.php | 2 +- modules/gallery/tests/Database_Test.php | 2 +- modules/gallery/tests/Dir_Helper_Test.php | 2 +- modules/gallery/tests/DrawForm_Test.php | 2 +- modules/gallery/tests/File_Structure_Test.php | 2 +- modules/gallery/tests/Gallery_I18n_Test.php | 2 +- modules/gallery/tests/Gallery_Installer_Test.php | 2 +- modules/gallery/tests/Html_Helper_Test.php | 2 +- modules/gallery/tests/Item_Helper_Test.php | 2 +- modules/gallery/tests/Item_Model_Test.php | 2 +- modules/gallery/tests/Locales_Helper_Test.php | 2 +- modules/gallery/tests/Menu_Test.php | 2 +- modules/gallery/tests/ORM_MPTT_Test.php | 2 +- modules/gallery/tests/Photos_Controller_Test.php | 2 +- modules/gallery/tests/SafeString_Test.php | 2 +- modules/gallery/tests/Sendmail_Test.php | 2 +- modules/gallery/tests/Url_Security_Test.php | 2 +- modules/gallery/tests/Var_Test.php | 2 +- modules/gallery/tests/Xss_Security_Test.php | 2 +- modules/gallery_unit_test/helpers/test.php | 11 ++ modules/rest/tests/Rest_Controller_Test.php | 142 ++++------------------ modules/tag/tests/Tag_Rest_Helper_Test.php | 2 +- modules/tag/tests/Tag_Test.php | 2 +- modules/user/tests/No_Direct_ORM_Access_Test.php | 2 +- modules/user/tests/User_Groups_Test.php | 2 +- modules/user/tests/User_Installer_Test.php | 2 +- 35 files changed, 68 insertions(+), 151 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/akismet/tests/Akismet_Helper_Test.php b/modules/akismet/tests/Akismet_Helper_Test.php index b32e9a02..e185f280 100644 --- a/modules/akismet/tests/Akismet_Helper_Test.php +++ b/modules/akismet/tests/Akismet_Helper_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Akismet_Helper_Test extends Unit_Test_Case { +class Akismet_Helper_Test extends Gallery_Unit_Test_Case { private $_comment; public function setup() { diff --git a/modules/comment/tests/Comment_Event_Test.php b/modules/comment/tests/Comment_Event_Test.php index 5b7daef4..27272055 100644 --- a/modules/comment/tests/Comment_Event_Test.php +++ b/modules/comment/tests/Comment_Event_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Comment_Event_Test extends Unit_Test_Case { +class Comment_Event_Test extends Gallery_Unit_Test_Case { public function deleting_an_item_deletes_its_comments_too_test() { $album = test::random_album(); diff --git a/modules/comment/tests/Comment_Helper_Test.php b/modules/comment/tests/Comment_Helper_Test.php index d780aba6..7ba024c7 100644 --- a/modules/comment/tests/Comment_Helper_Test.php +++ b/modules/comment/tests/Comment_Helper_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Comment_Helper_Test extends Unit_Test_Case { +class Comment_Helper_Test extends Gallery_Unit_Test_Case { private $_ip_address; private $_user_agent; diff --git a/modules/comment/tests/Comment_Model_Test.php b/modules/comment/tests/Comment_Model_Test.php index c98eb63c..f0449c05 100644 --- a/modules/comment/tests/Comment_Model_Test.php +++ b/modules/comment/tests/Comment_Model_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Comment_Model_Test extends Unit_Test_Case { +class Comment_Model_Test extends Gallery_Unit_Test_Case { public function cant_view_comments_for_unviewable_items_test() { $album = test::random_album(); diff --git a/modules/digibug/tests/Digibug_Controller_Test.php b/modules/digibug/tests/Digibug_Controller_Test.php index 38dcd8e9..561dd3c9 100644 --- a/modules/digibug/tests/Digibug_Controller_Test.php +++ b/modules/digibug/tests/Digibug_Controller_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Digibug_Controller_Test extends Unit_Test_Case { +class Digibug_Controller_Test extends Gallery_Unit_Test_Case { private $_server; public function setup() { diff --git a/modules/exif/tests/Exif_Test.php b/modules/exif/tests/Exif_Test.php index 191bdb99..e4835b7f 100644 --- a/modules/exif/tests/Exif_Test.php +++ b/modules/exif/tests/Exif_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Exif_Test extends Unit_Test_Case { +class Exif_Test extends Gallery_Unit_Test_Case { public function exif_extract_test() { $photo = test::random_photo_unsaved() ->set_data_file(MODPATH . "exif/tests/data/image.jpg") diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index da72f12f..7ddd2875 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Access_Helper_Test extends Unit_Test_Case { +class Access_Helper_Test extends Gallery_Unit_Test_Case { private $_group; public function teardown() { diff --git a/modules/gallery/tests/Albums_Controller_Test.php b/modules/gallery/tests/Albums_Controller_Test.php index 26dc2571..76c9a628 100644 --- a/modules/gallery/tests/Albums_Controller_Test.php +++ b/modules/gallery/tests/Albums_Controller_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Albums_Controller_Test extends Unit_Test_Case { +class Albums_Controller_Test extends Gallery_Unit_Test_Case { public function setup() { $this->_save = array($_POST, $_SERVER); } diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php index d5bf37cc..1023568b 100644 --- a/modules/gallery/tests/Cache_Test.php +++ b/modules/gallery/tests/Cache_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Cache_Test extends Unit_Test_Case { +class Cache_Test extends Gallery_Unit_Test_Case { private $_driver; public function setup() { db::build()->delete("caches")->execute(); diff --git a/modules/gallery/tests/Controller_Auth_Test.php b/modules/gallery/tests/Controller_Auth_Test.php index 124d8b4c..c27196da 100644 --- a/modules/gallery/tests/Controller_Auth_Test.php +++ b/modules/gallery/tests/Controller_Auth_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Controller_Auth_Test extends Unit_Test_Case { +class Controller_Auth_Test extends Gallery_Unit_Test_Case { public function find_missing_auth_test() { $found = array(); $controllers = explode("\n", `git ls-files '*/*/controllers/*.php'`); diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index 6aa186e5..e58f73eb 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Database_Test extends Unit_Test_Case { +class Database_Test extends Gallery_Unit_Test_Case { function setup() { $config = Kohana_Config::instance(); $config->set("database.mock.connection.type", "mock"); diff --git a/modules/gallery/tests/Dir_Helper_Test.php b/modules/gallery/tests/Dir_Helper_Test.php index 46bb871c..69241447 100644 --- a/modules/gallery/tests/Dir_Helper_Test.php +++ b/modules/gallery/tests/Dir_Helper_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Dir_Helper_Test extends Unit_Test_Case { +class Dir_Helper_Test extends Gallery_Unit_Test_Case { public function remove_album_test() { $dirname = (VARPATH . "albums/testdir"); mkdir($dirname, 0777, true); diff --git a/modules/gallery/tests/DrawForm_Test.php b/modules/gallery/tests/DrawForm_Test.php index da8a6b04..f7b727c0 100644 --- a/modules/gallery/tests/DrawForm_Test.php +++ b/modules/gallery/tests/DrawForm_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class DrawForm_Test extends Unit_Test_Case { +class DrawForm_Test extends Gallery_Unit_Test_Case { function no_group_test() { $form = new Forge("test/controller", "", "post", array("id" => "g-test-group-form")); $form->input("title")->label(t("Title")); diff --git a/modules/gallery/tests/File_Structure_Test.php b/modules/gallery/tests/File_Structure_Test.php index b5026188..bffdf361 100644 --- a/modules/gallery/tests/File_Structure_Test.php +++ b/modules/gallery/tests/File_Structure_Test.php @@ -19,7 +19,7 @@ */ require_once(MODPATH . "gallery/tests/Gallery_Filters.php"); -class File_Structure_Test extends Unit_Test_Case { +class File_Structure_Test extends Gallery_Unit_Test_Case { public function no_trailing_closing_php_tag_test() { $dir = new GalleryCodeFilterIterator( new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DOCROOT))); diff --git a/modules/gallery/tests/Gallery_I18n_Test.php b/modules/gallery/tests/Gallery_I18n_Test.php index 5d2fd994..f6e50d71 100644 --- a/modules/gallery/tests/Gallery_I18n_Test.php +++ b/modules/gallery/tests/Gallery_I18n_Test.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Gallery_I18n_Test extends Unit_Test_Case { +class Gallery_I18n_Test extends Gallery_Unit_Test_Case { private $i18n; public function setup() { diff --git a/modules/gallery/tests/Gallery_Installer_Test.php b/modules/gallery/tests/Gallery_Installer_Test.php index 74a07b1a..3db434bc 100644 --- a/modules/gallery/tests/Gallery_Installer_Test.php +++ b/modules/gallery/tests/Gallery_Installer_Test.php @@ -22,7 +22,7 @@ * This test case operates under the assumption that gallery_installer::install() is called by the * test controller before it starts. */ -class Gallery_Installer_Test extends Unit_Test_Case { +class Gallery_Installer_Test extends Gallery_Unit_Test_Case { public function install_creates_dirs_test() { $this->assert_true(file_exists(VARPATH . "albums")); $this->assert_true(file_exists(VARPATH . "resizes")); diff --git a/modules/gallery/tests/Html_Helper_Test.php b/modules/gallery/tests/Html_Helper_Test.php index 1662b866..be318632 100644 --- a/modules/gallery/tests/Html_Helper_Test.php +++ b/modules/gallery/tests/Html_Helper_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Html_Helper_Test extends Unit_Test_Case { +class Html_Helper_Test extends Gallery_Unit_Test_Case { public function clean_test() { $safe_string = html::clean("hello

world

"); $this->assert_equal("hello <p >world</p>", diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index b3896c7a..5fa8d6b1 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -17,7 +17,7 @@ * 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 { +class Item_Helper_Test extends Gallery_Unit_Test_Case { public function viewable_test() { $album = test::random_album(); diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 284491a0..9ea74b16 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -17,7 +17,7 @@ * 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_Model_Test extends Unit_Test_Case { +class Item_Model_Test extends Gallery_Unit_Test_Case { public function saving_sets_created_and_updated_dates_test() { $item = test::random_photo(); $this->assert_true(!empty($item->created)); diff --git a/modules/gallery/tests/Locales_Helper_Test.php b/modules/gallery/tests/Locales_Helper_Test.php index 4c03d8d4..a2680928 100644 --- a/modules/gallery/tests/Locales_Helper_Test.php +++ b/modules/gallery/tests/Locales_Helper_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Locales_Helper_Test extends Unit_Test_Case { +class Locales_Helper_Test extends Gallery_Unit_Test_Case { static $installed_locales; static $default_locale; diff --git a/modules/gallery/tests/Menu_Test.php b/modules/gallery/tests/Menu_Test.php index c91aee0b..643aa727 100644 --- a/modules/gallery/tests/Menu_Test.php +++ b/modules/gallery/tests/Menu_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Menu_Test extends Unit_Test_Case { +class Menu_Test extends Gallery_Unit_Test_Case { public function find_menu_item_test() { $menu = new Menu(true); $menu diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php index 30adf2a0..1ffe1c57 100644 --- a/modules/gallery/tests/ORM_MPTT_Test.php +++ b/modules/gallery/tests/ORM_MPTT_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class ORM_MPTT_Test extends Unit_Test_Case { +class ORM_MPTT_Test extends Gallery_Unit_Test_Case { public function add_to_parent_test() { $album = test::random_album(); diff --git a/modules/gallery/tests/Photos_Controller_Test.php b/modules/gallery/tests/Photos_Controller_Test.php index f548b40d..6012ed1c 100644 --- a/modules/gallery/tests/Photos_Controller_Test.php +++ b/modules/gallery/tests/Photos_Controller_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Photos_Controller_Test extends Unit_Test_Case { +class Photos_Controller_Test extends Gallery_Unit_Test_Case { public function setup() { $this->_save = array($_POST, $_SERVER); $_SERVER["HTTP_REFERER"] = "HTTP_REFERER"; diff --git a/modules/gallery/tests/SafeString_Test.php b/modules/gallery/tests/SafeString_Test.php index 2c07d934..7002a874 100644 --- a/modules/gallery/tests/SafeString_Test.php +++ b/modules/gallery/tests/SafeString_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class SafeString_Test extends Unit_Test_Case { +class SafeString_Test extends Gallery_Unit_Test_Case { public function toString_escapes_for_html_test() { $safe_string = new SafeString("hello

world

"); $this->assert_equal("hello <p>world</p>", diff --git a/modules/gallery/tests/Sendmail_Test.php b/modules/gallery/tests/Sendmail_Test.php index f3a8d897..bc57e434 100644 --- a/modules/gallery/tests/Sendmail_Test.php +++ b/modules/gallery/tests/Sendmail_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Sendmail_Test extends Unit_Test_Case { +class Sendmail_Test extends Gallery_Unit_Test_Case { public function setup() { Kohana_Config::instance()->set("sendmail.from", "from@gallery3.com"); } diff --git a/modules/gallery/tests/Url_Security_Test.php b/modules/gallery/tests/Url_Security_Test.php index de25880f..255b3909 100644 --- a/modules/gallery/tests/Url_Security_Test.php +++ b/modules/gallery/tests/Url_Security_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Url_Security_Test extends Unit_Test_Case { +class Url_Security_Test extends Gallery_Unit_Test_Case { public function setup() { $this->save = array(Router::$current_uri, Router::$complete_uri, $_GET); } diff --git a/modules/gallery/tests/Var_Test.php b/modules/gallery/tests/Var_Test.php index 355d94a7..fb19da7a 100644 --- a/modules/gallery/tests/Var_Test.php +++ b/modules/gallery/tests/Var_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Var_Test extends Unit_Test_Case { +class Var_Test extends Gallery_Unit_Test_Case { public function add_parameter_test() { module::set_var("gallery", "Parameter", "original value"); $this->assert_equal("original value", module::get_var("gallery", "Parameter")); diff --git a/modules/gallery/tests/Xss_Security_Test.php b/modules/gallery/tests/Xss_Security_Test.php index b296d97c..a39a069d 100644 --- a/modules/gallery/tests/Xss_Security_Test.php +++ b/modules/gallery/tests/Xss_Security_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Xss_Security_Test extends Unit_Test_Case { +class Xss_Security_Test extends Gallery_Unit_Test_Case { public function find_unescaped_variables_in_views_test() { $found = array(); foreach (glob("*/*/views/*.php") as $view) { diff --git a/modules/gallery_unit_test/helpers/test.php b/modules/gallery_unit_test/helpers/test.php index 77948465..8e483c60 100644 --- a/modules/gallery_unit_test/helpers/test.php +++ b/modules/gallery_unit_test/helpers/test.php @@ -48,6 +48,11 @@ class test_Core { return test::random_photo_unsaved($parent)->save(); } + static function random_user($password="password") { + $rand = "name_" . rand(); + return identity::create_user($rand, $rand, $password, "$rand@rand.com"); + } + static function random_name($item=null) { $rand = "name_" . rand(); if ($item && $item->is_photo()) { @@ -59,4 +64,10 @@ class test_Core { static function starts_with($outer, $inner) { return strpos($outer, $inner) === 0; } + + static function call_and_capture($callback) { + ob_start(); + call_user_func($callback); + return ob_get_clean(); + } } diff --git a/modules/rest/tests/Rest_Controller_Test.php b/modules/rest/tests/Rest_Controller_Test.php index c881583c..ae5e6d48 100644 --- a/modules/rest/tests/Rest_Controller_Test.php +++ b/modules/rest/tests/Rest_Controller_Test.php @@ -17,108 +17,43 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Rest_Controller_Test extends Unit_Test_Case { +class Rest_Controller_Test extends Gallery_Unit_Test_Case { public function setup() { $this->_save = array($_GET, $_POST, $_SERVER); } - private function _create_user() { - if (empty($this->_user)) { - $this->_user = identity::create_user("access_test" . rand(), "Access Test", "password"); - $this->_key = ORM::factory("user_access_token"); - $this->_key->access_key = md5($this->_user->name . rand()); - $this->_key->user_id = $this->_user->id; - $this->_key->save(); - identity::set_active_user($this->_user); - } - return array($this->_key->access_key, $this->_user); - } - public function teardown() { list($_GET, $_POST, $_SERVER) = $this->_save; - if (!empty($this->_user)) { - try { - $this->_user->delete(); - } catch (Exception $e) { } - } - } - - private function _create_image($parent=null) { - $filename = MODPATH . "gallery/tests/test.jpg"; - $image_name = "image_" . rand(); - if (empty($parent)) { - $parent = ORM::factory("item", 1); - } - return photo::create($parent, $filename, "$image_name.jpg", $image_name); - } - - public function rest_access_key_exists_test() { - list ($access_key, $user) = $this->_create_user(); - $_SERVER["REQUEST_METHOD"] = "GET"; - $_GET["user"] = $user->name;; - $_GET["password"] = "password"; - - $this->assert_equal( - json_encode(array("status" => "OK", "token" => $access_key)), - $this->_call_controller()); } - public function rest_access_key_generated_test() { - list ($access_key, $user) = $this->_create_user(); - ORM::factory("user_access_token") - ->where("access_key", $access_key) - ->delete(); - $_SERVER["REQUEST_METHOD"] = "GET"; - $_GET["user"] = $user->name; - $_GET["password"] = "password"; + public function login_test() { + $user = test::random_user("password"); - $results = json_decode($this->_call_controller()); - - $this->assert_equal("OK", $results->status); - $this->assert_false(empty($results->token)); - } + // There's no access key at first + $this->assert_false( + ORM::factory("user_access_token")->where("user_id", "=", $user->id)->find()->loaded()); - public function rest_access_key_no_parameters_test() { - $_SERVER["REQUEST_METHOD"] = "GET"; - - try { - $this->_call_controller(); - } catch (Rest_Exception $e) { - $this->assert_equal(403, $e->getCode()); - $this->assert_equal("Forbidden", $e->getMessage()); - } catch (Exception $e) { - $this->assert_false(true, $e->__toString()); - } - } + $_POST["user"] = $user->name; + $_POST["password"] = "password"; - public function rest_access_key_user_not_found_test() { - $_SERVER["REQUEST_METHOD"] = "POST"; - $_POST["request"] = json_encode(array("user" => "access_test2", "password" => "password")); + $response = test::call_and_capture(array(new Rest_Controller(), "index")); + $expected = + ORM::factory("user_access_token")->where("user_id", "=", $user->id)->find()->access_key; - try { - $this->_call_controller(); - } catch (Rest_Exception $e) { - $this->assert_equal(403, $e->getCode()); - $this->assert_equal("Forbidden", $e->getMessage()); - } catch (Exception $e) { - $this->assert_false(true, $e->__toString()); - } + // Now there is an access key, and it was returned + $this->assert_equal(json_encode($expected), $response); } - public function rest_access_key_invalid_password_test() { - $_SERVER["REQUEST_METHOD"] = "POST"; + public function login_failed_test() { + $user = test::random_user("password"); + $_POST["user"] = $user->name; + $_POST["password"] = "WRONG PASSWORD"; - try { - $this->_call_controller(); - } catch (Rest_Exception $e) { - $this->assert_equal(403, $e->getCode()); - $this->assert_equal("Forbidden", $e->getMessage()); - } catch (Exception $e) { - $this->assert_false(true, $e->__toString()); - } + // @todo check the http response code + $this->assert_equal(null, test::call_and_capture(array(new Rest_Controller(), "index"))); } - public function rest_get_resource_no_request_key_test() { + public function rest_get_resource_no_request_key_test_() { $_SERVER["REQUEST_METHOD"] = "GET"; $photo = $this->_create_image(); @@ -132,7 +67,7 @@ class Rest_Controller_Test extends Unit_Test_Case { $this->_call_controller("rest", explode("/", $photo->relative_url()))); } - public function rest_get_resource_invalid_key_test() { + public function rest_get_resource_invalid_key_test_() { list ($access_key, $user) = $this->_create_user(); $_SERVER["HTTP_X_GALLERY_REQUEST_KEY"] = md5($access_key); // screw up the access key; $_SERVER["REQUEST_METHOD"] = "GET"; @@ -147,7 +82,7 @@ class Rest_Controller_Test extends Unit_Test_Case { } } - public function rest_get_resource_no_user_for_key_test() { + public function rest_get_resource_no_user_for_key_test_() { list ($access_key, $user) = $this->_create_user(); $_SERVER["REQUEST_METHOD"] = "GET"; $_SERVER["HTTP_X_GALLERY_REQUEST_KEY"] = $access_key; @@ -166,7 +101,7 @@ class Rest_Controller_Test extends Unit_Test_Case { } } - public function rest_get_resource_no_handler_test() { + public function rest_get_resource_no_handler_test_() { list ($access_key, $user) = $this->_create_user(); $_SERVER["REQUEST_METHOD"] = "GET"; $_SERVER["HTTP_X_GALLERY_REQUEST_KEY"] = $access_key; @@ -183,7 +118,7 @@ class Rest_Controller_Test extends Unit_Test_Case { } } - public function rest_get_resource_test() { + public function rest_get_resource_test_() { list ($access_key, $user) = $this->_create_user(); $_SERVER["REQUEST_METHOD"] = "GET"; $_SERVER["HTTP_X_GALLERY_REQUEST_KEY"] = $access_key; @@ -198,33 +133,4 @@ class Rest_Controller_Test extends Unit_Test_Case { "internet_address" => $photo->slug))), $this->_call_controller("rest", explode("/", $photo->relative_url()))); } - - private function _call_controller($method="access_key", $arg=null) { - $controller = new Rest_Controller(); - - ob_start(); - call_user_func_array(array($controller, $method), $arg); - $results = ob_get_contents(); - ob_end_clean(); - - return $results; - } -} - -class rest_rest { - static $request = null; - - static function get($request) { - self::$request = $request; - $item = ORM::factory("item") - ->where("relative_url_cache", "=", implode("/", $request->arguments)) - ->find(); - $response["path"] = $item->relative_url(); - $response["title"] = $item->title; - $response["thumb_url"] = $item->thumb_url(); - $response["description"] = $item->description; - $response["internet_address"] = $item->slug; - return rest::reply(array($item->type => $response)); - } - } diff --git a/modules/tag/tests/Tag_Rest_Helper_Test.php b/modules/tag/tests/Tag_Rest_Helper_Test.php index 555539fd..c2d55ba4 100644 --- a/modules/tag/tests/Tag_Rest_Helper_Test.php +++ b/modules/tag/tests/Tag_Rest_Helper_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Tag_Rest_Helper_Test extends Unit_Test_Case { +class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function setup() { try { Database::instance()->query("TRUNCATE {tags}"); diff --git a/modules/tag/tests/Tag_Test.php b/modules/tag/tests/Tag_Test.php index c96e7f2b..c3243145 100644 --- a/modules/tag/tests/Tag_Test.php +++ b/modules/tag/tests/Tag_Test.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Tag_Test extends Unit_Test_Case { +class Tag_Test extends Gallery_Unit_Test_Case { public function create_tag_test() { $rand = rand(); $root = ORM::factory("item", 1); diff --git a/modules/user/tests/No_Direct_ORM_Access_Test.php b/modules/user/tests/No_Direct_ORM_Access_Test.php index 440321fa..c372258e 100644 --- a/modules/user/tests/No_Direct_ORM_Access_Test.php +++ b/modules/user/tests/No_Direct_ORM_Access_Test.php @@ -19,7 +19,7 @@ */ require_once(MODPATH . "gallery/tests/Gallery_Filters.php"); -class No_Direct_ORM_Access_Test extends Unit_Test_Case { +class No_Direct_ORM_Access_Test extends Gallery_Unit_Test_Case { public function no_access_to_users_table_test() { $dir = new UserModuleFilterIterator( new PhpCodeFilterIterator( diff --git a/modules/user/tests/User_Groups_Test.php b/modules/user/tests/User_Groups_Test.php index 163b7d79..089ab9a6 100644 --- a/modules/user/tests/User_Groups_Test.php +++ b/modules/user/tests/User_Groups_Test.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class User_Groups_Test extends Unit_Test_Case { +class User_Groups_Test extends Gallery_Unit_Test_Case { public function teardown() { try { $group = ORM::factory("group")->where("name", "=", "user_groups_test")->find(); diff --git a/modules/user/tests/User_Installer_Test.php b/modules/user/tests/User_Installer_Test.php index 12a10eda..b3c5960a 100644 --- a/modules/user/tests/User_Installer_Test.php +++ b/modules/user/tests/User_Installer_Test.php @@ -22,7 +22,7 @@ * This test case operates under the assumption that user_installer::install() is called by the * test controller before it starts. */ -class User_Installer_Test extends Unit_Test_Case { +class User_Installer_Test extends Gallery_Unit_Test_Case { public function install_creates_admin_user_test() { $user = ORM::factory("user", 1); $this->assert_equal("guest", $user->name); -- cgit v1.2.3 From 995faaa27fc870589e346f7ef65e0bd7cabfe047 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 20 Jan 2010 22:45:19 -0800 Subject: Stop using MY_ORM::original(). It's got very odd semantics and we are not capturing all cases for setting and resetting $original, which leads to some weird and hard to reproduce behavior. Instead, if we need the original just reload it from the database. This may result in a somewhat excessive load in places, but we'll have to fix that in a later optimization pass. --- modules/gallery/models/item.php | 104 +++++++++++++++--------------- modules/gallery/tests/Item_Model_Test.php | 1 + 2 files changed, 54 insertions(+), 51 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 58ff86ed..19c379ab 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -415,65 +415,58 @@ class Item_Model extends ORM_MPTT { } else { // Update an existing item - // The new values have to be valid before we do anything with them. If we make any - // other changes before we call parent::save() below, we'll have to validate those changes - // again. But, we can't take any action on these values until we know they're ok so this - // is unavoidable. - if (!$this->_valid) { - $this->validate(); - } - - $original = clone $this->original(); - - if ($original->name != $this->name || $original->parent_id != $this->parent_id) { - // Get the old relative path for when we rename or move below - if (!isset($this->relative_path_cache)) { - $this->_build_relative_caches(); // but don't call save() - } - $before_save = clone $this; + // If any significant fields have changed, load up a copy of the original item and + // keep it around. + if (array_intersect($this->changed, array("parent_id", "name", "slug"))) { + $original = ORM::factory("item")->where("id", "=", $this->id)->find(); + $original->_build_relative_caches(); $this->relative_path_cache = null; - } - - if ($original->slug != $this->slug) { $this->relative_url_cache = null; } parent::save(); - if ($original->parent_id != $this->parent_id || $original->name != $this->name) { + // Now update the filesystem and any database caches if there were significant value + // changes. If anything past this point fails, then we'll have an inconsistent database + // so this code should be as robust as we can make it. + if (isset($original)) { + // Update the MPTT pointers, if necessary. We have to do this before we generate any + // cached paths! if ($original->parent_id != $this->parent_id) { - // Move the ORM pointers around parent::move_to($this->parent()); } - // Move all of the items associated data files - @rename($before_save->file_path(), $this->file_path()); - if ($this->is_album()) { - @rename(dirname($before_save->resize_path()), dirname($this->resize_path())); - @rename(dirname($before_save->thumb_path()), dirname($this->thumb_path())); - } else { - @rename($before_save->resize_path(), $this->resize_path()); - @rename($before_save->thumb_path(), $this->thumb_path()); - } + if ($original->parent_id != $this->parent_id || $original->name != $this->name) { + // Move all of the items associated data files + @rename($original->file_path(), $this->file_path()); + if ($this->is_album()) { + @rename(dirname($original->resize_path()), dirname($this->resize_path())); + @rename(dirname($original->thumb_path()), dirname($this->thumb_path())); + } else { + @rename($original->resize_path(), $this->resize_path()); + @rename($original->thumb_path(), $this->thumb_path()); + } - if ($original->parent_id != $this->parent_id) { - // This will result in 2 events since we'll still fire the item_updated event below - module::event("item_moved", $this, $original->parent()); + + if ($original->parent_id != $this->parent_id) { + // This will result in 2 events since we'll still fire the item_updated event below + module::event("item_moved", $this, $original->parent()); + } } - } - // Changing the name, slug or parent ripples downwards - if ($this->is_album() && - ($original->name != $this->name || - $original->slug != $this->slug || - $original->parent_id != $this->parent_id)) { - db::build() - ->update("items") - ->set("relative_url_cache", null) - ->set("relative_path_cache", null) - ->where("left_ptr", ">", $this->left_ptr) - ->where("right_ptr", "<", $this->right_ptr) - ->execute(); + // Changing the name, slug or parent ripples downwards + if ($this->is_album() && + ($original->name != $this->name || + $original->slug != $this->slug || + $original->parent_id != $this->parent_id)) { + db::build() + ->update("items") + ->set("relative_url_cache", null) + ->set("relative_path_cache", null) + ->where("left_ptr", ">", $this->left_ptr) + ->where("right_ptr", "<", $this->right_ptr) + ->execute(); + } } module::event("item_updated", $original, $this); @@ -784,27 +777,36 @@ class Item_Model extends ORM_MPTT { return; } else if (rtrim($this->name, ".") !== $this->name) { $v->add_error("name", "no_trailing_period"); - } else if ($this->is_movie() || $this->is_photo()) { - if ($this->original()->loaded()) { + return; + } + + if ($this->is_movie() || $this->is_photo()) { + if ($this->loaded()) { // Existing items can't change their extension + $original = ORM::factory("item")->where("id", "=", $this->id)->find(); $new_ext = pathinfo($this->name, PATHINFO_EXTENSION); - $old_ext = pathinfo($this->original()->name, PATHINFO_EXTENSION); + $old_ext = pathinfo($original->name, PATHINFO_EXTENSION); if (strcasecmp($new_ext, $old_ext)) { $v->add_error("name", "illegal_data_file_extension"); + return; } } else { // New items must have an extension if (!pathinfo($this->name, PATHINFO_EXTENSION)) { $v->add_error("name", "illegal_data_file_extension"); + return; } } - } else if (db::build() + } + + if (db::build() ->from("items") ->where("parent_id", "=", $this->parent_id) ->where("name", "=", $this->name) ->merge_where($this->id ? array(array("id", "<>", $this->id)) : null) ->count_records()) { $v->add_error("name", "conflict"); + return; } } @@ -900,7 +902,7 @@ class Item_Model extends ORM_MPTT { * This field cannot be changed after it's been set. */ public function read_only(Validation $v, $field) { - if ($this->original()->loaded() && $this->original()->$field != $this->$field) { + if ($this->loaded() && isset($this->changed[$field])) { $v->add_error($field, "read_only"); } } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 9ea74b16..efad660e 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -139,6 +139,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { try { $item->name = $item2->name; + print "SAVE\n"; $item->save(); } catch (ORM_Validation_Exception $e) { $this->assert_true(in_array("conflict", $e->validation->errors())); -- cgit v1.2.3 From feefdfd533dd4e82a2edd5c0b342322889877b79 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 20 Jan 2010 22:51:18 -0800 Subject: Stop using MY_ORM::original(). --- modules/gallery/tests/Item_Model_Test.php | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index efad660e..035ecb51 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -149,16 +149,6 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $this->assert_false(true, "rename should conflict"); } - public function save_original_values_test() { - $item = test::random_photo_unsaved(); - $item->title = "ORIGINAL_VALUE"; - $item->save(); - $item->title = "NEW_VALUE"; - - $this->assert_same("ORIGINAL_VALUE", $item->original()->title); - $this->assert_same("NEW_VALUE", $item->title); - } - public function move_album_test() { $album2 = test::random_album(); $album1 = test::random_album($album2); -- cgit v1.2.3 From 46d4d778ad9febf175380cd82e0a10da33293d36 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 20 Jan 2010 23:33:09 -0800 Subject: Remove debug code. --- modules/gallery/tests/Item_Model_Test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 035ecb51..1e77076a 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -139,7 +139,6 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { try { $item->name = $item2->name; - print "SAVE\n"; $item->save(); } catch (ORM_Validation_Exception $e) { $this->assert_true(in_array("conflict", $e->validation->errors())); -- cgit v1.2.3 From 1e35cf28eef8d88e8e5c611db108667526a0767b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 21 Jan 2010 08:29:30 -0800 Subject: Reload the album after adding the photo so that MPTT pointers are correct. --- modules/gallery/tests/Item_Helper_Test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index 5fa8d6b1..cdbdd324 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -22,6 +22,7 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case { public function viewable_test() { $album = test::random_album(); $item = test::random_photo($album); + $album->reload(); identity::set_active_user(identity::guest()); // We can see the item when permissions are granted -- cgit v1.2.3 From b278f9680c7afd7de6e7e9a64a724d87b6e04c93 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 21 Jan 2010 19:05:53 -0800 Subject: Can't call ORM_MPTT::move_to() externally, so call Item_Model::save() instead. --- modules/gallery/tests/ORM_MPTT_Test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php index 1ffe1c57..8c850a86 100644 --- a/modules/gallery/tests/ORM_MPTT_Test.php +++ b/modules/gallery/tests/ORM_MPTT_Test.php @@ -66,7 +66,8 @@ class ORM_MPTT_Test extends Gallery_Unit_Test_Case { $album1_2->reload(); $album1_1_1->reload(); - $album1_1_1->move_to($album1_2); + $album1_1_1->parent_id = $album1_2->id; + $album1_1_1->save(); $album1_1->reload(); $album1_2->reload(); -- cgit v1.2.3 From 313f816818c6ee0db9354992005c9b3ad6da15d4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 21 Jan 2010 19:06:32 -0800 Subject: Fix a minor bad expectation. --- modules/gallery/tests/Photos_Controller_Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Photos_Controller_Test.php b/modules/gallery/tests/Photos_Controller_Test.php index 6012ed1c..50d49fcc 100644 --- a/modules/gallery/tests/Photos_Controller_Test.php +++ b/modules/gallery/tests/Photos_Controller_Test.php @@ -48,7 +48,7 @@ class Photos_Controller_Test extends Gallery_Unit_Test_Case { $this->assert_equal("new-slug", $photo->slug); $this->assert_equal("new title", $photo->title); $this->assert_equal("new description", $photo->description); - $this->assert_equal("new name.jpeg", $photo->name); + $this->assert_equal("new name.jpg", $photo->name); } public function change_photo_no_csrf_fails_test() { -- cgit v1.2.3 From f7f4df64b9abe726fae30cc44b8e640f68ef1415 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 21 Jan 2010 20:04:46 -0800 Subject: Exclude modules/gallery_unit_test/views/kohana/error.php --- modules/gallery/tests/File_Structure_Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/File_Structure_Test.php b/modules/gallery/tests/File_Structure_Test.php index bffdf361..4590e95d 100644 --- a/modules/gallery/tests/File_Structure_Test.php +++ b/modules/gallery/tests/File_Structure_Test.php @@ -36,7 +36,7 @@ class File_Structure_Test extends Gallery_Unit_Test_Case { $dir = new GalleryCodeFilterIterator( new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DOCROOT))); foreach ($dir as $file) { - if (strpos($file, "modules/gallery/views/kohana/error.php")) { + if (strpos($file, "views/kohana/error.php")) { continue; } -- cgit v1.2.3 From 709d797408b2821fd8ec97c83fa982519a028bf8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 21 Jan 2010 20:10:45 -0800 Subject: Make sure that we actually don't have permissions, to avoid contamination w/ other tests. --- modules/gallery/tests/Gallery_Rest_Helper_Test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Gallery_Rest_Helper_Test.php b/modules/gallery/tests/Gallery_Rest_Helper_Test.php index dcd9a9db..7586e010 100644 --- a/modules/gallery/tests/Gallery_Rest_Helper_Test.php +++ b/modules/gallery/tests/Gallery_Rest_Helper_Test.php @@ -194,6 +194,7 @@ class Gallery_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function delete_album_fails_without_permission_test() { $album1 = test::random_album(); + access::deny(identity::everybody(), "edit", $album1); $request->url = rest::url("gallery", $album1); try { -- cgit v1.2.3 From 8788880065ca199216df552f66fd065c3f35a0aa Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 21 Jan 2010 20:18:19 -0800 Subject: We don't need CSRF in Rest_Controller::__call() because we use access tokens. --- modules/gallery/tests/controller_auth_data.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index beabee49..71ae5a0c 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -20,8 +20,8 @@ modules/gallery/controllers/simple_uploader.php start modules/gallery/controllers/simple_uploader.php finish DIRTY_AUTH modules/gallery/controllers/upgrader.php index DIRTY_AUTH modules/gallery/controllers/welcome_message.php index DIRTY_AUTH -modules/rest/controllers/rest.php access_key DIRTY_CSRF|DIRTY_AUTH -modules/rest/controllers/rest.php __call DIRTY_AUTH +modules/rest/controllers/rest.php index DIRTY_CSRF|DIRTY_AUTH +modules/rest/controllers/rest.php __call DIRTY_CSRF|DIRTY_AUTH modules/rss/controllers/rss.php feed DIRTY_CSRF|DIRTY_AUTH modules/search/controllers/search.php index DIRTY_CSRF|DIRTY_AUTH modules/server_add/controllers/admin_server_add.php autocomplete DIRTY_CSRF -- cgit v1.2.3 From cb8b31d70ccd4872b122c204095ca8a439487c5d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 22 Jan 2010 00:49:05 -0800 Subject: Updated tests to pass after recent refactor of gallery_rest -> item_rest. --- modules/gallery/tests/Item_Rest_Helper_Test.php | 213 ++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 modules/gallery/tests/Item_Rest_Helper_Test.php (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php new file mode 100644 index 00000000..115d3b1b --- /dev/null +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -0,0 +1,213 @@ +assert_equal($album->id, $resolved->id); + } + + public function get_scope_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $photo2 = test::random_photo($album2); + $album1->reload(); + + // No scope is the same as "direct" + $request->url = rest::url("item", $album1); + $request->params = new stdClass(); + $this->assert_equal_array( + array("url" => rest::url("item", $album1), + "resource" => $album1->as_array(), + "members" => array( + rest::url("item", $photo1), + rest::url("item", $album2)), + "relationships" => array( + "tags" => array())), + item_rest::get($request)); + + $request->url = rest::url("item", $album1); + $request->params->scope = "direct"; + $this->assert_equal_array( + array("url" => rest::url("item", $album1), + "resource" => $album1->as_array(), + "members" => array( + rest::url("item", $photo1), + rest::url("item", $album2)), + "relationships" => array( + "tags" => array())), + item_rest::get($request)); + + $request->url = rest::url("item", $album1); + $request->params->scope = "all"; + $this->assert_equal_array( + array("url" => rest::url("item", $album1), + "resource" => $album1->as_array(), + "members" => array( + rest::url("item", $photo1), + rest::url("item", $album2), + rest::url("item", $photo2)), + "relationships" => array( + "tags" => array())), + item_rest::get($request)); + } + + public function get_children_like_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $photo2 = test::random_photo_unsaved($album1); + $photo2->name = "foo.jpg"; + $photo2->save(); + $album1->reload(); + + $request->url = rest::url("item", $album1); + $request->params->name = "foo"; + $this->assert_equal_array( + array("url" => rest::url("item", $album1), + "resource" => $album1->as_array(), + "members" => array( + rest::url("item", $photo2)), + "relationships" => array( + "tags" => array())), + item_rest::get($request)); + } + + public function get_children_type_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $album1->reload(); + + $request->url = rest::url("item", $album1); + $request->params->type = "album"; + $this->assert_equal_array( + array("url" => rest::url("item", $album1), + "resource" => $album1->as_array(), + "members" => array( + rest::url("item", $album2)), + "relationships" => array( + "tags" => array())), + item_rest::get($request)); + } + + public function update_album_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); + + $request->url = rest::url("item", $album1); + $request->params->title = "my new title"; + + item_rest::put($request); + $this->assert_equal("my new title", $album1->reload()->title); + } + + public function update_album_illegal_value_fails_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); + + $request->url = rest::url("item", $album1); + $request->params->title = "my new title"; + $request->params->slug = "not url safe"; + + try { + item_rest::put($request); + } catch (ORM_Validation_Exception $e) { + $this->assert_equal(array("slug" => "not_url_safe"), $e->validation->errors()); + return; + } + $this->assert_true(false, "Shouldn't get here"); + } + + public function add_album_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); + + $request->url = rest::url("item", $album1); + $request->params->type = "album"; + $request->params->name = "my album"; + $request->params->title = "my album"; + $response = item_rest::post($request); + $new_album = rest::resolve($response["url"]); + + $this->assert_true($new_album->is_album()); + $this->assert_equal($album1->id, $new_album->parent_id); + } + + public function add_album_illegal_value_fails_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); + + $request->url = rest::url("item", $album1); + $request->params->type = "album"; + $request->params->name = "my album"; + $request->params->title = "my album"; + $request->params->slug = "not url safe"; + + try { + item_rest::post($request); + } catch (ORM_Validation_Exception $e) { + $this->assert_equal(array("slug" => "not_url_safe"), $e->validation->errors()); + return; + } + $this->assert_true(false, "Shouldn't get here"); + } + + + public function add_photo_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); + + $request->url = rest::url("item", $album1); + $request->params->type = "photo"; + $request->params->name = "my photo.jpg"; + $request->file = MODPATH . "gallery/tests/test.jpg"; + $response = item_rest::post($request); + $new_photo = rest::resolve($response["url"]); + + $this->assert_true($new_photo->is_photo()); + $this->assert_equal($album1->id, $new_photo->parent_id); + } + + public function delete_album_test() { + $album1 = test::random_album(); + access::allow(identity::everybody(), "edit", $album1); + + $request->url = rest::url("item", $album1); + item_rest::delete($request); + + $album1->reload(); + $this->assert_false($album1->loaded()); + } + + public function delete_album_fails_without_permission_test() { + $album1 = test::random_album(); + access::deny(identity::everybody(), "edit", $album1); + + $request->url = rest::url("item", $album1); + try { + item_rest::delete($request); + } catch (Exception $e) { + $this->assert_equal("@todo FORBIDDEN", $e->getMessage()); + return; + } + $this->assert_true(false, "Shouldn't get here"); + } +} -- cgit v1.2.3 From 25dc3e1a7bc7736363ca642a6e67ac1644266f68 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 22 Jan 2010 01:11:03 -0800 Subject: Moved to Item_Rest_Helper_Test.php --- modules/gallery/tests/Gallery_Rest_Helper_Test.php | 208 --------------------- 1 file changed, 208 deletions(-) delete mode 100644 modules/gallery/tests/Gallery_Rest_Helper_Test.php (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Gallery_Rest_Helper_Test.php b/modules/gallery/tests/Gallery_Rest_Helper_Test.php deleted file mode 100644 index 7586e010..00000000 --- a/modules/gallery/tests/Gallery_Rest_Helper_Test.php +++ /dev/null @@ -1,208 +0,0 @@ -_save = array($_GET, $_POST, $_SERVER, $_FILES); - } - - public function teardown() { - list($_GET, $_POST, $_SERVER, $_FILES) = $this->_save; - } - - public function resolve_test() { - $album = test::random_album(); - $resolved = rest::resolve(rest::url("gallery", $album)); - $this->assert_equal($album->id, $resolved->id); - } - - public function get_scope_test() { - $album1 = test::random_album(); - $photo1 = test::random_photo($album1); - $album2 = test::random_album($album1); - $photo2 = test::random_photo($album2); - $album1->reload(); - - // No scope is the same as "direct" - $request->url = rest::url("gallery", $album1); - $request->params = new stdClass(); - $this->assert_equal_array( - array("resource" => $album1->as_array(), - "members" => array( - rest::url("gallery", $photo1), - rest::url("gallery", $album2))), - gallery_rest::get($request)); - - $request->url = rest::url("gallery", $album1); - $request->params->scope = "direct"; - $this->assert_equal_array( - array("resource" => $album1->as_array(), - "members" => array( - rest::url("gallery", $photo1), - rest::url("gallery", $album2))), - gallery_rest::get($request)); - - $request->url = rest::url("gallery", $album1); - $request->params->scope = "all"; - $this->assert_equal_array( - array("resource" => $album1->as_array(), - "members" => array( - rest::url("gallery", $photo1), - rest::url("gallery", $album2), - rest::url("gallery", $photo2))), - gallery_rest::get($request)); - } - - public function get_children_like_test() { - $album1 = test::random_album(); - $photo1 = test::random_photo($album1); - $photo2 = test::random_photo_unsaved($album1); - $photo2->name = "foo.jpg"; - $photo2->save(); - $album1->reload(); - - $request->url = rest::url("gallery", $album1); - $request->params->name = "foo"; - $this->assert_equal_array( - array("resource" => $album1->as_array(), - "members" => array( - rest::url("gallery", $photo2))), - gallery_rest::get($request)); - } - - public function get_children_type_test() { - $album1 = test::random_album(); - $photo1 = test::random_photo($album1); - $album2 = test::random_album($album1); - $album1->reload(); - - $request->url = rest::url("gallery", $album1); - $request->params->type = "album"; - $this->assert_equal_array( - array("resource" => $album1->as_array(), - "members" => array( - rest::url("gallery", $album2))), - gallery_rest::get($request)); - } - - public function update_album_test() { - $album1 = test::random_album(); - access::allow(identity::everybody(), "edit", $album1); - - $request->url = rest::url("gallery", $album1); - $request->params->title = "my new title"; - - $this->assert_equal_array( - array("url" => rest::url("gallery", $album1)), - gallery_rest::put($request)); - $this->assert_equal("my new title", $album1->reload()->title); - } - - public function update_album_illegal_value_fails_test() { - $album1 = test::random_album(); - access::allow(identity::everybody(), "edit", $album1); - - $request->url = rest::url("gallery", $album1); - $request->params->title = "my new title"; - $request->params->slug = "not url safe"; - - try { - gallery_rest::put($request); - } catch (ORM_Validation_Exception $e) { - $this->assert_equal(array("slug" => "not_url_safe"), $e->validation->errors()); - return; - } - $this->assert_true(false, "Shouldn't get here"); - } - - public function add_album_test() { - $album1 = test::random_album(); - access::allow(identity::everybody(), "edit", $album1); - - $request->url = rest::url("gallery", $album1); - $request->params->type = "album"; - $request->params->name = "my album"; - $request->params->title = "my album"; - $response = gallery_rest::post($request); - $new_album = rest::resolve($response["url"]); - - $this->assert_true($new_album->is_album()); - $this->assert_equal($album1->id, $new_album->parent_id); - } - - public function add_album_illegal_value_fails_test() { - $album1 = test::random_album(); - access::allow(identity::everybody(), "edit", $album1); - - $request->url = rest::url("gallery", $album1); - $request->params->type = "album"; - $request->params->name = "my album"; - $request->params->title = "my album"; - $request->params->slug = "not url safe"; - - try { - gallery_rest::post($request); - } catch (ORM_Validation_Exception $e) { - $this->assert_equal(array("slug" => "not_url_safe"), $e->validation->errors()); - return; - } - $this->assert_true(false, "Shouldn't get here"); - } - - - public function add_photo_test() { - $album1 = test::random_album(); - access::allow(identity::everybody(), "edit", $album1); - - $request->url = rest::url("gallery", $album1); - $request->params->type = "photo"; - $request->params->name = "my photo.jpg"; - $request->file = MODPATH . "gallery/tests/test.jpg"; - $response = gallery_rest::post($request); - $new_photo = rest::resolve($response["url"]); - - $this->assert_true($new_photo->is_photo()); - $this->assert_equal($album1->id, $new_photo->parent_id); - } - - public function delete_album_test() { - $album1 = test::random_album(); - access::allow(identity::everybody(), "edit", $album1); - - $request->url = rest::url("gallery", $album1); - gallery_rest::delete($request); - - $album1->reload(); - $this->assert_false($album1->loaded()); - } - - public function delete_album_fails_without_permission_test() { - $album1 = test::random_album(); - access::deny(identity::everybody(), "edit", $album1); - - $request->url = rest::url("gallery", $album1); - try { - gallery_rest::delete($request); - } catch (Exception $e) { - $this->assert_equal("@todo FORBIDDEN", $e->getMessage()); - return; - } - $this->assert_true(false, "Shouldn't get here"); - } -} -- cgit v1.2.3 From 4960061b562a0d5adafd767af7856d1a80a549a6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 23 Jan 2010 11:35:26 -0800 Subject: Don't use ORM_MPTT::move_to directly, it's protected. --- modules/gallery/tests/ORM_MPTT_Test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php index 8c850a86..5e741537 100644 --- a/modules/gallery/tests/ORM_MPTT_Test.php +++ b/modules/gallery/tests/ORM_MPTT_Test.php @@ -90,7 +90,8 @@ class ORM_MPTT_Test extends Gallery_Unit_Test_Case { $album3 = test::random_album($album2); try { - $album1->move_to($album3); + $album1->parent_id = $album3->id; + $album1->save(); $this->assert_true(false, "We should be unable to move an item inside its own hierarchy"); } catch (Exception $e) { // pass -- cgit v1.2.3 From a60969401852ddda878bd2a3444d6378899d4dcc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 23 Jan 2010 12:13:14 -0800 Subject: Update tests for recent REST changes. --- modules/gallery/tests/Item_Rest_Helper_Test.php | 20 +++++++++++++++----- modules/rest/tests/Rest_Controller_Test.php | 2 +- modules/tag/helpers/tag_rest.php | 5 +++-- modules/tag/tests/Tag_Rest_Helper_Test.php | 8 ++++++-- 4 files changed, 25 insertions(+), 10 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index 115d3b1b..8ce6bc43 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -41,7 +41,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { rest::url("item", $photo1), rest::url("item", $album2)), "relationships" => array( - "tags" => array())), + "tags" => array( + "url" => rest::url("item_tags", $album1), + "members" => array()))), item_rest::get($request)); $request->url = rest::url("item", $album1); @@ -53,7 +55,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { rest::url("item", $photo1), rest::url("item", $album2)), "relationships" => array( - "tags" => array())), + "tags" => array( + "url" => rest::url("item_tags", $album1), + "members" => array()))), item_rest::get($request)); $request->url = rest::url("item", $album1); @@ -66,7 +70,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { rest::url("item", $album2), rest::url("item", $photo2)), "relationships" => array( - "tags" => array())), + "tags" => array( + "url" => rest::url("item_tags", $album1), + "members" => array()))), item_rest::get($request)); } @@ -86,7 +92,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { "members" => array( rest::url("item", $photo2)), "relationships" => array( - "tags" => array())), + "tags" => array( + "url" => rest::url("item_tags", $album1), + "members" => array()))), item_rest::get($request)); } @@ -104,7 +112,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { "members" => array( rest::url("item", $album2)), "relationships" => array( - "tags" => array())), + "tags" => array( + "url" => rest::url("item_tags", $album1), + "members" => array() ))), item_rest::get($request)); } diff --git a/modules/rest/tests/Rest_Controller_Test.php b/modules/rest/tests/Rest_Controller_Test.php index 377f5334..5e624112 100644 --- a/modules/rest/tests/Rest_Controller_Test.php +++ b/modules/rest/tests/Rest_Controller_Test.php @@ -130,7 +130,7 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case { try { test::call_and_capture(array(new Rest_Controller(), "mock")); } catch (Exception $e) { - $this->assert_equal(403, $e->getCode()); + $this->assert_equal(400, $e->getCode()); return; } $this->assert_true(false, "Shouldn't get here"); diff --git a/modules/tag/helpers/tag_rest.php b/modules/tag/helpers/tag_rest.php index 4fe9bef9..4b2a4b46 100644 --- a/modules/tag/helpers/tag_rest.php +++ b/modules/tag/helpers/tag_rest.php @@ -31,8 +31,9 @@ class tag_rest_Core { "url" => $request->url, "resource" => $tag->as_array(), "relationships" => array( - "url" => rest::url("tag_items", $tag), - "items" => $tag_items)); + "items" => array( + "url" => rest::url("tag_items", $tag), + "members" => $tag_items))); } static function post($request) { diff --git a/modules/tag/tests/Tag_Rest_Helper_Test.php b/modules/tag/tests/Tag_Rest_Helper_Test.php index cbd7b6cd..eacf91b3 100644 --- a/modules/tag/tests/Tag_Rest_Helper_Test.php +++ b/modules/tag/tests/Tag_Rest_Helper_Test.php @@ -34,7 +34,9 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { "resource" => $tag->as_array(), "relationships" => array( "items" => array( - rest::url("tag_item", $tag, item::root())))), + "url" => rest::url("tag_items", $tag), + "members" => array( + rest::url("tag_item", $tag, item::root()))))), tag_rest::get($request)); } @@ -56,7 +58,9 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("tag", $tag), "resource" => $tag->as_array(), "relationships" => array( - "items" => array())), + "items" => array( + "url" => rest::url("tag_items", $tag), + "members" => array()))), tag_rest::get($request)); } -- cgit v1.2.3 From d4308e4d35a585a1ce17e4340894e520268260b7 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 23 Jan 2010 12:16:04 -0800 Subject: Updated --- modules/gallery/tests/xss_data.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 1530c73e..5f6e8520 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -98,10 +98,14 @@ modules/gallery/views/admin_maintenance.html.php 158 DIRTY $task- modules/gallery/views/admin_maintenance_show_log.html.php 8 DIRTY_JS url::site("admin/maintenance/save_log/$task->id?csrf=$csrf") modules/gallery/views/admin_maintenance_show_log.html.php 13 DIRTY $task->name modules/gallery/views/admin_maintenance_task.html.php 55 DIRTY $task->name -modules/gallery/views/admin_modules.html.php 10 DIRTY access::csrf_form_field() -modules/gallery/views/admin_modules.html.php 19 DIRTY_ATTR text::alternate("g-odd","g-even") -modules/gallery/views/admin_modules.html.php 22 DIRTY form::checkbox($data,'1',module::is_active($module_name)) -modules/gallery/views/admin_modules.html.php 24 DIRTY $module_info->version +modules/gallery/views/admin_modules.html.php 48 DIRTY access::csrf_form_field() +modules/gallery/views/admin_modules.html.php 57 DIRTY_ATTR text::alternate("g-odd","g-even") +modules/gallery/views/admin_modules.html.php 60 DIRTY form::checkbox($data,'1',module::is_active($module_name)) +modules/gallery/views/admin_modules.html.php 62 DIRTY $module_info->version +modules/gallery/views/admin_modules_confirm.html.php 11 DIRTY_ATTR $class +modules/gallery/views/admin_modules_confirm.html.php 11 DIRTY $message +modules/gallery/views/admin_modules_confirm.html.php 16 DIRTY access::csrf_form_field() +modules/gallery/views/admin_modules_confirm.html.php 18 DIRTY form::hidden($module,1) modules/gallery/views/admin_sidebar.html.php 50 DIRTY $available modules/gallery/views/admin_sidebar.html.php 58 DIRTY $active modules/gallery/views/admin_sidebar_blocks.html.php 4 DIRTY_ATTR $ref -- cgit v1.2.3 From c5cdd13b41c2911390a67e22700fa414dfe53ea2 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 26 Jan 2010 13:26:03 -0800 Subject: Added view_permissions_propagate_down_to_photos_test(). --- modules/gallery/tests/Access_Helper_Test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index 7ddd2875..35cf5edb 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -193,6 +193,18 @@ class Access_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_true(access::group_can(identity::everybody(), "view", $album)); } + public function view_permissions_propagate_down_to_photos_test() { + $album = album::create(item::root(), rand(), "test album"); + $photo = photo::create($album, MODPATH . "gallery/images/gallery.png", "", ""); + identity::set_active_user(identity::guest()); + + $this->assert_true(access::can("view", $photo)); + access::deny(identity::everybody(), "view", $album); + + $photo->reload(); // view permissions are cached in the photo + $this->assert_false(access::can("view", $photo)); + } + public function can_toggle_view_permissions_propagate_down_test() { $album1 = test::random_album(item::root()); $album2 = test::random_album($album1); -- cgit v1.2.3 From 63db756441fe2971bdcbcee3ba1bb20c179ffa59 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 27 Jan 2010 01:49:37 -0800 Subject: Switch to using test helper. Also, reload the album before running access::deny since the mptt pointers will have changed. --- modules/gallery/tests/Access_Helper_Test.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index 35cf5edb..5331117d 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -194,14 +194,15 @@ class Access_Helper_Test extends Gallery_Unit_Test_Case { } public function view_permissions_propagate_down_to_photos_test() { - $album = album::create(item::root(), rand(), "test album"); - $photo = photo::create($album, MODPATH . "gallery/images/gallery.png", "", ""); + $album = test::random_album(); + $photo = test::random_photo($album); identity::set_active_user(identity::guest()); $this->assert_true(access::can("view", $photo)); + $album->reload(); // MPTT pointers have changed, so reload before calling access::deny access::deny(identity::everybody(), "view", $album); - $photo->reload(); // view permissions are cached in the photo + $photo->reload(); // view permissions are cached in the photo, so reload before checking $this->assert_false(access::can("view", $photo)); } -- cgit v1.2.3 From f9062101479c809b0957903b7116aaed86f24d76 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 27 Jan 2010 09:55:49 -0800 Subject: Verified and updated --- modules/gallery/tests/controller_auth_data.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index 40f37e96..0aa26057 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -19,7 +19,7 @@ modules/gallery/controllers/quick.php form_edit modules/gallery/controllers/simple_uploader.php start DIRTY_AUTH modules/gallery/controllers/simple_uploader.php finish DIRTY_AUTH modules/gallery/controllers/upgrader.php index DIRTY_AUTH -modules/gallery/controllers/user_profile.php show DIRTY_CSRF|DIRTY_AUTH +modules/gallery/controllers/user_profile.php show DIRTY_AUTH modules/gallery/controllers/user_profile.php contact DIRTY_AUTH modules/gallery/controllers/user_profile.php send DIRTY_AUTH modules/gallery/controllers/welcome_message.php index DIRTY_AUTH -- cgit v1.2.3 From ec0f89f10a58c3c3751387d5c1d1efcbf940bc9a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 27 Jan 2010 21:40:48 -0800 Subject: Change "resource" to "entity" in REST responses. They're all resources, but we differentiate resources as collections and entities. --- modules/gallery/helpers/item_rest.php | 2 +- modules/gallery/tests/Item_Rest_Helper_Test.php | 11 ++++++----- modules/tag/helpers/tag_rest.php | 2 +- modules/tag/tests/Tag_Rest_Helper_Test.php | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 9598b191..2236fbbb 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -77,7 +77,7 @@ class item_rest_Core { return array( "url" => $request->url, - "resource" => $item->as_array(), + "entity" => $item->as_array(), "members" => $members, "relationships" => rest::relationships("item", $item)); } diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index 8ce6bc43..d91e0f58 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -36,7 +36,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params = new stdClass(); $this->assert_equal_array( array("url" => rest::url("item", $album1), - "resource" => $album1->as_array(), + "entity" => $album1->as_array(), "members" => array( rest::url("item", $photo1), rest::url("item", $album2)), @@ -50,7 +50,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "direct"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "resource" => $album1->as_array(), + "entity" => $album1->as_array(), "members" => array( rest::url("item", $photo1), rest::url("item", $album2)), @@ -64,7 +64,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "all"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "resource" => $album1->as_array(), + "entity" => $album1->as_array(), "members" => array( rest::url("item", $photo1), rest::url("item", $album2), @@ -88,7 +88,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->name = "foo"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "resource" => $album1->as_array(), + "entity" => $album1->as_array(), "members" => array( rest::url("item", $photo2)), "relationships" => array( @@ -108,7 +108,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->type = "album"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "resource" => $album1->as_array(), + "entity" => $album1->as_array(), "members" => array( rest::url("item", $album2)), "relationships" => array( @@ -210,6 +210,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function delete_album_fails_without_permission_test() { $album1 = test::random_album(); access::deny(identity::everybody(), "edit", $album1); + identity::set_active_user(identity::guest()); $request->url = rest::url("item", $album1); try { diff --git a/modules/tag/helpers/tag_rest.php b/modules/tag/helpers/tag_rest.php index 4b2a4b46..7143daa9 100644 --- a/modules/tag/helpers/tag_rest.php +++ b/modules/tag/helpers/tag_rest.php @@ -29,7 +29,7 @@ class tag_rest_Core { return array( "url" => $request->url, - "resource" => $tag->as_array(), + "entity" => $tag->as_array(), "relationships" => array( "items" => array( "url" => rest::url("tag_items", $tag), diff --git a/modules/tag/tests/Tag_Rest_Helper_Test.php b/modules/tag/tests/Tag_Rest_Helper_Test.php index eacf91b3..d3cae0fb 100644 --- a/modules/tag/tests/Tag_Rest_Helper_Test.php +++ b/modules/tag/tests/Tag_Rest_Helper_Test.php @@ -31,7 +31,7 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->url = rest::url("tag", $tag); $this->assert_equal_array( array("url" => rest::url("tag", $tag), - "resource" => $tag->as_array(), + "entity" => $tag->as_array(), "relationships" => array( "items" => array( "url" => rest::url("tag_items", $tag), @@ -56,7 +56,7 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->url = rest::url("tag", $tag); $this->assert_equal_array( array("url" => rest::url("tag", $tag), - "resource" => $tag->as_array(), + "entity" => $tag->as_array(), "relationships" => array( "items" => array( "url" => rest::url("tag_items", $tag), -- cgit v1.2.3 From 212633d05a5a8abb77a744a69c61d6e3051b73c5 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 27 Jan 2010 21:52:18 -0800 Subject: Prevent accidentally deleting the root album. --- modules/gallery/models/item.php | 6 ++++++ modules/gallery/tests/Item_Model_Test.php | 10 ++++++++++ 2 files changed, 16 insertions(+) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index e4ff0bfb..9706d61f 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -71,6 +71,12 @@ class Item_Model extends ORM_MPTT { } public function delete() { + if ($this->id == 1) { + $v = new Validation(array("id")); + $v->add_error("id", "cant_delete_root_album"); + ORM_Validation_Exception::handle_validation($this->table_name, $v); + } + $old = clone $this; module::event("item_before_delete", $this); diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 1e77076a..eb9ecc99 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -336,4 +336,14 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { } $this->assert_true(false, "Shouldn't get here"); } + + public function cant_delete_root_album_test() { + try { + item::root()->delete(); + } catch (ORM_Validation_Exception $e) { + $this->assert_same(array("id" => "cant_delete_root_album"), $e->validation->errors()); + return; // pass + } + $this->assert_true(false, "Shouldn't get here"); + } } -- cgit v1.2.3 From 75aec29350442351299c5ecadfa07042b857c558 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 28 Jan 2010 08:42:14 -0800 Subject: Update the xss golden file for user profile changes. --- modules/gallery/tests/xss_data.txt | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index a89725c0..04add4c7 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -34,6 +34,9 @@ modules/comment/views/comment.mrss.php 35 DIRTY_ATTR $chi modules/comment/views/comment.mrss.php 35 DIRTY_ATTR $child->thumb_width modules/comment/views/comments.html.php 16 DIRTY_ATTR $comment->id modules/comment/views/comments.html.php 19 DIRTY_ATTR $comment->author()->avatar_url(40,$theme->url(,true)) +modules/comment/views/user_profile_comments.html.php 5 DIRTY_ATTR $comment->id +modules/comment/views/user_profile_comments.html.php 10 DIRTY_JS $comment->item()->url() +modules/comment/views/user_profile_comments.html.php 11 DIRTY $comment->item()->thumb_img(array(),50) modules/digibug/views/digibug_form.html.php 4 DIRTY form::open("http://www.digibug.com/dapi/order.php") modules/digibug/views/digibug_form.html.php 5 DIRTY form::hidden($order_parms) modules/digibug/views/digibug_form.html.php 6 DIRTY form::close() @@ -43,10 +46,10 @@ modules/g2_import/views/admin_g2_import.html.php 30 DIRTY $form modules/gallery/views/admin_advanced_settings.html.php 21 DIRTY_ATTR text::alternate("g-odd","g-even") modules/gallery/views/admin_advanced_settings.html.php 22 DIRTY $var->module_name modules/gallery/views/admin_block_log_entries.html.php 4 DIRTY_ATTR log::severity_class($entry->severity) -modules/gallery/views/admin_block_log_entries.html.php 5 DIRTY_JS user_profile::url($entryr->id) -modules/gallery/views/admin_block_log_entries.html.php 6 DIRTY gallery::date_time($entry->timestamp) -modules/gallery/views/admin_block_log_entries.html.php 7 DIRTY $entry->message -modules/gallery/views/admin_block_log_entries.html.php 8 DIRTY $entry->html +modules/gallery/views/admin_block_log_entries.html.php 8 DIRTY_JS user_profile::url($entry->user->id) +modules/gallery/views/admin_block_log_entries.html.php 10 DIRTY gallery::date_time($entry->timestamp) +modules/gallery/views/admin_block_log_entries.html.php 11 DIRTY $entry->message +modules/gallery/views/admin_block_log_entries.html.php 12 DIRTY $entry->html modules/gallery/views/admin_block_news.html.php 5 DIRTY_JS $entry["link"] modules/gallery/views/admin_block_news.html.php 5 DIRTY $entry["title"] modules/gallery/views/admin_block_news.html.php 7 DIRTY text::limit_words(strip_tags($entry["description"]),25); @@ -219,10 +222,9 @@ modules/gallery/views/upgrader.html.php 77 DIRTY $modul modules/gallery/views/upgrader.html.php 99 DIRTY_ATTR $done?"muted":"" modules/gallery/views/upgrader.html.php 102 DIRTY_ATTR $done?"muted":"" modules/gallery/views/user_languages_block.html.php 2 DIRTY form::dropdown("g-select-session-locale",$installed_locales,$selected) -modules/gallery/views/user_profile.html.php 35 DIRTY_ATTR $height -modules/gallery/views/user_profile.html.php 44 DIRTY $field -modules/gallery/views/user_profile.html.php 45 DIRTY $value -modules/gallery/views/user_profile.html.php 65 DIRTY_JS $return->for_html_attr() +modules/gallery/views/user_profile.html.php 35 DIRTY_ATTR $user->avatar_url(40,$theme->url(,true)) +modules/gallery/views/user_profile.html.php 46 DIRTY $info->view +modules/gallery/views/user_profile_info.html.php 5 DIRTY $field modules/image_block/views/image_block_block.html.php 3 DIRTY_JS $item->url() modules/image_block/views/image_block_block.html.php 4 DIRTY $item->thumb_img(array("class"=>"g-thumbnail")) modules/info/views/info_block.html.php 22 DIRTY date("M j, Y H:i:s",$item->captured) @@ -235,6 +237,8 @@ modules/notification/views/item_deleted.html.php 18 DIRTY_JS $item- modules/notification/views/item_deleted.html.php 19 DIRTY $item->parent()->abs_url() modules/notification/views/item_updated.html.php 20 DIRTY_JS $item->abs_url() modules/notification/views/item_updated.html.php 20 DIRTY $item->abs_url() +modules/notification/views/user_profile_notification.html.php 5 DIRTY_ATTR $subscription->id +modules/notification/views/user_profile_notification.html.php 6 DIRTY_JS $subscription->url modules/organize/views/organize_dialog.html.php 3 DIRTY_JS url::site("organize/move_to/__ALBUM_ID__?csrf=$csrf") modules/organize/views/organize_dialog.html.php 4 DIRTY_JS url::site("organize/rearrange/__TARGET_ID__/__BEFORE__?csrf=$csrf") modules/organize/views/organize_dialog.html.php 5 DIRTY_JS url::site("organize/sort_order/__ALBUM_ID__/__COL__/__DIR__?csrf=$csrf") -- cgit v1.2.3 From c51fe9682075c961972c344f4888a4adceabe3eb Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 28 Jan 2010 09:27:27 -0800 Subject: Make the varible for the profile name more descriptive and clean the label --- modules/gallery/helpers/gallery_event.php | 4 ++-- modules/gallery/tests/xss_data.txt | 1 - modules/gallery/views/user_profile_info.html.php | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 9b252f61..b3d4daab 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -404,14 +404,14 @@ class gallery_event_Core { if (!$data->display_all) { $fields = array("name" => t("Name"), "full_name" => t("Full name"), "url" => "Web site"); } - $v->fields = array(); + $v->user_profile_data = array(); foreach ($fields as $field => $label) { if (!empty($data->user->$field)) { $value = $data->user->$field; if ($field == "locale") { $value = locales::display_name($value); } - $v->fields[(string) $label] = $value; + $v->user_profile_data[(string) $label] = $value; } } $data->content[] = (object) array("title" => t("User information"), "view" => $v); diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 04add4c7..663080a0 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -224,7 +224,6 @@ modules/gallery/views/upgrader.html.php 102 DIRTY_ATTR $don modules/gallery/views/user_languages_block.html.php 2 DIRTY form::dropdown("g-select-session-locale",$installed_locales,$selected) modules/gallery/views/user_profile.html.php 35 DIRTY_ATTR $user->avatar_url(40,$theme->url(,true)) modules/gallery/views/user_profile.html.php 46 DIRTY $info->view -modules/gallery/views/user_profile_info.html.php 5 DIRTY $field modules/image_block/views/image_block_block.html.php 3 DIRTY_JS $item->url() modules/image_block/views/image_block_block.html.php 4 DIRTY $item->thumb_img(array("class"=>"g-thumbnail")) modules/info/views/info_block.html.php 22 DIRTY date("M j, Y H:i:s",$item->captured) diff --git a/modules/gallery/views/user_profile_info.html.php b/modules/gallery/views/user_profile_info.html.php index 2f2d68d3..58e134bb 100644 --- a/modules/gallery/views/user_profile_info.html.php +++ b/modules/gallery/views/user_profile_info.html.php @@ -1,8 +1,8 @@ - $value): ?> + $value): ?> - + -- cgit v1.2.3 From 86721d3884568c534f412915175088be667ca65b Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 28 Jan 2010 09:40:04 -0800 Subject: Reviewed all DIRTY_JS entries --- modules/gallery/tests/xss_data.txt | 3 --- 1 file changed, 3 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 663080a0..d139d297 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -97,8 +97,6 @@ modules/gallery/views/admin_maintenance.html.php 158 DIRTY $task- modules/gallery/views/admin_maintenance_show_log.html.php 8 DIRTY_JS url::site("admin/maintenance/save_log/$task->id?csrf=$csrf") modules/gallery/views/admin_maintenance_show_log.html.php 13 DIRTY $task->name modules/gallery/views/admin_maintenance_task.html.php 55 DIRTY $task->name -modules/gallery/views/admin_modules.html.php 25 DIRTY_JS t("Continue") -modules/gallery/views/admin_modules.html.php 35 DIRTY_JS t("Continue") modules/gallery/views/admin_modules.html.php 51 DIRTY access::csrf_form_field() modules/gallery/views/admin_modules.html.php 60 DIRTY_ATTR text::alternate("g-odd","g-even") modules/gallery/views/admin_modules.html.php 63 DIRTY form::checkbox($data,'1',module::is_active($module_name)) @@ -127,7 +125,6 @@ modules/gallery/views/form_uploadify.html.php 30 DIRTY_JS url::f modules/gallery/views/form_uploadify.html.php 31 DIRTY_JS url::site("simple_uploader/add_photo/{$album->id}") modules/gallery/views/form_uploadify.html.php 35 DIRTY_JS url::file("lib/uploadify/cancel.png") modules/gallery/views/form_uploadify.html.php 36 DIRTY_JS $simultaneous_upload_limit -modules/gallery/views/form_uploadify.html.php 61 DIRTY_JS t("Completed") modules/gallery/views/in_place_edit.html.php 2 DIRTY form::open($action,array("method"=>"post","id"=>"g-in-place-edit-form","class"=>"g-short-form"),$hidden) modules/gallery/views/in_place_edit.html.php 5 DIRTY form::input("input",$form["input"]," class=\"textbox\"") modules/gallery/views/in_place_edit.html.php 12 DIRTY form::close() -- cgit v1.2.3 From df3db40ab7a181ba0f461fe2ebf84d2ba828265c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 28 Jan 2010 09:43:10 -0800 Subject: Reviewed DIRTY_ATTR --- modules/gallery/tests/xss_data.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index d139d297..c2769647 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -101,7 +101,7 @@ modules/gallery/views/admin_modules.html.php 51 DIRTY access modules/gallery/views/admin_modules.html.php 60 DIRTY_ATTR text::alternate("g-odd","g-even") modules/gallery/views/admin_modules.html.php 63 DIRTY form::checkbox($data,'1',module::is_active($module_name)) modules/gallery/views/admin_modules.html.php 65 DIRTY $module_info->version -modules/gallery/views/admin_modules_confirm.html.php 11 DIRTY_ATTR $class +modules/gallery/views/admin_modules_confirm.html.php 11 DIRTY_ATTR $css_class modules/gallery/views/admin_modules_confirm.html.php 11 DIRTY $message modules/gallery/views/admin_modules_confirm.html.php 16 DIRTY access::csrf_form_field() modules/gallery/views/admin_modules_confirm.html.php 18 DIRTY form::hidden($module,1) -- cgit v1.2.3 From 69636955695476622b7f3019922afff14ea66380 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 30 Jan 2010 23:22:53 -0800 Subject: Verified --- modules/gallery/tests/xss_data.txt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index c2769647..65b45a08 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -38,8 +38,7 @@ modules/comment/views/user_profile_comments.html.php 5 DIRTY_ATTR $com modules/comment/views/user_profile_comments.html.php 10 DIRTY_JS $comment->item()->url() modules/comment/views/user_profile_comments.html.php 11 DIRTY $comment->item()->thumb_img(array(),50) modules/digibug/views/digibug_form.html.php 4 DIRTY form::open("http://www.digibug.com/dapi/order.php") -modules/digibug/views/digibug_form.html.php 5 DIRTY form::hidden($order_parms) -modules/digibug/views/digibug_form.html.php 6 DIRTY form::close() +modules/digibug/views/digibug_form.html.php 6 DIRTY form::hidden($key,$value) modules/exif/views/exif_dialog.html.php 14 DIRTY $details[$i]["caption"] modules/exif/views/exif_dialog.html.php 21 DIRTY $details[$i]["caption"] modules/g2_import/views/admin_g2_import.html.php 30 DIRTY $form @@ -125,10 +124,9 @@ modules/gallery/views/form_uploadify.html.php 30 DIRTY_JS url::f modules/gallery/views/form_uploadify.html.php 31 DIRTY_JS url::site("simple_uploader/add_photo/{$album->id}") modules/gallery/views/form_uploadify.html.php 35 DIRTY_JS url::file("lib/uploadify/cancel.png") modules/gallery/views/form_uploadify.html.php 36 DIRTY_JS $simultaneous_upload_limit -modules/gallery/views/in_place_edit.html.php 2 DIRTY form::open($action,array("method"=>"post","id"=>"g-in-place-edit-form","class"=>"g-short-form"),$hidden) -modules/gallery/views/in_place_edit.html.php 5 DIRTY form::input("input",$form["input"]," class=\"textbox\"") -modules/gallery/views/in_place_edit.html.php 12 DIRTY form::close() -modules/gallery/views/in_place_edit.html.php 14 DIRTY $errors["input"] +modules/gallery/views/in_place_edit.html.php 2 DIRTY form::open($action,array("method"=>"post","id"=>"g-in-place-edit-form","class"=>"g-short-form")) +modules/gallery/views/in_place_edit.html.php 3 DIRTY access::csrf_form_field() +modules/gallery/views/in_place_edit.html.php 6 DIRTY form::input("input",$form["input"]," class=\"textbox\"") modules/gallery/views/kohana_error_page.php 102 DIRTY $message modules/gallery/views/kohana_error_page.php 116 DIRTY $trace modules/gallery/views/kohana_profiler.php 32 DIRTY $profile->render(); @@ -219,8 +217,8 @@ modules/gallery/views/upgrader.html.php 77 DIRTY $modul modules/gallery/views/upgrader.html.php 99 DIRTY_ATTR $done?"muted":"" modules/gallery/views/upgrader.html.php 102 DIRTY_ATTR $done?"muted":"" modules/gallery/views/user_languages_block.html.php 2 DIRTY form::dropdown("g-select-session-locale",$installed_locales,$selected) -modules/gallery/views/user_profile.html.php 35 DIRTY_ATTR $user->avatar_url(40,$theme->url(,true)) -modules/gallery/views/user_profile.html.php 46 DIRTY $info->view +modules/gallery/views/user_profile.html.php 36 DIRTY_ATTR $user->avatar_url(40,$theme->url(,true)) +modules/gallery/views/user_profile.html.php 47 DIRTY $info->view modules/image_block/views/image_block_block.html.php 3 DIRTY_JS $item->url() modules/image_block/views/image_block_block.html.php 4 DIRTY $item->thumb_img(array("class"=>"g-thumbnail")) modules/info/views/info_block.html.php 22 DIRTY date("M j, Y H:i:s",$item->captured) -- cgit v1.2.3 From d29028c4ea9002ac036a89a4478fb4640c86fedb Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 30 Jan 2010 23:36:11 -0800 Subject: Add Item_Model::as_restful_array() for convenience. --- modules/gallery/models/item.php | 17 +++++++++++++++++ modules/gallery/tests/Item_Model_Test.php | 12 ++++++++++++ 2 files changed, 29 insertions(+) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index ae6e4cc9..fd121a5a 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -914,4 +914,21 @@ class Item_Model extends ORM_MPTT { $v->add_error($field, "read_only"); } } + + /** + * Same as ORM::as_array() but convert id fields into their RESTful form. + */ + public function as_restful_array() { + // Convert item ids to rest URLs for consistency + $data = $this->as_array(); + if ($tmp = $this->parent()) { + $data["parent"] = rest::url("item", $tmp); + } + unset($data["parent_id"]); + if ($tmp = $this->album_cover()) { + $data["album_cover"] = rest::url("item", $tmp); + } + unset($data["album_cover_item_id"]); + return $data; + } } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index eb9ecc99..9f632fb5 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -346,4 +346,16 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { } $this->assert_true(false, "Shouldn't get here"); } + + public function as_restful_array_test() { + $album = test::random_album(); + $photo = test::random_photo($album); + $album->reload(); + + $result = $album->as_restful_array(); + $this->assert_same(rest::url("item", item::root()), $result["parent"]); + $this->assert_same(rest::url("item", $photo), $result["album_cover"]); + $this->assert_true(!array_key_exists("parent_id", $result)); + $this->assert_true(!array_key_exists("album_cover_item_id", $result)); + } } -- cgit v1.2.3 From a79d20a36135d50f77a7f11046b1d7ee392d46c7 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 30 Jan 2010 23:36:41 -0800 Subject: Use Item_Model::as_restful_array() to simplify tests. --- modules/gallery/helpers/item_rest.php | 13 +------------ modules/gallery/tests/Item_Rest_Helper_Test.php | 10 +++++----- 2 files changed, 6 insertions(+), 17 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index f5056bc1..c0fc422a 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -75,20 +75,9 @@ class item_rest_Core { $members[] = rest::url("item", $child); } - // Convert item ids to rest URLs for consistency - $entity = $item->as_array(); - if ($tmp = $item->parent()) { - $entity["parent"] = rest::url("item", $tmp); - } - unset($entity["parent_id"]); - if ($tmp = $item->album_cover()) { - $entity["album_cover"] = rest::url("item", $tmp); - } - unset($entity["album_cover_id"]); - return array( "url" => $request->url, - "entity" => $entity, + "entity" => $item->as_restful_array(), "members" => $members, "relationships" => rest::relationships("item", $item)); } diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index d91e0f58..088b1cbd 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -36,7 +36,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params = new stdClass(); $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_array(), + "entity" => $album1->as_restful_array(), "members" => array( rest::url("item", $photo1), rest::url("item", $album2)), @@ -50,7 +50,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "direct"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_array(), + "entity" => $album1->as_restful_array(), "members" => array( rest::url("item", $photo1), rest::url("item", $album2)), @@ -64,7 +64,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "all"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_array(), + "entity" => $album1->as_restful_array(), "members" => array( rest::url("item", $photo1), rest::url("item", $album2), @@ -88,7 +88,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->name = "foo"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_array(), + "entity" => $album1->as_restful_array(), "members" => array( rest::url("item", $photo2)), "relationships" => array( @@ -108,7 +108,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->type = "album"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_array(), + "entity" => $album1->as_restful_array(), "members" => array( rest::url("item", $album2)), "relationships" => array( -- cgit v1.2.3 From c050acf30a7351bf0ef5b8ee206704c073e881c7 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 31 Jan 2010 16:07:41 -0800 Subject: Fix lots of warnings that pop up when we're in E_STRICT mode. They're mostly issues around uninitialized variables, calling non-static functions in a static context, calling Session functions directly instead of on its singleton, passing non-variables by reference, and subclasses not using the same interface as the parent class. --- modules/comment/controllers/admin_comments.php | 1 + modules/comment/helpers/comment_rss.php | 1 + modules/comment/models/comment.php | 3 ++- modules/digibug/controllers/digibug.php | 2 +- modules/forge/libraries/Form_Group.php | 2 +- modules/g2_import/controllers/admin_g2_import.php | 5 +++++ modules/g2_import/helpers/g2_import.php | 11 +++++++++++ modules/g2_import/helpers/g2_import_task.php | 10 ++++++++-- modules/g2_import/views/admin_g2_import.html.php | 2 +- modules/gallery/controllers/admin_modules.php | 1 + modules/gallery/controllers/combined.php | 2 +- modules/gallery/controllers/file_proxy.php | 2 +- modules/gallery/helpers/gallery_block.php | 2 +- modules/gallery/helpers/gallery_rss.php | 1 + modules/gallery/helpers/gallery_task.php | 11 ++++++++--- modules/gallery/helpers/graphics.php | 3 +++ modules/gallery/helpers/l10n_client.php | 1 + modules/gallery/helpers/module.php | 3 ++- modules/gallery/libraries/Form_Script.php | 4 ++-- modules/gallery/libraries/MY_Database.php | 2 +- modules/gallery/libraries/MY_View.php | 2 +- modules/gallery/libraries/ORM_MPTT.php | 2 +- modules/gallery/models/item.php | 2 +- modules/gallery/models/task.php | 4 ++-- modules/gallery/tests/Database_Test.php | 8 ++++---- modules/gallery/tests/Item_Rest_Helper_Test.php | 17 +++++++++++++++++ .../gallery_unit_test/controllers/gallery_unit_test.php | 6 +++++- modules/rest/controllers/rest.php | 1 + modules/rest/helpers/rest.php | 2 +- modules/rest/tests/Rest_Controller_Test.php | 8 ++++---- modules/search/helpers/search.php | 3 ++- modules/tag/helpers/tag_rss.php | 2 ++ modules/tag/helpers/tags_rest.php | 1 - modules/tag/models/tag.php | 2 +- modules/tag/tests/Tag_Item_Rest_Helper_Test.php | 4 +++- modules/tag/tests/Tag_Rest_Helper_Test.php | 8 ++++++++ modules/tag/tests/Tags_Rest_Helper_Test.php | 4 ++++ modules/user/controllers/admin_users.php | 2 +- 38 files changed, 111 insertions(+), 36 deletions(-) (limited to 'modules/gallery/tests') diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php index b7dc5fb3..3dd45919 100644 --- a/modules/comment/controllers/admin_comments.php +++ b/modules/comment/controllers/admin_comments.php @@ -92,6 +92,7 @@ class Admin_Comments_Controller extends Admin_Controller { } private function _counts() { + $counts = new stdClass(); $counts->unpublished = 0; $counts->published = 0; $counts->spam = 0; diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php index 77044884..79fa07df 100644 --- a/modules/comment/helpers/comment_rss.php +++ b/modules/comment/helpers/comment_rss.php @@ -42,6 +42,7 @@ class comment_rss_Core { $comments->where("item_id", "=", $id); } + $feed = new stdClass(); $feed->view = "comment.mrss"; $feed->children = array(); foreach ($comments->find_all($limit, $offset) as $comment) { diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index add15ce8..d9d05995 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -116,7 +116,8 @@ class Comment_Model extends ORM { // We only notify on the related items if we're making a visible change. if ($visible_change) { - module::event("item_related_update", $this->item()); + $item = $this->item(); + module::event("item_related_update", $item); } return $this; diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index e3b06196..c98ae20c 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -91,7 +91,7 @@ class Digibug_Controller extends Controller { } // We don't need to save the session for this request - Session::abort_save(); + Session::instance()->abort_save(); if (!TEST_MODE) { // Dump out the image diff --git a/modules/forge/libraries/Form_Group.php b/modules/forge/libraries/Form_Group.php index e0601321..0a04912b 100644 --- a/modules/forge/libraries/Form_Group.php +++ b/modules/forge/libraries/Form_Group.php @@ -80,7 +80,7 @@ class Form_Group_Core extends Forge { } } - public function render() + public function render($template = 'forge_template', $custom = FALSE) { // No Sir, we don't want any html today thank you return; diff --git a/modules/g2_import/controllers/admin_g2_import.php b/modules/g2_import/controllers/admin_g2_import.php index 1c65f482..6dd155b9 100644 --- a/modules/g2_import/controllers/admin_g2_import.php +++ b/modules/g2_import/controllers/admin_g2_import.php @@ -19,6 +19,7 @@ */ class Admin_g2_import_Controller extends Admin_Controller { public function index() { + g2_import::lower_error_reporting(); if (g2_import::is_configured()) { g2_import::init(); } @@ -31,6 +32,7 @@ class Admin_g2_import_Controller extends Admin_Controller { $view = new Admin_View("admin.html"); $view->content = new View("admin_g2_import.html"); $view->content->form = $this->_get_import_form(); + $view->content->version = g2_import::version(); if (g2_import::is_initialized()) { $view->content->g2_stats = $g2_stats; @@ -38,11 +40,13 @@ class Admin_g2_import_Controller extends Admin_Controller { $view->content->thumb_size = module::get_var("gallery", "thumb_size"); $view->content->resize_size = module::get_var("gallery", "resize_size"); } + g2_import::restore_error_reporting(); print $view; } public function save() { access::verify_csrf(); + g2_import::lower_error_reporting(); $form = $this->_get_import_form(); if ($form->validate()) { @@ -63,6 +67,7 @@ class Admin_g2_import_Controller extends Admin_Controller { $view = new Admin_View("admin.html"); $view->content = new View("admin_g2_import.html"); $view->content->form = $form; + g2_import::restore_error_reporting(); print $view; } diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index fa95e547..0fcc0539 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -24,6 +24,7 @@ class g2_import_Core { public static $g2_base_url = null; private static $current_g2_item = null; + private static $error_reporting = null; static function is_configured() { return module::get_var("g2_import", "embed_path"); @@ -931,6 +932,16 @@ class g2_import_Core { "useAuthToken" => false)); return str_replace(self::$g2_base_url, "", $url); } + + static function lower_error_reporting() { + // Gallery 2 was not designed to run in E_STRICT mode and will barf out errors. So dial down + // the error reporting when we make G2 calls. + self::$error_reporting = error_reporting(error_reporting() & ~E_STRICT); + } + + static function restore_error_reporting() { + error_reporting(self::$error_reporting); + } } /** diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index e80b88b9..21ba4c3a 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -19,17 +19,19 @@ */ class g2_import_task_Core { static function available_tasks() { + g2_import::lower_error_reporting(); if (g2_import::is_configured()) { g2_import::init(); } - + $version = g2_import::version(); + g2_import::restore_error_reporting(); if (class_exists("GalleryCoreApi")) { return array(Task_Definition::factory() ->callback("g2_import_task::import") ->name(t("Import from Gallery 2")) ->description( - t("Gallery %version detected", array("version" => g2_import::version()))) + t("Gallery %version detected", array("version" => $version))) ->severity(log::SUCCESS)); } @@ -37,6 +39,8 @@ class g2_import_task_Core { } static function import($task) { + g2_import::lower_error_reporting(); + $start = microtime(true); g2_import::init(); @@ -207,5 +211,7 @@ class g2_import_task_Core { $task->set("mode", $mode); $task->set("queue", $queue); $task->set("done", $done); + + g2_import::restore_error_reporting(); } } diff --git a/modules/g2_import/views/admin_g2_import.html.php b/modules/g2_import/views/admin_g2_import.html.php index 0875e7f7..6a5214a3 100644 --- a/modules/g2_import/views/admin_g2_import.html.php +++ b/modules/g2_import/views/admin_g2_import.html.php @@ -34,7 +34,7 @@

  • - g2_import::version())) ?> + $version)) ?>
  • diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php index 84fee25d..081b3f12 100644 --- a/modules/gallery/controllers/admin_modules.php +++ b/modules/gallery/controllers/admin_modules.php @@ -67,6 +67,7 @@ class Admin_Modules_Controller extends Admin_Controller { } private function _do_save() { + $changes = new stdClass(); $changes->activate = array(); $changes->deactivate = array(); $activated_names = array(); diff --git a/modules/gallery/controllers/combined.php b/modules/gallery/controllers/combined.php index e90a2f1a..7f3a3c7d 100644 --- a/modules/gallery/controllers/combined.php +++ b/modules/gallery/controllers/combined.php @@ -41,7 +41,7 @@ class Combined_Controller extends Controller { $input = Input::instance(); // We don't need to save the session for this request - Session::abort_save(); + Session::instance()->abort_save(); // Our data is immutable, so if they already have a copy then it needs no updating. if ($input->server("HTTP_IF_MODIFIED_SINCE")) { diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index 646edf17..33952366 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -121,7 +121,7 @@ class File_Proxy_Controller extends Controller { expires::check(2592000, $item->updated); // We don't need to save the session for this request - Session::abort_save(); + Session::instance()->abort_save(); expires::set(2592000, $item->updated); // 30 days diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index 9d4e81b6..be0f11b8 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -72,7 +72,7 @@ class gallery_block_Core { $block->content = new View("admin_block_platform.html"); if (is_readable("/proc/loadavg")) { $block->content->load_average = - join(" ", array_slice(explode(" ", array_shift(file("/proc/loadavg"))), 0, 3)); + join(" ", array_slice(explode(" ", current(file("/proc/loadavg"))), 0, 3)); } else { $block->content->load_average = t("Unavailable"); } diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index d422636f..c1790d28 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -25,6 +25,7 @@ class gallery_rss_Core { } static function feed($feed_id, $offset, $limit, $id) { + $feed = new stdClass(); switch ($feed_id) { case "latest": $feed->children = ORM::factory("item") diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index c75e050a..b2f18d7c 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -111,6 +111,7 @@ class gallery_task_Core { site_status::clear("graphics_dirty"); } } catch (Exception $e) { + Kohana_Log::add("error",(string)$e); $task->done = true; $task->state = "error"; $task->status = $e->getMessage(); @@ -214,6 +215,7 @@ class gallery_task_Core { Cache::instance()->delete("update_l10n_cache:{$task->id}"); } } catch (Exception $e) { + Kohana_Log::add("error",(string)$e); $task->done = true; $task->state = "error"; $task->status = $e->getMessage(); @@ -233,10 +235,10 @@ class gallery_task_Core { try { $start = microtime(true); $data = Cache::instance()->get("file_cleanup_cache:{$task->id}"); - if ($data) { - $files = unserialize($data); - } + $files = $data ? unserialize($data) : array(); $i = 0; + $current = 0; + $total = 0; switch ($task->get("mode", "init")) { case "init": // 0% @@ -262,6 +264,7 @@ class gallery_task_Core { if (count($files) == 0) { break; } + case "delete_files": $current = $task->get("current"); $total = $task->get("total"); @@ -279,8 +282,10 @@ class gallery_task_Core { if ($total == $current) { $task->done = true; $task->state = "success"; + $task->percent_complete = 100; } } catch (Exception $e) { + Kohana_Log::add("error",(string)$e); $task->done = true; $task->state = "error"; $task->status = $e->getMessage(); diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 5a290905..c85c7750 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -262,6 +262,9 @@ class graphics_Core { */ static function detect_toolkits() { $toolkits = new stdClass(); + $toolkits->gd = new stdClass(); + $toolkits->imagemagick = new stdClass(); + $toolkits->graphicsmagick = new stdClass(); // GD is special, it doesn't use exec() $gd = function_exists("gd_info") ? gd_info() : array(); diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index 086245e8..c27e4e5b 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -77,6 +77,7 @@ class l10n_client_Core { * translations for. */ static function fetch_updates(&$num_fetched) { + $request = new stdClass(); $request->locales = array(); $request->messages = new stdClass(); diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 95e426c4..9523d1d2 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -430,7 +430,8 @@ class module_Core { // This could happen if there's a race condition continue; } - self::$var_cache->{$row->module_name}->{$row->name} = $row->value; + // Mute the "Creating default object from empty value" warning below + @self::$var_cache->{$row->module_name}->{$row->name} = $row->value; } $cache = ORM::factory("var"); $cache->module_name = "gallery"; diff --git a/modules/gallery/libraries/Form_Script.php b/modules/gallery/libraries/Form_Script.php index e841408d..1f965767 100644 --- a/modules/gallery/libraries/Form_Script.php +++ b/modules/gallery/libraries/Form_Script.php @@ -50,7 +50,7 @@ class Form_Script_Core extends Forge { return $this; } - public function render() { + public function render($template="forge_template", $custom=false) { $script = array(); if (!empty($this->data["url"])) { $script[] = html::script($this->data["url"]); @@ -63,4 +63,4 @@ class Form_Script_Core extends Forge { return implode("\n", $script); } -} // End Form Script \ No newline at end of file +} \ No newline at end of file diff --git a/modules/gallery/libraries/MY_Database.php b/modules/gallery/libraries/MY_Database.php index 61f23fb0..e2ef68cd 100644 --- a/modules/gallery/libraries/MY_Database.php +++ b/modules/gallery/libraries/MY_Database.php @@ -38,7 +38,7 @@ abstract class Database extends Database_Core { * Parse the query string and convert any strings of the form `\([a-zA-Z0-9_]*?)\] * table prefix . $1 */ - public function query($sql = '') { + public function query($sql) { if (!empty($sql)) { $sql = $this->add_table_prefixes($sql); } diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php index cec59ec1..83e0d0be 100644 --- a/modules/gallery/libraries/MY_View.php +++ b/modules/gallery/libraries/MY_View.php @@ -27,7 +27,7 @@ class View extends View_Core { View::$global_data[$key] = $value; } - public function is_set($key) { + public function is_set($key=null) { return parent::is_set($key) ? true : array_key_exists($key, View::$global_data); } diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index 83f9b51e..3668d42d 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -85,7 +85,7 @@ class ORM_MPTT_Core extends ORM { /** * Delete this node and all of its children. */ - public function delete() { + public function delete($ignored_id=null) { $children = $this->children(); if ($children) { foreach ($this->children() as $item) { diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 083fd06b..dbd56fa2 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -70,7 +70,7 @@ class Item_Model extends ORM_MPTT { return $this->type == 'movie'; } - public function delete() { + public function delete($ignored_id=null) { if ($this->id == 1) { $v = new Validation(array("id")); $v->add_error("id", "cant_delete_root_album"); diff --git a/modules/gallery/models/task.php b/modules/gallery/models/task.php index f40be492..24d909cb 100644 --- a/modules/gallery/models/task.php +++ b/modules/gallery/models/task.php @@ -27,7 +27,7 @@ class Task_Model extends ORM { } } - public function set($key, $value) { + public function set($key, $value=null) { $context = unserialize($this->context); $context[$key] = $value; $this->context = serialize($context); @@ -40,7 +40,7 @@ class Task_Model extends ORM { return parent::save(); } - public function delete() { + public function delete($ignored_id=null) { Cache::instance()->delete($this->_cache_key()); return parent::delete(); } diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index e58f73eb..861f7bba 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -168,12 +168,12 @@ class Database_Mock extends Database { return array("test"); } - public function quote_column($val) { - return "[$val]"; + public function quote_column($val, $alias=null) { + return $alias ? "[$val,$alias]" : "[$val]"; } - public function quote_table($val) { - return "[$val]"; + public function quote_table($val, $alias=null) { + return $alias ? "[$val,$alias]" : "[$val]"; } public function quote($val) { diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index 088b1cbd..6d1dd864 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -32,6 +32,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1->reload(); // No scope is the same as "direct" + $request = new stdClass(); $request->url = rest::url("item", $album1); $request->params = new stdClass(); $this->assert_equal_array( @@ -84,7 +85,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $photo2->save(); $album1->reload(); + $request = new stdClass(); $request->url = rest::url("item", $album1); + $request->params = new stdClass(); $request->params->name = "foo"; $this->assert_equal_array( array("url" => rest::url("item", $album1), @@ -104,7 +107,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album2 = test::random_album($album1); $album1->reload(); + $request = new stdClass(); $request->url = rest::url("item", $album1); + $request->params = new stdClass(); $request->params->type = "album"; $this->assert_equal_array( array("url" => rest::url("item", $album1), @@ -122,7 +127,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); + $request = new stdClass(); $request->url = rest::url("item", $album1); + $request->params = new stdClass(); $request->params->title = "my new title"; item_rest::put($request); @@ -133,7 +140,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); + $request = new stdClass(); $request->url = rest::url("item", $album1); + $request->params = new stdClass(); $request->params->title = "my new title"; $request->params->slug = "not url safe"; @@ -150,7 +159,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); + $request = new stdClass(); $request->url = rest::url("item", $album1); + $request->params = new stdClass(); $request->params->type = "album"; $request->params->name = "my album"; $request->params->title = "my album"; @@ -165,7 +176,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); + $request = new stdClass(); $request->url = rest::url("item", $album1); + $request->params = new stdClass(); $request->params->type = "album"; $request->params->name = "my album"; $request->params->title = "my album"; @@ -185,7 +198,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); + $request = new stdClass(); $request->url = rest::url("item", $album1); + $request->params = new stdClass(); $request->params->type = "photo"; $request->params->name = "my photo.jpg"; $request->file = MODPATH . "gallery/tests/test.jpg"; @@ -200,6 +215,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album1 = test::random_album(); access::allow(identity::everybody(), "edit", $album1); + $request = new stdClass(); $request->url = rest::url("item", $album1); item_rest::delete($request); @@ -212,6 +228,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { access::deny(identity::everybody(), "edit", $album1); identity::set_active_user(identity::guest()); + $request = new stdClass(); $request->url = rest::url("item", $album1); try { item_rest::delete($request); diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php index e05fcbaa..2690ad24 100644 --- a/modules/gallery_unit_test/controllers/gallery_unit_test.php +++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php @@ -18,11 +18,15 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Gallery_Unit_Test_Controller extends Controller { - function Index() { + function index() { if (!TEST_MODE) { throw new Kohana_404_Exception(); } + // Force strict behavior to flush out bugs early + ini_set("display_errors", true); + error_reporting(-1); + // Jump through some hoops to satisfy the way that we check for the site_domain in // config.php. We structure this such that the code in config will leave us with a // site_domain of "." (for historical reasons) diff --git a/modules/rest/controllers/rest.php b/modules/rest/controllers/rest.php index 9141d6d4..374ae0d2 100644 --- a/modules/rest/controllers/rest.php +++ b/modules/rest/controllers/rest.php @@ -40,6 +40,7 @@ class Rest_Controller extends Controller { public function __call($function, $args) { $input = Input::instance(); + $request = new stdClass(); switch ($method = strtolower($input->server("REQUEST_METHOD"))) { case "get": $request->params = (object) $input->get(); diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php index b3f80a55..a61aba2f 100644 --- a/modules/rest/helpers/rest.php +++ b/modules/rest/helpers/rest.php @@ -19,7 +19,7 @@ */ class rest_Core { static function reply($data=array()) { - Session::abort_save(); + Session::instance()->abort_save(); if ($data) { if (Input::instance()->get("output") == "html") { diff --git a/modules/rest/tests/Rest_Controller_Test.php b/modules/rest/tests/Rest_Controller_Test.php index 5e624112..9f73bed9 100644 --- a/modules/rest/tests/Rest_Controller_Test.php +++ b/modules/rest/tests/Rest_Controller_Test.php @@ -138,8 +138,8 @@ class Rest_Controller_Test extends Gallery_Unit_Test_Case { } class mock_rest { - function get($request) { return $request; } - function post($request) { return $request; } - function put($request) { return $request; } - function delete($request) { return $request; } + static function get($request) { return $request; } + static function post($request) { return $request; } + static function put($request) { return $request; } + static function delete($request) { return $request; } } \ No newline at end of file diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index b2497eae..9018ffa2 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -65,7 +65,8 @@ class search_Core { $record->item_id = $item->id; } - module::event("item_index_data", $record->item(), $data); + $item = $record->item(); + module::event("item_index_data", $item, $data); $record->data = join(" ", (array)$data); $record->dirty = 0; $record->save(); diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php index f09a4530..5d42caab 100644 --- a/modules/tag/helpers/tag_rss.php +++ b/modules/tag/helpers/tag_rss.php @@ -34,6 +34,8 @@ class tag_rss_Core { if (!$tag->loaded()) { throw new Kohana_404_Exception(); } + + $feed = new stdClass(); $feed->children = $tag->items($limit, $offset, "photo"); $feed->max_pages = ceil($tag->count / $limit); $feed->title = $tag->name; diff --git a/modules/tag/helpers/tags_rest.php b/modules/tag/helpers/tags_rest.php index ac0eb81d..f28be7b5 100644 --- a/modules/tag/helpers/tags_rest.php +++ b/modules/tag/helpers/tags_rest.php @@ -35,7 +35,6 @@ class tags_rest_Core { $query->or_where("edit_{$group->id}", "=", access::ALLOW); } $has_any_edit_perm = $query->close()->count_records(); - if (!$has_any_edit_perm) { access::forbidden(); } diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index 2b33c30d..38a8ed69 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -95,7 +95,7 @@ class Tag_Model extends ORM { * Overload ORM::delete() to trigger an item_related_update event for all items that are * related to this tag. */ - public function delete() { + public function delete($ignored_id=null) { $related_item_ids = array(); foreach (db::build() ->select("item_id") diff --git a/modules/tag/tests/Tag_Item_Rest_Helper_Test.php b/modules/tag/tests/Tag_Item_Rest_Helper_Test.php index 69c580f1..cb368790 100644 --- a/modules/tag/tests/Tag_Item_Rest_Helper_Test.php +++ b/modules/tag/tests/Tag_Item_Rest_Helper_Test.php @@ -28,6 +28,7 @@ class Tag_Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function get_test() { $tag = tag::add(item::root(), "tag1")->reload(); + $request = new stdClass(); $request->url = rest::url("tag_item", $tag, item::root()); $this->assert_equal_array( array("url" => rest::url("tag_item", $tag, item::root()), @@ -38,6 +39,7 @@ class Tag_Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { } public function get_with_invalid_url_test() { + $request = new stdClass(); $request->url = "bogus"; try { tag_item_rest::get($request); @@ -50,6 +52,7 @@ class Tag_Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function delete_test() { $tag = tag::add(item::root(), "tag1")->reload(); + $request = new stdClass(); $request->url = rest::url("tag_item", $tag, item::root()); tag_item_rest::delete($request); @@ -60,7 +63,6 @@ class Tag_Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $album = test::random_album(); $tag = tag::add($album, "tag1")->reload(); - $tuple = rest::resolve(rest::url("tag_item", $tag, $album)); $this->assert_equal_array($tag->as_array(), $tuple[0]->as_array()); $this->assert_equal_array($album->as_array(), $tuple[1]->as_array()); diff --git a/modules/tag/tests/Tag_Rest_Helper_Test.php b/modules/tag/tests/Tag_Rest_Helper_Test.php index d3cae0fb..838de975 100644 --- a/modules/tag/tests/Tag_Rest_Helper_Test.php +++ b/modules/tag/tests/Tag_Rest_Helper_Test.php @@ -28,6 +28,7 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function get_test() { $tag = tag::add(item::root(), "tag1")->reload(); + $request = new stdClass(); $request->url = rest::url("tag", $tag); $this->assert_equal_array( array("url" => rest::url("tag", $tag), @@ -41,6 +42,7 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { } public function get_with_invalid_url_test() { + $request = new stdClass(); $request->url = "bogus"; try { tag_rest::get($request); @@ -53,6 +55,7 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function get_with_no_relationships_test() { $tag = test::random_tag(); + $request = new stdClass(); $request->url = rest::url("tag", $tag); $this->assert_equal_array( array("url" => rest::url("tag", $tag), @@ -72,7 +75,9 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { access::allow(identity::everybody(), "edit", $album); // Add the album to the tag + $request = new stdClass(); $request->url = rest::url("tag", $tag); + $request->params = new stdClass(); $request->params->url = rest::url("item", $album); $this->assert_equal_array( array("url" => rest::url("tag_item", $tag, $album)), @@ -93,7 +98,9 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function put_test() { $tag = test::random_tag(); + $request = new stdClass(); $request->url = rest::url("tag", $tag); + $request->params = new stdClass(); $request->params->name = "new name"; tag_rest::put($request); @@ -102,6 +109,7 @@ class Tag_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function delete_tag_test() { $tag = test::random_tag(); + $request = new stdClass(); $request->url = rest::url("tag", $tag); tag_rest::delete($request); diff --git a/modules/tag/tests/Tags_Rest_Helper_Test.php b/modules/tag/tests/Tags_Rest_Helper_Test.php index a1713811..cdf7bfdf 100644 --- a/modules/tag/tests/Tags_Rest_Helper_Test.php +++ b/modules/tag/tests/Tags_Rest_Helper_Test.php @@ -43,6 +43,8 @@ class Tags_Rest_Helper_Test extends Gallery_Unit_Test_Case { public function post_test() { access::allow(identity::everybody(), "edit", item::root()); + $request = new stdClass(); + $request->params = new stdClass(); $request->params->name = "test tag"; $this->assert_equal( array("url" => url::site("rest/tag/1")), @@ -55,6 +57,8 @@ class Tags_Rest_Helper_Test extends Gallery_Unit_Test_Case { identity::set_active_user(identity::guest()); try { + $request = new stdClass(); + $request->params = new stdClass(); $request->params->name = "test tag"; tags_rest::post($request); } catch (Exception $e) { diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index c11b0596..03d9858b 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -323,7 +323,7 @@ class Admin_Users_Controller extends Admin_Controller { return $form; } - private function _add_locale_dropdown(&$form, $user=null) { + private static function _add_locale_dropdown(&$form, $user=null) { $locales = locales::installed(); foreach ($locales as $locale => $display_name) { $locales[$locale] = SafeString::of_safe_html($display_name); -- cgit v1.2.3