mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-05-26 06:19:10 -04:00
Implement the RESTful interface for albums/photos/movies
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user