diff options
Diffstat (limited to 'modules/tag')
-rw-r--r-- | modules/tag/controllers/admin_tags.php | 20 | ||||
-rw-r--r-- | modules/tag/controllers/tags.php | 10 | ||||
-rw-r--r-- | modules/tag/helpers/tag.php | 28 | ||||
-rw-r--r-- | modules/tag/helpers/tag_event.php | 2 | ||||
-rw-r--r-- | modules/tag/helpers/tag_rest.php | 160 | ||||
-rw-r--r-- | modules/tag/helpers/tag_rss.php | 4 | ||||
-rw-r--r-- | modules/tag/models/tag.php | 36 | ||||
-rw-r--r-- | modules/tag/tests/Tag_Rest_Helper_Test.php | 288 | ||||
-rw-r--r-- | modules/tag/tests/Tag_Test.php | 6 |
9 files changed, 511 insertions, 43 deletions
diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index 67587c2e..e20b8ac8 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -19,7 +19,7 @@ */ class Admin_Tags_Controller extends Admin_Controller { public function index() { - $filter = $this->input->get("filter"); + $filter = Input::instance()->get("filter"); $view = new Admin_View("admin.html"); $view->content = new View("admin_tags.html"); @@ -29,13 +29,13 @@ class Admin_Tags_Controller extends Admin_Controller { if ($filter) { $query->like("name", $filter); } - $view->content->tags = $query->orderby("name", "ASC")->find_all(); + $view->content->tags = $query->order_by("name", "ASC")->find_all(); print $view; } public function form_delete($id) { $tag = ORM::factory("tag", $id); - if ($tag->loaded) { + if ($tag->loaded()) { print tag::get_delete_form($tag); } } @@ -44,14 +44,14 @@ class Admin_Tags_Controller extends Admin_Controller { access::verify_csrf(); $tag = ORM::factory("tag", $id); - if (!$tag->loaded) { - kohana::show_404(); + if (!$tag->loaded()) { + throw new Kohana_404_Exception(); } $form = tag::get_delete_form($tag); if ($form->validate()) { $name = $tag->name; - Database::instance()->delete("items_tags", array("tag_id" => "$tag->id")); + db::build()->delete("items_tags")->where("tag_id", "=", $tag->id)->execute(); $tag->delete(); message::success(t("Deleted tag %tag_name", array("tag_name" => $name))); log::success("tags", t("Deleted tag %tag_name", array("tag_name" => $name))); @@ -68,7 +68,7 @@ class Admin_Tags_Controller extends Admin_Controller { public function form_rename($id) { $tag = ORM::factory("tag", $id); - if ($tag->loaded) { + if ($tag->loaded()) { print InPlaceEdit::factory($tag->name) ->action("admin/tags/rename/$id") ->render(); @@ -79,8 +79,8 @@ class Admin_Tags_Controller extends Admin_Controller { access::verify_csrf(); $tag = ORM::factory("tag", $id); - if (!$tag->loaded) { - kohana::show_404(); + if (!$tag->loaded()) { + throw new Kohana_404_Exception(); } $in_place_edit = InPlaceEdit::factory($tag->name) @@ -106,7 +106,7 @@ class Admin_Tags_Controller extends Admin_Controller { } public function check_for_duplicate(Validation $post_data, $field) { - $tag_exists = ORM::factory("tag")->where("name", $post_data[$field])->count_all(); + $tag_exists = ORM::factory("tag")->where("name", "=", $post_data[$field])->count_all(); if ($tag_exists) { $post_data->add_error($field, "in_use"); } diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 9f9e45d9..992c7411 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -21,7 +21,7 @@ class Tags_Controller extends Controller { public function show($tag_id) { $tag = ORM::factory("tag", $tag_id); $page_size = module::get_var("gallery", "page_size", 9); - $page = (int) $this->input->get("page", "1"); + $page = (int) Input::instance()->get("page", "1"); $children_count = $tag->items_count(); $offset = ($page-1) * $page_size; $max_pages = max(ceil($children_count / $page_size), 1); @@ -79,12 +79,12 @@ class Tags_Controller extends Controller { public function autocomplete() { $tags = array(); - $tag_parts = preg_split("#,#", $this->input->get("q")); - $limit = $this->input->get("limit"); + $tag_parts = preg_split("#,#", Input::instance()->get("q")); + $limit = Input::instance()->get("limit"); $tag_part = end($tag_parts); $tag_list = ORM::factory("tag") - ->like("name", "{$tag_part}%", false) - ->orderby("name", "ASC") + ->where("name", "LIKE", "{$tag_part}%") + ->order_by("name", "ASC") ->limit($limit) ->find_all(); foreach ($tag_list as $tag) { diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 89a27034..8075afe4 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -33,8 +33,8 @@ class tag_Core { throw new exception("@todo MISSING_TAG_NAME"); } - $tag = ORM::factory("tag")->where("name", $tag_name)->find(); - if (!$tag->loaded) { + $tag = ORM::factory("tag")->where("name", "=", $tag_name)->find(); + if (!$tag->loaded()) { $tag->name = $tag_name; $tag->count = 0; $tag->save(); @@ -57,7 +57,7 @@ class tag_Core { */ static function popular_tags($count) { return ORM::factory("tag") - ->orderby("count", "DESC") + ->order_by("count", "DESC") ->limit($count) ->find_all(); } @@ -89,12 +89,12 @@ class tag_Core { */ static function item_tags($item) { $tags = array(); - foreach (Database::instance() + foreach (db::build() ->select("name") ->from("tags") ->join("items_tags", "tags.id", "items_tags.tag_id", "left") - ->where("items_tags.item_id", $item->id) - ->get() as $row) { + ->where("items_tags.item_id", "=", $item->id) + ->execute() as $row) { $tags[] = $row->name; } return $tags; @@ -125,10 +125,16 @@ class tag_Core { * Delete all tags associated with an item */ static function clear_all($item) { - $db = Database::instance(); - $db->query("UPDATE {tags} SET `count` = `count` - 1 WHERE `count` > 0 " . - "AND `id` IN (SELECT `tag_id` from {items_tags} WHERE `item_id` = $item->id)"); - $db->delete("items_tags", array("item_id" => "$item->id")); + db::build() + ->update("tags") + ->set("count", new Database_Expression("`count` - 1")) + ->where("count", ">", 0) + ->where("id", "IN", db::build()->select("tag_id")->from("items_tags")->where("item_id", "=", $item->id)) + ->execute(); + db::build() + ->delete("items_tags") + ->where("item_id", "=", $item->id) + ->execute(); } /** @@ -138,6 +144,6 @@ class tag_Core { // @todo There's a potential race condition here which we can solve by adding a lock around // this and all the cases where we create/update tags. I'm loathe to do that since it's an // extremely rare case. - Database::instance() ->delete("tags", array("count" => 0)); + db::build()->delete("tags")->where("count", "=", 0)->execute(); } }
\ No newline at end of file diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index a857a99d..6ee8e708 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -51,7 +51,7 @@ class tag_event_Core { try { tag::add($photo, $tag); } catch (Exception $e) { - Kohana::log("error", "Error adding tag: $tag\n" . + Kohana_Log::add("error", "Error adding tag: $tag\n" . $e->getMessage() . "\n" . $e->getTraceAsString()); } } diff --git a/modules/tag/helpers/tag_rest.php b/modules/tag/helpers/tag_rest.php new file mode 100644 index 00000000..cd1ca6c6 --- /dev/null +++ b/modules/tag/helpers/tag_rest.php @@ -0,0 +1,160 @@ +<?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 tag_rest_Core { + // If no arguments just return all the tags. If 2 or more then it is a path then + // return the tags for that item. But if its only 1, then is it a path or a tag? + // Assume a tag first, if nothing is found then try finding the item. + static function get($request) { + $resources = array(); + switch (count($request->arguments)) { + case 0: + $tags = ORM::factory("tag") + ->select("name", "count") + ->order_by("count", "DESC"); + if (!empty($request->limit)) { + $tags->limit($request->limit); + } + if (!empty($request->offset)) { + $tags->offset($request->offset); + } + $resources = array("tags" => array()); + foreach ($tags->find_all() as $row) { + $resources["tags"][] = array("name" => $row->name, "count" => $row->count); + } + break; + case 1: + $resources = tag_rest::_get_items($request); + if (!empty($resources)) { + $resources = array("resources" => $resources); + break; + } + default: + $item = ORM::factory("item") + ->where("relative_url_cache", "=", implode("/", $request->arguments)) + ->viewable() + ->find(); + if ($item->loaded()) { + $resources = array("tags" => tag::item_tags($item)); + } + } + + return rest::success($resources); + } + + static function post($request) { + if (empty($request->arguments) || count($request->arguments) != 1 || empty($request->path)) { + throw new Rest_Exception(400, "Bad request"); + } + $path = $request->path; + $tags = explode(",", $request->arguments[0]); + + $item = ORM::factory("item") + ->where("relative_url_cache", "=", $path) + ->viewable() + ->find(); + if (!$item->loaded()) { + throw new Kohana_404_Exception(); + } + + if (!access::can("edit", $item)) { + throw new Kohana_404_Exception(); + } + + foreach ($tags as $tag) { + tag::add($item, $tag); + } + return rest::success(); + } + + static function put($request) { + if (empty($request->arguments[0]) || empty($request->new_name)) { + throw new Rest_Exception(400, "Bad request"); + } + + $name = $request->arguments[0]; + + $tag = ORM::factory("tag") + ->where("name", "=", $name) + ->find(); + if (!$tag->loaded()) { + throw new Kohana_404_Exception(); + } + + $tag->name = $request->new_name; + $tag->save(); + + return rest::success(); + } + + static function delete($request) { + if (empty($request->arguments[0])) { + throw new Rest_Exception(400, "Bad request"); + } + $tags = explode(",", $request->arguments[0]); + if (!empty($request->path)) { + $tag_list = ORM::factory("tag") + ->join("items_tags", "tags.id", "items_tags.tag_id") + ->join("items", "items.id", "items_tags.item_id") + ->where("tags.name", "IN", $tags) + ->where("relative_url_cache", "=", $request->path) + ->viewable() + ->find_all(); + } else { + $tag_list = ORM::factory("tag") + ->where("name", "IN", $tags) + ->find_all(); + } + + foreach ($tag_list as $row) { + $row->delete(); + }; + + tag::compact(); + return rest::success(); + } + + private static function _get_items($request) { + $tags = explode(",", $request->arguments[0]); + $items = ORM::factory("item") + ->select_distinct("*") + ->join("items_tags", "items.id", "items_tags.item_id") + ->join("tags", "tags.id", "items_tags.tag_id") + ->where("tags.name", "IN", $tags); + if (!empty($request->limit)) { + $items->limit($request->limit); + } + if (!empty($request->offset)) { + $items->offset($request->offset); + } + $resources = array(); + foreach ($items->find_all() as $item) { + $resources[] = array("type" => $item->type, + "has_children" => $item->children_count() > 0, + "path" => $item->relative_url(), + "thumb_url" => $item->thumb_url(true), + "thumb_dimensions" => array("width" => $item->thumb_width, + "height" => $item->thumb_height), + "has_thumb" => $item->has_thumb(), + "title" => $item->title); + } + + return $resources; + } +} diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php index de5d6c72..f09a4530 100644 --- a/modules/tag/helpers/tag_rss.php +++ b/modules/tag/helpers/tag_rss.php @@ -31,8 +31,8 @@ class tag_rss_Core { static function feed($feed_id, $offset, $limit, $id) { if ($feed_id == "tag") { $tag = ORM::factory("tag", $id); - if (!$tag->loaded) { - Kohana::show_404(); + if (!$tag->loaded()) { + throw new Kohana_404_Exception(); } $feed->children = $tag->items($limit, $offset, "photo"); $feed->max_pages = ceil($tag->count / $limit); diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index be020f5f..d0d2117c 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -31,9 +31,9 @@ class Tag_Model extends ORM { $model = ORM::factory("item") ->viewable() ->join("items_tags", "items.id", "items_tags.item_id") - ->where("items_tags.tag_id", $this->id); + ->where("items_tags.tag_id", "=", $this->id); if ($type) { - $model->where("items.type", $type); + $model->where("items.type", "=", $type); } return $model->find_all($limit, $offset); } @@ -47,10 +47,10 @@ class Tag_Model extends ORM { $model = ORM::factory("item") ->viewable() ->join("items_tags", "items.id", "items_tags.item_id") - ->where("items_tags.tag_id", $this->id); + ->where("items_tags.tag_id", "=", $this->id); if ($type) { - $model->where("items.type", $type); + $model->where("items.type", "=", $type); } return $model->count_all(); } @@ -61,20 +61,29 @@ class Tag_Model extends ORM { * event for the union of all related items before and after the save. */ public function save() { - $db = Database::instance(); $related_item_ids = array(); - foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) { + foreach (db::build() + ->select("item_id") + ->from("items_tags") + ->where("tag_id", "=", $this->id) + ->execute() as $row) { $related_item_ids[$row->item_id] = 1; } $result = parent::save(); - foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) { + foreach (db::build() + ->select("item_id") + ->from("items_tags") + ->where("tag_id", "=", $this->id) + ->execute() as $row) { $related_item_ids[$row->item_id] = 1; } if ($related_item_ids) { - foreach (ORM::factory("item")->in("id", array_keys($related_item_ids))->find_all() as $item) { + foreach (ORM::factory("item") + ->where("id", "IN", array_keys($related_item_ids)) + ->find_all() as $item) { module::event("item_related_update", $item); } } @@ -88,15 +97,20 @@ class Tag_Model extends ORM { */ public function delete() { $related_item_ids = array(); - $db = Database::Instance(); - foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) { + foreach (db::build() + ->select("item_id") + ->from("items_tags") + ->where("tag_id", "=", $this->id) + ->execute() as $row) { $related_item_ids[$row->item_id] = 1; } $result = parent::delete(); if ($related_item_ids) { - foreach (ORM::factory("item")->in("id", array_keys($related_item_ids))->find_all() as $item) { + foreach (ORM::factory("item") + ->where("id", "IN", array_keys($related_item_ids)) + ->find_all() as $item) { module::event("item_related_update", $item); } } diff --git a/modules/tag/tests/Tag_Rest_Helper_Test.php b/modules/tag/tests/Tag_Rest_Helper_Test.php new file mode 100644 index 00000000..4e8dd527 --- /dev/null +++ b/modules/tag/tests/Tag_Rest_Helper_Test.php @@ -0,0 +1,288 @@ +<?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 Tag_Rest_Helper_Test extends Unit_Test_Case { + public function setup() { + try { + Database::instance()->query("TRUNCATE {tags}"); + Database::instance()->query("TRUNCATE {items_tags}"); + } catch (Exception $e) { } + $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); + + try { + if (!empty($this->_user)) { + $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; + } + + private function _create_album($tags=array(), $parent=null) { + $album_name = "tag_album_" . rand(); + if (empty($parent)) { + $parent = ORM::factory("item", 1); + } + $album = album::create($parent, $album_name, $album_name, $album_name); + foreach ($tags as $tag) { + tag::add($album, $tag); + } + return $album; + } + + private function _create_image($tags=array(), $parent=null) { + $filename = MODPATH . "gallery/tests/test.jpg"; + $image_name = "tag_image_" . rand(); + if (empty($parent)) { + $parent = ORM::factory("item", 1); + } + $photo = photo::create($parent, $filename, "$image_name.jpg", $image_name); + foreach ($tags as $tag) { + tag::add($photo, $tag); + } + return $photo; + } + + public function tag_rest_get_all_test() { + $album = $this->_create_album(array("albums", "A1", "T1")); + $child = $this->_create_album(array("albums", "C1", "T1"), $album); + $photo = $this->_create_image(array("photos", "P1", "T1"), $child); + $sibling = $this->_create_image(array("photos", "P3"), $album); + + $request = (object)array("arguments" => array(), "limit" => 2, "offset" => 1); + + $this->assert_equal( + json_encode(array("status" => "OK", + "tags" => array(array("name" => "albums", "count" => 2), + array("name" => "photos", "count" => 2)))), + tag_rest::get($request)); + } + + public function tag_rest_get_tags_for_item_test() { + $photo = $this->_create_image(array("photos", "P1", "T1")); + + $request = (object)array("arguments" => explode("/", $photo->relative_url())); + + $this->assert_equal( + json_encode(array("status" => "OK", + "tags" => array("photos", "P1", "T1"))), + tag_rest::get($request)); + } + + public function tag_rest_get_items_test() { + $album = $this->_create_album(array("albums", "A1", "T1")); + $child = $this->_create_album(array("albums", "A1", "T1"), $album); + $photo = $this->_create_image(array("photos", "P1", "T1"), $child); + $sibling = $this->_create_image(array("photos", "P3"), $album); + $child->reload(); + $album->reload(); + + $request = (object)array("arguments" => array("albums")); + + $resources = array(); + foreach (array($album, $child) as $resource) { + $resources[] = array("type" => $resource->type, + "has_children" => $resource->children_count() > 0, + "path" => $resource->relative_url(), + "thumb_url" => $resource->thumb_url(), + "thumb_dimensions" => array("width" => $resource->thumb_width, + "height" => $resource->thumb_height), + "has_thumb" => $resource->has_thumb(), + "title" => $resource->title); + + } + $this->assert_equal(json_encode(array("status" => "OK", "resources" => $resources)), + tag_rest::get($request)); + } + + public function tag_rest_add_tags_for_item_no_path_test() { + $request = (object)array("arguments" => array("new,one")); + + try { + tag_rest::post($request); + } catch (Rest_Exception $e) { + $this->assert_equal("400 Bad request", $e->getMessage()); + } catch (Exception $e) { + $this->assert_false(true, $e->__toString()); + } + } + + public function tag_rest_add_tags_for_item_not_found_test() { + $photo = $this->_create_image(array("photos", "P1", "T1")); + $request = (object)array("path" => $photo->relative_url() . "b", + "arguments" => array("new,one")); + try { + tag_rest::post($request); + } catch (Kohana_404_Exception $k404) { + } catch (Exception $e) { + $this->assert_false(true, $e->__toString()); + } + } + + public function tag_rest_add_tags_for_item_no_access_test() { + $photo = $this->_create_image(array("photos", "P1", "T1")); + $this->_create_user(); + $request = (object)array("path" => $photo->relative_url(), + "arguments" => array("new,one")); + + try { + tag_rest::post($request); + } catch (Kohana_404_Exception $k404) { + } catch (Exception $e) { + $this->assert_false(true, $e->__toString()); + } + } + + public function tag_rest_add_tags_for_item_test() { + $album = $this->_create_album(array("albums", "A1", "T1")); + $child = $this->_create_album(array("albums", "A1", "T1"), $album); + $photo = $this->_create_image(array("photos", "P1", "T1"), $child); + $sibling = $this->_create_image(array("photos", "P3"), $album); + access::allow(identity::registered_users(), "edit", $child); + $this->_create_user(); + $request = (object)array("path" => $photo->relative_url(), + "arguments" => array("new,one")); + + $this->assert_equal( + json_encode(array("status" => "OK")), + tag_rest::post($request)); + $request = (object)array("arguments" => explode("/", $photo->relative_url())); + $this->assert_equal( + json_encode(array("status" => "OK", + "tags" => array("photos", "P1", "T1", "new", "one"))), + tag_rest::get($request)); + } + + public function tag_rest_update_tag_no_arguments_test() { + $request = (object)array("arguments" => array()); + + try { + tag_rest::put($request); + } catch (Rest_Exception $e) { + $this->assert_equal("400 Bad request", $e->getMessage()); + } catch (Exception $e) { + $this->assert_false(true, $e->__toString()); + } + } + + public function tag_rest_update_tag_one_arguments_test() { + $request = (object)array("arguments" => array("photos")); + try { + tag_rest::put($request); + } catch (Rest_Exception $e) { + $this->assert_equal("400 Bad request", $e->getMessage()); + } catch (Exception $e) { + $this->assert_false(true, $e->__toString()); + } + + $request = (object)array("arguments" => array(), "new_name" => "valid"); + try { + tag_rest::put($request); + } catch (Rest_Exception $e) { + $this->assert_equal("400 Bad request", $e->getMessage()); + } catch (Exception $e) { + $this->assert_false(true, $e->__toString()); + } + } + + public function tag_rest_update_tags_not_found_test() { + $request = (object)array("arguments" => array("not"), "new_name" => "found"); + + try { + tag_rest::put($request); + } catch (Kohana_404_Exception $k404) { + } catch (Exception $e) { + $this->assert_false(true, $e->__toString()); + } + } + + public function tag_rest_update_tags_test() { + $album = $this->_create_album(array("albums", "A1", "T1")); + $child = $this->_create_album(array("albums", "A1", "T1"), $album); + $photo = $this->_create_image(array("photos", "P1", "T1"), $child); + $child->reload(); + $sibling = $this->_create_image(array("photos", "P3"), $album); + $child->reload(); + $album->reload(); + + $request = (object)array("arguments" => array("albums"), "new_name" => "new name"); + + $this->assert_equal(json_encode(array("status" => "OK")), tag_rest::put($request)); + + $request = (object)array("arguments" => array("new name")); + $resources = array(); + foreach (array($album, $child) as $resource) { + $resources[] = array("type" => $resource->type, + "has_children" => $resource->children_count() > 0, + "path" => $resource->relative_url(), + "thumb_url" => $resource->thumb_url(), + "thumb_dimensions" => array("width" => $resource->thumb_width, + "height" => $resource->thumb_height), + "has_thumb" => $resource->has_thumb(), + "title" => $resource->title); + + } + $this->assert_equal( + json_encode(array("status" => "OK", "resources" => $resources)), + tag_rest::get($request)); + } + + public function tag_rest_delete_tag_test() { + $album = $this->_create_album(array("albums", "A1", "T1")); + $child = $this->_create_album(array("albums", "A1", "T1"), $album); + $photo = $this->_create_image(array("photos", "P1", "T1"), $child); + + $request = (object)array("arguments" => array("T1,P1")); + $this->assert_equal(json_encode(array("status" => "OK")), tag_rest::delete($request)); + + $request = (object)array("arguments" => array("T1,P1")); + $this->assert_equal(json_encode(array("status" => "OK")), + tag_rest::get($request)); + } + + public function tag_rest_delete_tagc_from_item_test() { + $album = $this->_create_album(array("albums", "A1", "T1")); + $child = $this->_create_album(array("albums", "A1", "T1"), $album); + $photo = $this->_create_image(array("photos", "P1", "T1"), $child); + $request = (object)array("arguments" => array("T1,P1"), + $photo->relative_url()); + + $this->assert_equal(json_encode(array("status" => "OK")), tag_rest::delete($request)); + + $request = (object)array("arguments" => explode("/", $photo->relative_url())); + $this->assert_equal(json_encode(array("status" => "OK", "tags" => array("photos"))), + tag_rest::get($request)); + } +} diff --git a/modules/tag/tests/Tag_Test.php b/modules/tag/tests/Tag_Test.php index c9a96286..c96e7f2b 100644 --- a/modules/tag/tests/Tag_Test.php +++ b/modules/tag/tests/Tag_Test.php @@ -25,18 +25,18 @@ class Tag_Test extends Unit_Test_Case { $tag1 = "tag1"; tag::add($album, $tag1); - $tag = ORM::factory("tag")->where("name", $tag1)->find(); + $tag = ORM::factory("tag")->where("name", "=", $tag1)->find(); $this->assert_true(1, $tag->count); // Make sure adding the tag again doesn't increase the count tag::add($album, $tag1); - $tag = ORM::factory("tag")->where("name", $tag1)->find(); + $tag = ORM::factory("tag")->where("name", "=", $tag1)->find(); $this->assert_true(1, $tag->count); $rand = rand(); $album = album::create($root, $rand, $rand, $rand); tag::add($album, $tag1); - $tag = ORM::factory("tag")->where("name", $tag1)->find(); + $tag = ORM::factory("tag")->where("name", "=", $tag1)->find(); $this->assert_true(2, $tag->count); } }
\ No newline at end of file |