summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-01-22 00:49:05 -0800
committerBharat Mediratta <bharat@menalto.com>2010-01-22 00:49:05 -0800
commitcb8b31d70ccd4872b122c204095ca8a439487c5d (patch)
tree2ec84d6d2be904d141e473c8417a61332f098dbf
parent2744b2e9380d2513a9691827d8995ba744c8852b (diff)
Updated tests to pass after recent refactor of gallery_rest -> item_rest.
-rw-r--r--modules/gallery/tests/Item_Rest_Helper_Test.php213
1 files changed, 213 insertions, 0 deletions
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 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2009 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * 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_Rest_Helper_Test extends Gallery_Unit_Test_Case {
+ public function resolve_test() {
+ $album = test::random_album();
+ $resolved = rest::resolve(rest::url("item", $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("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");
+ }
+}