summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/comment/controllers/comments.php2
-rw-r--r--modules/comment/helpers/comment.php6
-rw-r--r--modules/comment/helpers/comment_block.php2
-rw-r--r--modules/comment/helpers/comment_installer.php12
-rw-r--r--modules/comment/tests/Comment_Helper_Test.php33
5 files changed, 46 insertions, 9 deletions
diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php
index 293c456d..cb2ebb01 100644
--- a/modules/comment/controllers/comments.php
+++ b/modules/comment/controllers/comments.php
@@ -69,7 +69,7 @@ class Comments_Controller extends REST_Controller {
print json_encode(
array("result" => "success",
- "resource" => $comment->visible ? url::site("comments/{$comment->id}") : NULL,
+ "resource" => $comment->published ? url::site("comments/{$comment->id}") : NULL,
"form" => comment::get_add_form($item)->__toString()));
} else {
print json_encode(
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php
index 92a9e54c..d6c3bd48 100644
--- a/modules/comment/helpers/comment.php
+++ b/modules/comment/helpers/comment.php
@@ -46,13 +46,15 @@ class comment_Core {
$comment->text = $text;
$comment->item_id = $item_id;
$comment->url = $url;
+ $comment->ip_addr = Input::instance()->ip_address();
+ $comment->user_agent = Kohana::$user_agent;
$comment->created = time();
// @todo Figure out how to mock up the test of the spam_filter
if (module::is_installed("spam_filter") && !TEST_MODE) {
spam_filter::verify_comment($comment);
} else {
- $comment->visible = true;
+ $comment->published = true;
}
$comment->save();
@@ -75,6 +77,8 @@ class comment_Core {
$comment->email = $email;
$comment->text = $text;
$comment->url = $url;
+ $comment->ip_addr = Input::instance()->ip_address();
+ $comment->user_agent = Kohana::$user_agent;
// @todo Figure out how to mock up the test of the spam_filter
if (module::is_installed("spam_filter") && !TEST_MODE) {
diff --git a/modules/comment/helpers/comment_block.php b/modules/comment/helpers/comment_block.php
index 9231dcd6..ce748036 100644
--- a/modules/comment/helpers/comment_block.php
+++ b/modules/comment/helpers/comment_block.php
@@ -32,7 +32,7 @@ class comment_block_Core {
$view = new View("comments.html");
$view->comments = ORM::factory("comment")
->where("item_id", $theme->item()->id)
- ->where("visible", 1)
+ ->where("published", 1)
->orderby("created", "ASC")
->find_all();
diff --git a/modules/comment/helpers/comment_installer.php b/modules/comment/helpers/comment_installer.php
index f203d940..71b047e5 100644
--- a/modules/comment/helpers/comment_installer.php
+++ b/modules/comment/helpers/comment_installer.php
@@ -31,14 +31,14 @@ class comment_installer {
`created` int(9) NOT NULL,
`item_id` int(9) NOT NULL,
`url` varchar(255) default NULL,
- `visible` tinyint(1) default 1,
- PRIMARY KEY (`id`))
+ `published` tinyint(1) default 1,
+ `ip_addr` char(15) default NULL,
+ `user_agent` varchar(255) default NULL,
+ `spam_signature` varchar(255) default NULL,
+ `spam_type` char(15) default NULL,
+ PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- if (module::is_installed("spam_filter")) {
- spam_filter_installer::add_fields();
- }
-
module::set_version("comment", 1);
}
}
diff --git a/modules/comment/tests/Comment_Helper_Test.php b/modules/comment/tests/Comment_Helper_Test.php
index 81ec12a8..10903843 100644
--- a/modules/comment/tests/Comment_Helper_Test.php
+++ b/modules/comment/tests/Comment_Helper_Test.php
@@ -18,8 +18,25 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Comment_Helper_Test extends Unit_Test_Case {
+ private $_ip_address;
+ private $_user_agent;
+
+ public function setup() {
+ $this->_ip_address = Input::instance()->ip_address;
+ $this->_user_agent = Kohana::$user_agent;
+ }
+
+ public function teardown() {
+ Input::instance()->ip_address = $this->_ip_address;
+ Kohana::$user_agent = $this->_user_agent;
+ }
+
public function create_comment_test() {
$rand = rand();
+
+ Input::instance()->ip_address = "1.1.1.1";
+ Kohana::$user_agent = "Gallery3 Unit Test";
+
$comment = comment::create($rand, $rand, $rand, $rand, $rand, $rand);
$this->assert_equal($rand, $comment->author);
@@ -27,11 +44,15 @@ class Comment_Helper_Test extends Unit_Test_Case {
$this->assert_equal($rand, $comment->text);
$this->assert_equal($rand, $comment->item_id);
$this->assert_equal($rand, $comment->url);
+ $this->assert_equal("1.1.1.1", $comment->ip_addr);
+ $this->assert_equal("Gallery3 Unit Test", $comment->user_agent);
$this->assert_true(!empty($comment->created));
}
public function update_comment_test() {
$rand = rand();
+ Input::instance()->ip_address = "1.1.1.1";
+ Kohana::$user_agent = "Gallery3 Unit Test";
$comment = comment::create($rand, $rand, $rand, $rand, $rand, $rand);
$this->assert_equal($rand, $comment->author);
@@ -39,19 +60,27 @@ class Comment_Helper_Test extends Unit_Test_Case {
$this->assert_equal($rand, $comment->text);
$this->assert_equal($rand, $comment->item_id);
$this->assert_equal($rand, $comment->url);
+ $this->assert_equal("1.1.1.1", $comment->ip_addr);
+ $this->assert_equal("Gallery3 Unit Test", $comment->user_agent);
$this->assert_true(!empty($comment->created));
$rand2 = rand();
+ Input::instance()->ip_address = "1.1.1.2";
+ Kohana::$user_agent = "Gallery3 Unit Test New Agent";
comment::update($comment, $rand2, $rand2, $rand2, $rand2, $rand2);
$this->assert_equal($rand2, $comment->author);
$this->assert_equal($rand2, $comment->email);
$this->assert_equal($rand2, $comment->text);
$this->assert_equal($rand, $comment->item_id);
+ $this->assert_equal("1.1.1.2", $comment->ip_addr);
$this->assert_equal($rand2, $comment->url);
+ $this->assert_equal("Gallery3 Unit Test New Agent", $comment->user_agent);
}
public function update_comment_no_change_test() {
$rand = rand();
+ Input::instance()->ip_address = "1.1.1.1";
+ Kohana::$user_agent = "Gallery3 Unit Test";
$comment = comment::create($rand, $rand, $rand, $rand, $rand, $rand);
$this->assert_equal($rand, $comment->author);
@@ -60,6 +89,8 @@ class Comment_Helper_Test extends Unit_Test_Case {
$this->assert_equal($rand, $comment->item_id);
$this->assert_equal($rand, $comment->url);
$this->assert_true(!empty($comment->created));
+ $this->assert_equal("1.1.1.1", $comment->ip_addr);
+ $this->assert_equal("Gallery3 Unit Test", $comment->user_agent);
comment::update($comment, $rand, $rand, $rand, $rand, $rand);
$this->assert_equal($rand, $comment->author);
@@ -67,5 +98,7 @@ class Comment_Helper_Test extends Unit_Test_Case {
$this->assert_equal($rand, $comment->text);
$this->assert_equal($rand, $comment->item_id);
$this->assert_equal($rand, $comment->url);
+ $this->assert_equal("1.1.1.1", $comment->ip_addr);
+ $this->assert_equal("Gallery3 Unit Test", $comment->user_agent);
}
}