diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-09 12:06:45 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-12-09 12:06:45 -0800 |
commit | dfc556e8a6e2c0636a93d87bc0cdb0f85f588fd4 (patch) | |
tree | 625edab00bf512948a6d73c85aecb1759715c5a4 /modules/gallery/tests | |
parent | c3a0f419c6f53fa93b47fa76f5afdc3696d64720 (diff) |
Implement the RESTful interface for albums/photos/movies
Diffstat (limited to 'modules/gallery/tests')
-rw-r--r-- | modules/gallery/tests/Gallery_Rest_Helper_Test.php | 108 |
1 files changed, 102 insertions, 6 deletions
diff --git a/modules/gallery/tests/Gallery_Rest_Helper_Test.php b/modules/gallery/tests/Gallery_Rest_Helper_Test.php index b874863f..9c960409 100644 --- a/modules/gallery/tests/Gallery_Rest_Helper_Test.php +++ b/modules/gallery/tests/Gallery_Rest_Helper_Test.php @@ -36,7 +36,9 @@ class Gallery_Rest_Helper_Test extends Unit_Test_Case { $rand = rand(); $this->_photo = photo::create($this->_child, $filename, "$rand.jpg", $rand); - identity::set_active_user($this->_user); + $filename = MODPATH . "gallery/tests/test.jpg"; + $rand = rand(); + $this->_sibling = photo::create($this->_album, $filename, "$rand.jpg", $rand); } public function teardown() { @@ -54,11 +56,11 @@ class Gallery_Rest_Helper_Test extends Unit_Test_Case { } public function gallery_rest_get_album_test() { - $request = (object)array("path" => $this->_child->relative_path()); + $request = (object)array("path" => $this->_child->relative_url()); $this->assert_equal( json_encode(array("status" => "OK", - "album" => array("path" => $this->_child->relative_url_path(), + "album" => array("path" => $this->_child->relative_url(), "title" => $this->_child->title, "thumb_url" => $this->_child->thumb_url(), "url" => $this->_child->abs_url(), @@ -67,17 +69,17 @@ class Gallery_Rest_Helper_Test extends Unit_Test_Case { "children" => array(array( "type" => "photo", "has_children" => false, - "path" => $this->_photo->relative_url_path(), + "path" => $this->_photo->relative_url(), "title" => $this->_photo->title))))), gallery_rest::get($request)); } public function gallery_rest_get_photo_test() { - $request = (object)array("path" => $this->_photo->relative_path()); + $request = (object)array("path" => $this->_photo->relative_url()); $this->assert_equal( json_encode(array("status" => "OK", - "photo" => array("path" => $this->_photo->relative_path(), + "photo" => array("path" => $this->_photo->relative_url(), "title" => $this->_photo->title, "thumb_url" => $this->_photo->thumb_url(), "url" => $this->_photo->abs_url(), @@ -85,4 +87,98 @@ class Gallery_Rest_Helper_Test extends Unit_Test_Case { "internet_address" => $this->_photo->slug))), gallery_rest::get($request)); } + + public function gallery_rest_put_album_no_path_test() { + access::allow(identity::registered_users(), "edit", $this->_child); + + identity::set_active_user($this->_user); + $request = (object)array("description" => "Updated description", + "title" => "Updated Title", + "sort_order" => "DESC", + "sort_column" => "title", + "name" => "new name"); + + $this->assert_equal(json_encode(array("status" => "ERROR", "message" => "Invalid request")), + gallery_rest::put($request)); + } + + public function gallery_rest_put_album_not_found_test() { + access::allow(identity::registered_users(), "edit", $this->_child); + + identity::set_active_user($this->_user); + $request = (object)array("path" => $this->_child->relative_url() . rand(), + "description" => "Updated description", + "title" => "Updated Title", + "sort_order" => "DESC", + "sort_column" => "title", + "name" => "new name"); + + $this->assert_equal(json_encode(array("status" => "ERROR", "message" => "Resource not found")), + gallery_rest::put($request)); + } + + public function gallery_rest_put_album_no_edit_permission_test() { + identity::set_active_user($this->_user); + $request = (object)array("path" => $this->_child->relative_url(), + "description" => "Updated description", + "title" => "Updated Title", + "sort_order" => "DESC", + "sort_column" => "title", + "name" => "new name"); + + $this->assert_equal(json_encode(array("status" => "ERROR", "message" => "Resource not found")), + gallery_rest::put($request)); + } + + public function gallery_rest_put_album_rename_conflict_test() { + access::allow(identity::registered_users(), "edit", $this->_child); + identity::set_active_user($this->_user); + $request = (object)array("path" => $this->_child->relative_url(), + "description" => "Updated description", + "title" => "Updated Title", + "sort_order" => "DESC", + "sort_column" => "title", + "name" => $this->_sibling->name); + + $this->assert_equal( + json_encode(array("status" => "ERROR", + "message" => "Renaming album/child failed: new name exists")), + gallery_rest::put($request)); + } + + public function gallery_rest_put_album_test() { + access::allow(identity::registered_users(), "edit", $this->_child); + + identity::set_active_user($this->_user); + $request = (object)array("path" => $this->_child->relative_url(), + "description" => "Updated description", + "title" => "Updated Title", + "sort_order" => "DESC", + "sort_column" => "title", + "name" => "new name"); + + $this->assert_equal(json_encode(array("status" => "OK")), gallery_rest::put($request)); + $this->_child->reload(); + $this->assert_equal("Updated description", $this->_child->description); + $this->assert_equal("Updated Title", $this->_child->title); + $this->assert_equal("DESC", $this->_child->sort_order); + $this->assert_equal("title", $this->_child->sort_column); + $this->assert_equal("new name", $this->_child->name); + } + + public function gallery_rest_put_photo_test() { + access::allow(identity::registered_users(), "edit", $this->_child); + + identity::set_active_user($this->_user); + $request = (object)array("path" => $this->_photo->relative_url(), + "description" => "Updated description", + "title" => "Updated Title", + "name" => "new name"); + + $this->assert_equal(json_encode(array("status" => "OK")), gallery_rest::put($request)); + $this->_photo->reload(); + $this->assert_equal("Updated description", $this->_photo->description); + $this->assert_equal("Updated Title", $this->_photo->title); + $this->assert_equal("new name", $this->_photo->name); + } } |