From 1c85cf6397d8c780db0d2ade185e0bbf714a57a6 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Sat, 16 Jan 2010 22:27:07 -0800
Subject: Convert comment code over to model based validation.
---
modules/comment/controllers/comments.php | 57 +++++++++------------
modules/comment/helpers/comment.php | 40 ---------------
modules/comment/models/comment.php | 87 ++++++++++++++++++++++++++++----
3 files changed, 99 insertions(+), 85 deletions(-)
(limited to 'modules/comment')
diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php
index 068152a2..6c546321 100644
--- a/modules/comment/controllers/comments.php
+++ b/modules/comment/controllers/comments.php
@@ -26,50 +26,39 @@ class Comments_Controller extends Controller {
access::required("view", $item);
$form = comment::get_add_form($item);
- $valid = $form->validate();
- if ($valid) {
- if (identity::active_user()->guest && !$form->add_comment->inputs["name"]->value) {
- $form->add_comment->inputs["name"]->add_error("missing", 1);
- $valid = false;
- }
-
- if (!$form->add_comment->text->value) {
- $form->add_comment->text->add_error("missing", 1);
- $valid = false;
+ try {
+ $valid = $form->validate();
+ $comment = ORM::factory("comment");
+ $comment->item_id = $id;
+ $comment->author_id = identity::active_user()->id;
+ $comment->text = $form->add_comment->text->value;
+ $comment->guest_name = $form->add_comment->inputs["name"]->value;
+ $comment->guest_email = $form->add_comment->email->value;
+ $comment->guest_url = $form->add_comment->url->value;
+ $comment->validate();
+ } catch (ORM_Validation_Exception $e) {
+ // Translate ORM validation errors into form error messages
+ foreach ($e->validation->errors() as $key => $error) {
+ switch ($key) {
+ case "guest_name": $key = "name"; break;
+ case "guest_email": $key = "email"; break;
+ }
+ $form->add_comment->inputs[$key]->add_error($error, 1);
}
+ $valid = false;
}
if ($valid) {
- $comment = comment::create(
- $item, identity::active_user(),
- $form->add_comment->text->value,
- $form->add_comment->inputs["name"]->value,
- $form->add_comment->email->value,
- $form->add_comment->url->value);
-
- $active = identity::active_user();
- if ($active->guest) {
- $form->add_comment->inputs["name"]->value("");
- $form->add_comment->email->value("");
- $form->add_comment->url->value("");
- } else {
- $form->add_comment->inputs["name"]->value($active->full_name);
- $form->add_comment->email->value($active->email);
- $form->add_comment->url->value($active->url);
- }
-
- $form->add_comment->text->value("");
+ $comment->save();
$view = new Theme_View("comment.html", "other", "comment-fragment");
$view->comment = $comment;
print json_encode(
array("result" => "success",
- "view" => $view->__toString(),
- "form" => $form->__toString()));
+ "view" => (string) $view,
+ "form" => (string) comment::get_add_form($item)));
} else {
- print json_encode(
- array("result" => "error",
- "form" => $form->__toString()));
+ print json_encode(array("result" => "error", "form" => (string) $form));
}
}
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php
index 1e1e7d2f..389c8922 100644
--- a/modules/comment/helpers/comment.php
+++ b/modules/comment/helpers/comment.php
@@ -24,46 +24,6 @@
* Note: by design, this class does not do any permission checking.
*/
class comment_Core {
- /**
- * Create a new comment.
- * @param Item_MOdel $item the parent item
- * @param User_Model $author the author User_Model
- * @param string $text comment body
- * @param string $guest_name guest's name (if the author is a guest user, default empty)
- * @param string $guest_email guest's email (if the author is a guest user, default empty)
- * @param string $guest_url guest's url (if the author is a guest user, default empty)
- * @return Comment_Model
- */
- static function create($item, $author, $text, $guest_name=null,
- $guest_email=null, $guest_url=null) {
- $comment = ORM::factory("comment");
- $comment->author_id = $author->id;
- $comment->guest_email = $guest_email;
- $comment->guest_name = $guest_name;
- $comment->guest_url = $guest_url;
- $comment->item_id = $item->id;
- $comment->text = $text;
- $comment->state = "published";
-
- // These values are useful for spam fighting, so save them with the comment.
- $input = Input::instance();
- $comment->server_http_accept = substr($input->server("HTTP_ACCEPT"), 0, 128);
- $comment->server_http_accept_charset = substr($input->server("HTTP_ACCEPT_CHARSET"), 0, 64);
- $comment->server_http_accept_encoding = substr($input->server("HTTP_ACCEPT_ENCODING"), 0, 64);
- $comment->server_http_accept_language = substr($input->server("HTTP_ACCEPT_LANGUAGE"), 0, 64);
- $comment->server_http_connection = substr($input->server("HTTP_CONNECTION"), 0, 64);
- $comment->server_http_host = substr($input->server("HTTP_HOST"), 0, 64);
- $comment->server_http_referer = substr($input->server("HTTP_REFERER"), 0, 255);
- $comment->server_http_user_agent = substr($input->server("HTTP_USER_AGENT"), 0, 128);
- $comment->server_query_string = substr($input->server("QUERY_STRING"), 0, 64);
- $comment->server_remote_addr = substr($input->server("REMOTE_ADDR"), 0, 32);
- $comment->server_remote_host = substr($input->server("REMOTE_HOST"), 0, 64);
- $comment->server_remote_port = substr($input->server("REMOTE_PORT"), 0, 16);
- $comment->save();
-
- return $comment;
- }
-
static function get_add_form($item) {
$form = new Forge("comments/create/{$item->id}", "", "post", array("id" => "g-comment-form"));
$group = $form->group("add_comment")->label(t("Add comment"));
diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php
index e0b82039..7ad47c6d 100644
--- a/modules/comment/models/comment.php
+++ b/modules/comment/models/comment.php
@@ -18,6 +18,11 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Comment_Model extends ORM {
+ var $rules = array(
+ "text" => array("rules" => array("required")),
+ "state" => array("rules" => array("Comment_Model::valid_state"))
+ );
+
function item() {
return ORM::factory("item", $this->item_id);
}
@@ -53,25 +58,57 @@ class Comment_Model extends ORM {
}
}
+ /**
+ * Add some custom per-instance rules.
+ */
+ public function validate($array=null) {
+ // validate() is recursive, only modify the rules on the outermost call.
+ if (!$array) {
+ $this->rules["item_id"]["callbacks"] = array(array($this, "valid_item"));
+ $this->rules["guest_name"]["callbacks"] = array(array($this, "valid_author"));
+ }
+
+ parent::validate($array);
+ }
+
/**
* @see ORM::save()
*/
public function save() {
- if (!empty($this->changed)) {
- $this->updated = time();
- if (!$this->loaded() && empty($this->created)) {
- $this->created = $this->updated;
- $created = true;
+ $this->updated = time();
+ if (!$this->loaded()) {
+ // New comment
+ $this->created = $this->updated;
+ if (empty($this->state)) {
+ $this->state = "published";
}
- }
- $visible_change = $this->original()->state == "published" || $this->state == "published";
-
- $original = clone $this->original();
- parent::save();
- if (isset($created)) {
+ // These values are useful for spam fighting, so save them with the comment. It's painful to
+ // check each one to see if it already exists before setting it, so just use server_http_host
+ // as a semaphore for now (we use that in g2_import.php)
+ if (empty($this->server_http_host)) {
+ $input = Input::instance();
+ $this->server_http_accept = substr($input->server("HTTP_ACCEPT"), 0, 128);
+ $this->server_http_accept_charset = substr($input->server("HTTP_ACCEPT_CHARSET"), 0, 64);
+ $this->server_http_accept_encoding = substr($input->server("HTTP_ACCEPT_ENCODING"), 0, 64);
+ $this->server_http_accept_language = substr($input->server("HTTP_ACCEPT_LANGUAGE"), 0, 64);
+ $this->server_http_connection = substr($input->server("HTTP_CONNECTION"), 0, 64);
+ $this->server_http_host = substr($input->server("HTTP_HOST"), 0, 64);
+ $this->server_http_referer = substr($input->server("HTTP_REFERER"), 0, 255);
+ $this->server_http_user_agent = substr($input->server("HTTP_USER_AGENT"), 0, 128);
+ $this->server_query_string = substr($input->server("QUERY_STRING"), 0, 64);
+ $this->server_remote_addr = substr($input->server("REMOTE_ADDR"), 0, 32);
+ $this->server_remote_host = substr($input->server("REMOTE_HOST"), 0, 64);
+ $this->server_remote_port = substr($input->server("REMOTE_PORT"), 0, 16);
+ }
+ $visible_change = $this->original()->state == "published" || $this->state == "published";
+ parent::save();
module::event("comment_created", $this);
} else {
+ // Updated comment
+ $visible_change = $this->original()->state == "published" || $this->state == "published";
+ $original = clone $this->original();
+ parent::save();
module::event("comment_updated", $original, $this);
}
@@ -92,4 +129,32 @@ class Comment_Model extends ORM {
$this->join("items", "items.id", "comments.item_id");
return item::viewable($this);
}
+
+ /**
+ * Make sure we have an appropriate author id set, or a guest name.
+ */
+ public function valid_author(Validation $v, $field) {
+ if ($this->author_id == identity::guest()->id && empty($this->guest_name)) {
+ $v->add_error("guest_name", "required");
+ }
+ }
+
+ /**
+ * Make sure we have a valid associated item id.
+ */
+ public function valid_item(Validation $v, $field) {
+ if (db::build()
+ ->from("items")
+ ->where("id", "=", $this->item_id)
+ ->count_records() != 1) {
+ $v->add_error("item_id", "invalid");
+ }
+ }
+
+ /**
+ * Make sure that the state is legal.
+ */
+ static function valid_state($value) {
+ return in_array($value, array("published", "unpublished", "spam", "deleted"));
+ }
}
--
cgit v1.2.3
From 3789b85b7d960a046e4b6de2bbbf82b3e59d2eab Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Sun, 17 Jan 2010 12:19:24 -0800
Subject: Move rules down into validate() and improve valid_author().
---
modules/comment/models/comment.php | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
(limited to 'modules/comment')
diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php
index 7ad47c6d..891ffbce 100644
--- a/modules/comment/models/comment.php
+++ b/modules/comment/models/comment.php
@@ -18,11 +18,6 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Comment_Model extends ORM {
- var $rules = array(
- "text" => array("rules" => array("required")),
- "state" => array("rules" => array("Comment_Model::valid_state"))
- );
-
function item() {
return ORM::factory("item", $this->item_id);
}
@@ -64,8 +59,12 @@ class Comment_Model extends ORM {
public function validate($array=null) {
// validate() is recursive, only modify the rules on the outermost call.
if (!$array) {
- $this->rules["item_id"]["callbacks"] = array(array($this, "valid_item"));
- $this->rules["guest_name"]["callbacks"] = array(array($this, "valid_author"));
+ $this->rules = array(
+ "guest_name" => array("callbacks" => array(array($this, "valid_author"))),
+ "item_id" => array("callbacks" => array(array($this, "valid_item"))),
+ "state" => array("rules" => array("Comment_Model::valid_state")),
+ "text" => array("rules" => array("required")),
+ );
}
parent::validate($array);
@@ -134,7 +133,9 @@ class Comment_Model extends ORM {
* Make sure we have an appropriate author id set, or a guest name.
*/
public function valid_author(Validation $v, $field) {
- if ($this->author_id == identity::guest()->id && empty($this->guest_name)) {
+ if (empty($this->author_id)) {
+ $v->add_error("author_id", "required");
+ } else if ($this->author_id == identity::guest()->id && empty($this->guest_name)) {
$v->add_error("guest_name", "required");
}
}
--
cgit v1.2.3
From f68862f4c9a595cfd84e844e85339f7ed82c6c1a Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Sun, 17 Jan 2010 19:26:32 -0800
Subject: Updated for model based validation.
---
modules/comment/tests/Comment_Event_Test.php | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
(limited to 'modules/comment')
diff --git a/modules/comment/tests/Comment_Event_Test.php b/modules/comment/tests/Comment_Event_Test.php
index ff7f1c26..5b7daef4 100644
--- a/modules/comment/tests/Comment_Event_Test.php
+++ b/modules/comment/tests/Comment_Event_Test.php
@@ -19,14 +19,17 @@
*/
class Comment_Event_Test extends Unit_Test_Case {
public function deleting_an_item_deletes_its_comments_too_test() {
- $rand = rand();
- $album = album::create(ORM::factory("item", 1), "test_$rand", "test_$rand");
- $comment = comment::create(
- $album, identity::guest(), "text_$rand", "name_$rand", "email_$rand", "url_$rand");
+ $album = test::random_album();
+
+ $comment = ORM::factory("comment");
+ $comment->item_id = $album->id;
+ $comment->author_id = identity::guest()->id;
+ $comment->guest_name = "test";
+ $comment->text = "text";
+ $comment->save();
$album->delete();
- $deleted_comment = ORM::factory("comment", $comment->id);
- $this->assert_false($deleted_comment->loaded());
+ $this->assert_false(ORM::factory("comment")->where("id", "=", $comment->id)->find()->loaded());
}
}
--
cgit v1.2.3
From c863544ec39da4f39e30cf28ea4972c0ad1e3923 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Sun, 17 Jan 2010 19:31:49 -0800
Subject: Add validation for guest_email and guest_url.
---
modules/comment/models/comment.php | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
(limited to 'modules/comment')
diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php
index 891ffbce..69b8505e 100644
--- a/modules/comment/models/comment.php
+++ b/modules/comment/models/comment.php
@@ -60,10 +60,12 @@ class Comment_Model extends ORM {
// validate() is recursive, only modify the rules on the outermost call.
if (!$array) {
$this->rules = array(
- "guest_name" => array("callbacks" => array(array($this, "valid_author"))),
- "item_id" => array("callbacks" => array(array($this, "valid_item"))),
- "state" => array("rules" => array("Comment_Model::valid_state")),
- "text" => array("rules" => array("required")),
+ "guest_name" => array("callbacks" => array(array($this, "valid_author"))),
+ "guest_email" => array("rules" => array("email")),
+ "guest_url" => array("rules" => array("url")),
+ "item_id" => array("callbacks" => array(array($this, "valid_item"))),
+ "state" => array("rules" => array("Comment_Model::valid_state")),
+ "text" => array("rules" => array("required")),
);
}
--
cgit v1.2.3
From c5c17eecc3334649ee3f78bc4117262d1505eb3b Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Sun, 17 Jan 2010 19:32:05 -0800
Subject: Updated for model based validation.
---
modules/comment/tests/Comment_Helper_Test.php | 32 ++++++++++++++++-----------
1 file changed, 19 insertions(+), 13 deletions(-)
(limited to 'modules/comment')
diff --git a/modules/comment/tests/Comment_Helper_Test.php b/modules/comment/tests/Comment_Helper_Test.php
index 8e726869..d780aba6 100644
--- a/modules/comment/tests/Comment_Helper_Test.php
+++ b/modules/comment/tests/Comment_Helper_Test.php
@@ -48,15 +48,19 @@ class Comment_Helper_Test extends Unit_Test_Case {
}
public function create_comment_for_guest_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
- $comment = comment::create(
- $root, identity::guest(), "text_$rand", "name_$rand", "email_$rand", "url_$rand");
+ $comment = ORM::factory("comment");
+ $comment->item_id = item::root()->id;
+ $comment->text = "text";
+ $comment->author_id = identity::guest()->id;
+ $comment->guest_name = "name";
+ $comment->guest_email = "email@email.com";
+ $comment->guest_url = "http://url.com";
+ $comment->save();
- $this->assert_equal("name_$rand", $comment->author_name());
- $this->assert_equal("email_$rand", $comment->author_email());
- $this->assert_equal("url_$rand", $comment->author_url());
- $this->assert_equal("text_$rand", $comment->text);
+ $this->assert_equal("name", $comment->author_name());
+ $this->assert_equal("email@email.com", $comment->author_email());
+ $this->assert_equal("http://url.com", $comment->author_url());
+ $this->assert_equal("text", $comment->text);
$this->assert_equal(1, $comment->item_id);
$this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
@@ -78,16 +82,18 @@ class Comment_Helper_Test extends Unit_Test_Case {
}
public function create_comment_for_user_test() {
- $rand = rand();
- $root = ORM::factory("item", 1);
$admin = identity::admin_user();
- $comment = comment::create(
- $root, $admin, "text_$rand", "name_$rand", "email_$rand", "url_$rand");
+
+ $comment = ORM::factory("comment");
+ $comment->item_id = item::root()->id;
+ $comment->text = "text";
+ $comment->author_id = $admin->id;
+ $comment->save();
$this->assert_equal($admin->full_name, $comment->author_name());
$this->assert_equal($admin->email, $comment->author_email());
$this->assert_equal($admin->url, $comment->author_url());
- $this->assert_equal("text_$rand", $comment->text);
+ $this->assert_equal("text", $comment->text);
$this->assert_equal(1, $comment->item_id);
$this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
--
cgit v1.2.3
From c5f9a466c88985857bd7ef9499b631520d4a3365 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Sun, 17 Jan 2010 19:33:44 -0800
Subject: Updated for model based validation.
---
modules/comment/tests/Comment_Model_Test.php | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
(limited to 'modules/comment')
diff --git a/modules/comment/tests/Comment_Model_Test.php b/modules/comment/tests/Comment_Model_Test.php
index aa91d6f2..c98eb63c 100644
--- a/modules/comment/tests/Comment_Model_Test.php
+++ b/modules/comment/tests/Comment_Model_Test.php
@@ -20,21 +20,24 @@
class Comment_Model_Test extends Unit_Test_Case {
public function cant_view_comments_for_unviewable_items_test() {
- $root = ORM::factory("item", 1);
- $album = album::create($root, rand(), rand(), rand());
- $comment = comment::create($album, identity::guest(), "text", "name", "email", "url");
+ $album = test::random_album();
+
+ $comment = ORM::factory("comment");
+ $comment->item_id = $album->id;
+ $comment->author_id = identity::admin_user()->id;
+ $comment->text = "text";
+ $comment->save();
+
identity::set_active_user(identity::guest());
// We can see the comment when permissions are granted on the album
access::allow(identity::everybody(), "view", $album);
- $this->assert_equal(
- 1,
+ $this->assert_true(
ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all());
// We can't see the comment when permissions are denied on the album
access::deny(identity::everybody(), "view", $album);
- $this->assert_equal(
- 0,
+ $this->assert_false(
ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all());
}
}
--
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/comment')
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 6dc88be6b6828a968409167e9f3c57a1bb9ec79c Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Wed, 20 Jan 2010 22:50:20 -0800
Subject: Stop using MY_ORM::original().
---
modules/comment/models/comment.php | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
(limited to 'modules/comment')
diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php
index 69b8505e..43c4148f 100644
--- a/modules/comment/models/comment.php
+++ b/modules/comment/models/comment.php
@@ -102,13 +102,14 @@ class Comment_Model extends ORM {
$this->server_remote_host = substr($input->server("REMOTE_HOST"), 0, 64);
$this->server_remote_port = substr($input->server("REMOTE_PORT"), 0, 16);
}
- $visible_change = $this->original()->state == "published" || $this->state == "published";
+
+ $visible_change = $this->state == "published";
parent::save();
module::event("comment_created", $this);
} else {
// Updated comment
- $visible_change = $this->original()->state == "published" || $this->state == "published";
- $original = clone $this->original();
+ $original = ORM::factory("comment")->where("id", "=", $this->id)->find();
+ $visible_change = $original->state == "published" || $this->state == "published";
parent::save();
module::event("comment_updated", $original, $this);
}
--
cgit v1.2.3
From 4b32a71afc7650fe7bdd02ba384c8914f60538f3 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Wed, 27 Jan 2010 22:34:11 -0800
Subject: Convert back to using ORM::factory(..., $id) instead of calling
where().
---
modules/comment/models/comment.php | 2 +-
modules/comment/tests/Comment_Event_Test.php | 2 +-
modules/g2_import/controllers/g2.php | 2 +-
modules/g2_import/helpers/g2_import.php | 11 +++++------
modules/gallery/helpers/gallery_installer.php | 2 +-
modules/gallery/helpers/item_rest.php | 2 +-
modules/gallery/libraries/ORM_MPTT.php | 2 +-
modules/gallery/models/item.php | 4 ++--
modules/server_add/controllers/server_add.php | 13 ++++++-------
modules/tag/helpers/item_tags_rest.php | 2 +-
modules/tag/helpers/tag_item_rest.php | 4 ++--
modules/tag/helpers/tag_items_rest.php | 2 +-
modules/tag/helpers/tag_rest.php | 2 +-
modules/user/models/group.php | 2 +-
modules/user/models/user.php | 2 +-
15 files changed, 26 insertions(+), 28 deletions(-)
(limited to 'modules/comment')
diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php
index 43c4148f..8be022b5 100644
--- a/modules/comment/models/comment.php
+++ b/modules/comment/models/comment.php
@@ -108,7 +108,7 @@ class Comment_Model extends ORM {
module::event("comment_created", $this);
} else {
// Updated comment
- $original = ORM::factory("comment")->where("id", "=", $this->id)->find();
+ $original = ORM::factory("comment", $this->id);
$visible_change = $original->state == "published" || $this->state == "published";
parent::save();
module::event("comment_updated", $original, $this);
diff --git a/modules/comment/tests/Comment_Event_Test.php b/modules/comment/tests/Comment_Event_Test.php
index 27272055..08f55b3f 100644
--- a/modules/comment/tests/Comment_Event_Test.php
+++ b/modules/comment/tests/Comment_Event_Test.php
@@ -30,6 +30,6 @@ class Comment_Event_Test extends Gallery_Unit_Test_Case {
$album->delete();
- $this->assert_false(ORM::factory("comment")->where("id", "=", $comment->id)->find()->loaded());
+ $this->assert_false(ORM::factory("comment", $comment->id)->loaded());
}
}
diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php
index 3e002758..5fd4400c 100644
--- a/modules/g2_import/controllers/g2.php
+++ b/modules/g2_import/controllers/g2.php
@@ -50,7 +50,7 @@ class G2_Controller extends Admin_Controller {
throw new Kohana_404_Exception();
}
- $item = ORM::factory("item")->where("id", "=", $g2_map->g3_id)->find();
+ $item = ORM::factory("item", $g2_map->g3_id);
if (!$item->loaded() || !access::can("view", $item)) {
throw new Kohana_404_Exception();
}
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php
index 74164305..fa95e547 100644
--- a/modules/g2_import/helpers/g2_import.php
+++ b/modules/g2_import/helpers/g2_import.php
@@ -358,8 +358,7 @@ class g2_import_Core {
if ($g2_album->getParentId() == null) {
return t("Skipping Gallery 2 root album");
}
- $parent_album =
- ORM::factory("item")->where("id", "=", self::map($g2_album->getParentId()))->find();
+ $parent_album = ORM::factory("item", self::map($g2_album->getParentId()));
$album = ORM::factory("item");
$album->type = "album";
@@ -423,8 +422,8 @@ class g2_import_Core {
}
$item_id = self::map($g2_source->getId());
if ($item_id) {
- $item = ORM::factory("item")->where("id", "=", $item_id)->find();
- $g2_album = ORM::factory("item")->where("id", "=", $g3_album_id)->find();
+ $item = ORM::factory("item", $item_id);
+ $g2_album = ORM::factory("item", $g3_album_id);
$g2_album->album_cover_item_id = $item->id;
$g2_album->thumb_dirty = 1;
$g2_album->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_album_id));
@@ -452,7 +451,7 @@ class g2_import_Core {
array("id" => $g2_item_id, "exception" => (string)$e));
}
- $parent = ORM::factory("item")->where("id", "=", self::map($g2_item->getParentId()))->find();
+ $parent = ORM::factory("item", self::map($g2_item->getParentId()));
$g2_type = $g2_item->getEntityType();
$corrupt = 0;
@@ -633,7 +632,7 @@ class g2_import_Core {
GalleryCoreApi::requireOnce("modules/tags/classes/TagsHelper.class");
$g2_item_id = array_shift($queue);
- $g3_item = ORM::factory("item")->where("id", "=", self::map($g2_item_id))->find();
+ $g3_item = ORM::factory("item", self::map($g2_item_id));
if (!$g3_item->loaded()) {
return;
}
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index aa297236..bfab4645 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -228,7 +228,7 @@ class gallery_installer {
"updated" => $now,
"weight" => 1))
->execute();
- $root = ORM::factory("item")->where("id", "=", 1)->find();
+ $root = ORM::factory("item", 1);
access::add_item($root);
module::set_var("gallery", "active_site_theme", "wind");
diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php
index 2236fbbb..d5ca1456 100644
--- a/modules/gallery/helpers/item_rest.php
+++ b/modules/gallery/helpers/item_rest.php
@@ -145,7 +145,7 @@ class item_rest_Core {
}
static function resolve($id) {
- $item = ORM::factory("item")->where("id", "=", $id)->find();
+ $item = ORM::factory("item", $id);
if (!access::can("view", $item)) {
throw new Kohana_404_Exception();
}
diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php
index a7bb24ea..83f9b51e 100644
--- a/modules/gallery/libraries/ORM_MPTT.php
+++ b/modules/gallery/libraries/ORM_MPTT.php
@@ -48,7 +48,7 @@ class ORM_MPTT_Core extends ORM {
function save() {
if (!$this->loaded()) {
$this->lock();
- $parent = ORM::factory("item")->where("id", "=", $this->parent_id)->find();
+ $parent = ORM::factory("item", $this->parent_id);
try {
// Make a hole in the parent for this new item
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 9706d61f..ae1b6608 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -423,7 +423,7 @@ class Item_Model extends ORM_MPTT {
// If any significant fields have changed, load up a copy of the original item and
// keep it around.
- $original = ORM::factory("item")->where("id", "=", $this->id)->find();
+ $original = ORM::factory("item", $this->id);
if (array_intersect($this->changed, array("parent_id", "name", "slug"))) {
$original->_build_relative_caches();
$this->relative_path_cache = null;
@@ -787,7 +787,7 @@ class Item_Model extends ORM_MPTT {
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();
+ $original = ORM::factory("item", $this->id);
$new_ext = pathinfo($this->name, PATHINFO_EXTENSION);
$old_ext = pathinfo($original->name, PATHINFO_EXTENSION);
if (strcasecmp($new_ext, $old_ext)) {
diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php
index 4d6d5dfe..287855b6 100644
--- a/modules/server_add/controllers/server_add.php
+++ b/modules/server_add/controllers/server_add.php
@@ -24,7 +24,7 @@ class Server_Add_Controller extends Admin_Controller {
$files[] = $path;
}
- $item = ORM::factory("item")->where("id", "=", $id)->find();
+ $item = ORM::factory("item", $id);
$view = new View("server_add_tree_dialog.html");
$view->item = $item;
$view->tree = new View("server_add_tree.html");
@@ -78,7 +78,7 @@ class Server_Add_Controller extends Admin_Controller {
*/
public function start() {
access::verify_csrf();
- $item = ORM::factory("item")->where("id", "=", Input::instance()->get("item_id"))->find();
+ $item = ORM::factory("item", Input::instance()->get("item_id"));
foreach (Input::instance()->post("paths") as $path) {
if (server_add::is_valid_path($path)) {
@@ -104,7 +104,7 @@ class Server_Add_Controller extends Admin_Controller {
function run($task_id) {
access::verify_csrf();
- $task = ORM::factory("task")->where("id", "=", $task_id)->find();
+ $task = ORM::factory("task", $task_id);
if (!$task->loaded() || $task->owner_id != identity::active_user()->id) {
access::forbidden();
}
@@ -216,12 +216,11 @@ class Server_Add_Controller extends Admin_Controller {
// Look up the parent item for this entry. By now it should exist, but if none was
// specified, then this belongs as a child of the current item.
- $parent_entry =
- ORM::factory("server_add_file")->where("id", "=", $entry->parent_id)->find();
+ $parent_entry = ORM::factory("server_add_file", $entry->parent_id);
if (!$parent_entry->loaded()) {
- $parent = ORM::factory("item")->where("id", "=", $task->get("item_id"))->find();
+ $parent = ORM::factory("item", $task->get("item_id"));
} else {
- $parent = ORM::factory("item")->where("id", "=", $parent_entry->item_id)->find();
+ $parent = ORM::factory("item", $parent_entry->item_id);
}
$name = basename($entry->file);
diff --git a/modules/tag/helpers/item_tags_rest.php b/modules/tag/helpers/item_tags_rest.php
index ce814f77..43e2cef0 100644
--- a/modules/tag/helpers/item_tags_rest.php
+++ b/modules/tag/helpers/item_tags_rest.php
@@ -50,7 +50,7 @@ class item_tags_rest_Core {
}
static function resolve($id) {
- $item = ORM::factory("item")->where("id", "=", $id)->find();
+ $item = ORM::factory("item", $id);
if (!access::can("view", $item)) {
throw new Kohana_404_Exception();
}
diff --git a/modules/tag/helpers/tag_item_rest.php b/modules/tag/helpers/tag_item_rest.php
index cd9bb6fe..60d37437 100644
--- a/modules/tag/helpers/tag_item_rest.php
+++ b/modules/tag/helpers/tag_item_rest.php
@@ -35,8 +35,8 @@ class tag_item_rest_Core {
static function resolve($tuple) {
list ($tag_id, $item_id) = split(",", $tuple);
- $tag = ORM::factory("tag")->where("id", "=", $tag_id)->find();
- $item = ORM::factory("item")->where("id", "=", $item_id)->find();
+ $tag = ORM::factory("tag", $tag_id);
+ $item = ORM::factory("item", $item_id);
if (!$tag->loaded() || !$item->loaded() || !$tag->has($item)) {
throw new Kohana_404_Exception();
}
diff --git a/modules/tag/helpers/tag_items_rest.php b/modules/tag/helpers/tag_items_rest.php
index 369a8d83..ef563ac6 100644
--- a/modules/tag/helpers/tag_items_rest.php
+++ b/modules/tag/helpers/tag_items_rest.php
@@ -52,7 +52,7 @@ class tag_items_rest_Core {
}
static function resolve($id) {
- return ORM::factory("tag")->where("id", "=", $id)->find();
+ return ORM::factory("tag", $id);
}
static function url($tag) {
diff --git a/modules/tag/helpers/tag_rest.php b/modules/tag/helpers/tag_rest.php
index 7143daa9..4879cf63 100644
--- a/modules/tag/helpers/tag_rest.php
+++ b/modules/tag/helpers/tag_rest.php
@@ -77,7 +77,7 @@ class tag_rest_Core {
}
static function resolve($id) {
- $tag = ORM::factory("tag")->where("id", "=", $id)->find();
+ $tag = ORM::factory("tag", $id);
if (!$tag->loaded()) {
throw new Kohana_404_Exception();
}
diff --git a/modules/user/models/group.php b/modules/user/models/group.php
index 85114ede..851e72e6 100644
--- a/modules/user/models/group.php
+++ b/modules/user/models/group.php
@@ -55,7 +55,7 @@ class Group_Model extends ORM implements Group_Definition {
module::event("group_created", $this);
} else {
// Updated group
- $original = ORM::factory("group")->where("id", "=", $this->id)->find();
+ $original = ORM::factory("group", $this->id);
parent::save();
module::event("group_updated", $original, $this);
}
diff --git a/modules/user/models/user.php b/modules/user/models/user.php
index 7c97bae7..78c31047 100644
--- a/modules/user/models/user.php
+++ b/modules/user/models/user.php
@@ -99,7 +99,7 @@ class User_Model extends ORM implements User_Definition {
module::event("user_created", $this);
} else {
// Updated user
- $original = ORM::factory("user")->where("id", "=", $this->id)->find();
+ $original = ORM::factory("user", $this->id);
parent::save();
module::event("user_updated", $original, $this);
}
--
cgit v1.2.3
From 31e4c217194f8d938c8a6963449d42007663f473 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Wed, 27 Jan 2010 23:03:47 -0800
Subject: Localize error messages.
---
modules/comment/helpers/comment.php | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
(limited to 'modules/comment')
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php
index 389c8922..c9c20879 100644
--- a/modules/comment/helpers/comment.php
+++ b/modules/comment/helpers/comment.php
@@ -27,10 +27,20 @@ class comment_Core {
static function get_add_form($item) {
$form = new Forge("comments/create/{$item->id}", "", "post", array("id" => "g-comment-form"));
$group = $form->group("add_comment")->label(t("Add comment"));
- $group->input("name") ->label(t("Name")) ->id("g-author");
- $group->input("email") ->label(t("Email (hidden)")) ->id("g-email");
- $group->input("url") ->label(t("Website (hidden)"))->id("g-url");
- $group->textarea("text")->label(t("Comment")) ->id("g-text");
+ $group->input("name")
+ ->label(t("Name"))
+ ->id("g-author")
+ ->error_messages("required", t("You must enter a name for yourself"));
+ $group->input("email")
+ ->label(t("Email (hidden)"))
+ ->id("g-email");
+ $group->input("url")
+ ->label(t("Website (hidden)"))
+ ->id("g-url");
+ $group->textarea("text")
+ ->label(t("Comment"))
+ ->id("g-text")
+ ->error_messages("required", t("You must enter a comment"));
$group->hidden("item_id")->value($item->id);
module::event("comment_add_form", $form);
$group->submit("")->value(t("Add"))->class("ui-state-default ui-corner-all");
--
cgit v1.2.3
From bbe70119ef99e77a57dbc5354bc348c7adaece46 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Wed, 27 Jan 2010 23:05:57 -0800
Subject: Localize validation messages.
---
modules/comment/helpers/comment.php | 3 ---
modules/gallery/helpers/movie.php | 12 +++++++++---
2 files changed, 9 insertions(+), 6 deletions(-)
(limited to 'modules/comment')
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php
index c9c20879..f710ad92 100644
--- a/modules/comment/helpers/comment.php
+++ b/modules/comment/helpers/comment.php
@@ -50,10 +50,7 @@ class comment_Core {
$group->inputs["name"]->value($active->full_name)->disabled("disabled");
$group->email->value($active->email)->disabled("disabled");
$group->url->value($active->url)->disabled("disabled");
- } else {
- $group->inputs["name"]->error_messages("missing", t("You must provide a name"));
}
- $group->text->error_messages("missing", t("You must provide a comment"));
return $form;
}
diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php
index b07a9e69..7033b7da 100644
--- a/modules/gallery/helpers/movie.php
+++ b/modules/gallery/helpers/movie.php
@@ -28,20 +28,26 @@ class movie_Core {
$form = new Forge("movies/update/$movie->id", "", "post", array("id" => "g-edit-movie-form"));
$form->hidden("from_id");
$group = $form->group("edit_item")->label(t("Edit Movie"));
- $group->input("title")->label(t("Title"))->value($movie->title);
+ $group->input("title")->label(t("Title"))->value($movie->title)
+ ->error_messages("required", t("You must provide a title"))
+ ->error_messages("length", t("Your title is too long"));
$group->textarea("description")->label(t("Description"))->value($movie->description);
$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 \"/\""))
->error_messages("no_trailing_period", t("The movie name can't end in \".\""))
- ->error_messages("illegal_extension", t("You cannot change the filename extension"));
+ ->error_messages("illegal_data_file_extension", t("You cannot change the movie file extension"))
+ ->error_messages("required", t("You must provide a movie file name"))
+ ->error_messages("length", t("Your movie file name is too long"));
$group->input("slug")->label(t("Internet Address"))->value($movie->slug)
->error_messages(
"conflict", t("There is already a movie, photo or album with this internet address"))
->error_messages(
"not_url_safe",
- t("The internet address should contain only letters, numbers, hyphens and underscores"));
+ t("The internet address should contain only letters, numbers, hyphens and underscores"))
+ ->error_messages("required", t("You must provide an internet address"))
+ ->error_messages("length", t("Your internet address is too long"));
module::event("item_edit_form", $movie, $form);
--
cgit v1.2.3
From f943a2deefa822544ef737e579649c6437dc3450 Mon Sep 17 00:00:00 2001
From: Tim Almdal
Date: Thu, 28 Jan 2010 08:14:33 -0800
Subject: Don't show a link to the user profile for the guest user
---
modules/comment/views/admin_block_recent_comments.html.php | 6 ++++++
modules/comment/views/comment.html.php | 6 ++++++
modules/comment/views/comments.html.php | 6 ++++++
modules/gallery/views/admin_block_log_entries.html.php | 4 ++++
4 files changed, 22 insertions(+)
(limited to 'modules/comment')
diff --git a/modules/comment/views/admin_block_recent_comments.html.php b/modules/comment/views/admin_block_recent_comments.html.php
index 99f72a30..4017e4f9 100644
--- a/modules/comment/views/admin_block_recent_comments.html.php
+++ b/modules/comment/views/admin_block_recent_comments.html.php
@@ -8,10 +8,16 @@
width="32"
height="32" />
= gallery::date_time($comment->created) ?>
+ if ($comment->author()->guest): ?>
+ = t('%author_name said %comment_text',
+ array("author_name" => html::clean($comment->author_name()),
+ "comment_text" => text::limit_words(nl2br(html::purify($comment->text)), 50))); ?>
+ else: ?>
= t('%author_name said %comment_text',
array("author_name" => html::clean($comment->author_name()),
"url" => user_profile::url($comment->author_id),
"comment_text" => text::limit_words(nl2br(html::purify($comment->text)), 50))); ?>
+ endif ?>
endforeach ?>
diff --git a/modules/comment/views/comment.html.php b/modules/comment/views/comment.html.php
index c4cf1ce0..263e5f97 100644
--- a/modules/comment/views/comment.html.php
+++ b/modules/comment/views/comment.html.php
@@ -8,10 +8,16 @@
width="40"
height="40" />
+ if ($comment->author()->guest): ?>
+ = t("on %date_time, %name said",
+ array("date_time" => gallery::date_time($comment->created),
+ "name" => html::clean($comment->author_name()))) ?>
+ else: ?>
= t("on %date_time, %name said",
array("date_time" => gallery::date_time($comment->created),
"url" => user_profile::url($comment->author_id),
"name" => html::clean($comment->author_name()))) ?>
+ endif ?>
= nl2br(html::purify($comment->text)) ?>
diff --git a/modules/comment/views/comments.html.php b/modules/comment/views/comments.html.php
index c8236997..0ed07c22 100644
--- a/modules/comment/views/comments.html.php
+++ b/modules/comment/views/comments.html.php
@@ -22,10 +22,16 @@
width="40"
height="40" />
+ if ($comment->author()->guest): ?>
+ = t('on %date %name said',
+ array("date" => date("Y-M-d H:i:s", $comment->created),
+ "name" => html::clean($comment->author_name()))); ?>
+ else: ?>
= t('on %date
%name said',
array("date" => date("Y-M-d H:i:s", $comment->created),
"url" => user_profile::url($comment->author_id),
"name" => html::clean($comment->author_name()))); ?>
+ endif ?>
= nl2br(html::purify($comment->text)) ?>
diff --git a/modules/gallery/views/admin_block_log_entries.html.php b/modules/gallery/views/admin_block_log_entries.html.php
index 453724cb..5a8ed23c 100644
--- a/modules/gallery/views/admin_block_log_entries.html.php
+++ b/modules/gallery/views/admin_block_log_entries.html.php
@@ -2,7 +2,11 @@
foreach ($entries as $entry): ?>
-
+ if ($entry->user->guest): ?>
+ = html::clean($entry->user->name) ?>
+ else: ?>
= html::clean($entry->user->name) ?>
+ endif ?>
= gallery::date_time($entry->timestamp) ?>
= $entry->message ?>
= $entry->html ?>
--
cgit v1.2.3
From c4e360431564627003e4c7864b5dd5a07297e91e Mon Sep 17 00:00:00 2001
From: Tim Almdal
Date: Fri, 29 Jan 2010 14:04:27 -0800
Subject: Strongly type the argument list to the model::validate method.
---
modules/comment/models/comment.php | 2 +-
modules/gallery/models/item.php | 2 +-
modules/user/models/group.php | 2 +-
modules/user/models/user.php | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
(limited to 'modules/comment')
diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php
index 8be022b5..add15ce8 100644
--- a/modules/comment/models/comment.php
+++ b/modules/comment/models/comment.php
@@ -56,7 +56,7 @@ class Comment_Model extends ORM {
/**
* Add some custom per-instance rules.
*/
- public function validate($array=null) {
+ public function validate(Validation $array=null) {
// validate() is recursive, only modify the rules on the outermost call.
if (!$array) {
$this->rules = array(
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index ae1b6608..ae6e4cc9 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -720,7 +720,7 @@ class Item_Model extends ORM_MPTT {
/**
* Specify our rules here so that we have access to the instance of this model.
*/
- public function validate($array=null) {
+ public function validate(Validation $array=null) {
if (!$array) {
$this->rules = array(
"album_cover_item_id" => array("callbacks" => array(array($this, "valid_album_cover"))),
diff --git a/modules/user/models/group.php b/modules/user/models/group.php
index 851e72e6..82843ad1 100644
--- a/modules/user/models/group.php
+++ b/modules/user/models/group.php
@@ -37,7 +37,7 @@ class Group_Model extends ORM implements Group_Definition {
/**
* Specify our rules here so that we have access to the instance of this model.
*/
- public function validate($array=null) {
+ public function validate(Validation $array=null) {
// validate() is recursive, only modify the rules on the outermost call.
if (!$array) {
$this->rules = array(
diff --git a/modules/user/models/user.php b/modules/user/models/user.php
index 78c31047..0cd634ea 100644
--- a/modules/user/models/user.php
+++ b/modules/user/models/user.php
@@ -62,7 +62,7 @@ class User_Model extends ORM implements User_Definition {
/**
* Specify our rules here so that we have access to the instance of this model.
*/
- public function validate($array=null) {
+ public function validate(Validation $array=null) {
// validate() is recursive, only modify the rules on the outermost call.
if (!$array) {
$this->rules = 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/comment')
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 @@
= t("Import") ?>
-
- = t("Gallery version %version detected", array("version" => g2_import::version())) ?>
+ = t("Gallery version %version detected", array("version" => $version)) ?>
if ($g2_sizes["thumb"]["size"] && $thumb_size != $g2_sizes["thumb"]["size"]): ?>
-
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