From af3882cd346e48c72a41e370415467f31191a761 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 6 Jan 2009 23:42:20 +0000 Subject: Forgot to add the unit tests, which probably don't work anymore with some of the latest changes. --- modules/spam_filter/tests/Akismet_Driver_Test.php | 112 ++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 modules/spam_filter/tests/Akismet_Driver_Test.php (limited to 'modules') diff --git a/modules/spam_filter/tests/Akismet_Driver_Test.php b/modules/spam_filter/tests/Akismet_Driver_Test.php new file mode 100644 index 00000000..d5f5ee95 --- /dev/null +++ b/modules/spam_filter/tests/Akismet_Driver_Test.php @@ -0,0 +1,112 @@ +_ip_address = Input::instance()->ip_address; + $this->_user_agent = Kohana::$user_agent; + + Input::instance()->ip_address = "1.1.1.1"; + Kohana::$user_agent = "Gallery3 Unit Test"; + + $this->_driver = new Akismet_Driver(); + $this->_comment = comment::create("John Doe", "John@gallery.com", "This is a comment", 0, "http://gallery.com"); + $this->_api_key = module::get_var("spam_filter", "api_key"); + if (empty($this->_api_key)) { + $chars = "0123456789abcdefghijklmnopqrstuvwxyz"; + for ($i = 0; $i < 10; $i++) { + $this->_api_key .= $chars[mt_rand(0, 36)]; + } + module::set_var("spam_filter", "api_key", $this->_api_key); + } + } + + public function teardown() { + Input::instance()->ip_address = $this->_ip_address; + Kohana::$user_agent = $this->_user_agent; + } + + public function build_verify_key_request_test() { + $request = $this->_driver->_build_verify_request($this->_api_key); + $data = "key={$this->_api_key}&blog=http://./"; + $data_length = strlen($data); + $expected = "POST /1.1/verify-key HTTP/1.0\r\n" . + "Host: rest.akismet.com\r\n" . + "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" . + "Content-Length: {$data_length}\r\n" . + "User-Agent: Gallery 3.0 | Akismet/1.11 \r\n" . + "\r\n$data"; + $this->assert_equal($expected, $request); + } + + public function build_check_comment_request_test() { + $request = $this->_driver->_build_request("comment-check", $this->_comment); + $data = "user_ip=1.1.1.1&permalink=http%3A%2F%2F.%2Findex.php%2Fcomments%2F2&blog=http%3A%2F%2F.%2F" . + "&user_agent=Gallery3+Unit+Test&referrer=&comment_type=comment&comment_author=John+Doe" . + "&comment_author_email=John%40gallery.com&comment_author_url=http%3A%2F%2Fgallery.com" . + "&comment_content=This+is+a+comment&"; + $data_length = strlen($data); + $expected = "POST /1.1/comment-check HTTP/1.0\r\n" . + "Host: {$this->_api_key}.rest.akismet.com\r\n" . + "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" . + "Content-Length: {$data_length}\r\n" . + "User-Agent: Gallery 3.0 | Akismet/1.11 \r\n" . + "\r\n$data"; + $this->assert_equal($expected, $request); + } + + public function build_submit_spam_request_test() { + $request = $this->_driver->_build_request("submit-spam", $this->_comment); + $data = "user_ip=1.1.1.1&permalink=http%3A%2F%2F.%2Findex.php%2Fcomments%2F3&blog=http%3A%2F%2F.%2F" . + "&user_agent=Gallery3+Unit+Test&referrer=&comment_type=comment&comment_author=John+Doe" . + "&comment_author_email=John%40gallery.com&comment_author_url=http%3A%2F%2Fgallery.com" . + "&comment_content=This+is+a+comment&"; + $data_length = strlen($data); + $expected = "POST /1.1/submit-spam HTTP/1.0\r\n" . + "Host: {$this->_api_key}.rest.akismet.com\r\n" . + "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" . + "Content-Length: {$data_length}\r\n" . + "User-Agent: Gallery 3.0 | Akismet/1.11 \r\n" . + "\r\n$data"; + $this->assert_equal($expected, $request); + } + + public function build_submit_ham_equest_test() { + $request = $this->_driver->_build_request("submit-ham", $this->_comment); + $data = "user_ip=1.1.1.1&permalink=http%3A%2F%2F.%2Findex.php%2Fcomments%2F4&blog=http%3A%2F%2F.%2F" . + "&user_agent=Gallery3+Unit+Test&referrer=&comment_type=comment&comment_author=John+Doe" . + "&comment_author_email=John%40gallery.com&comment_author_url=http%3A%2F%2Fgallery.com" . + "&comment_content=This+is+a+comment&"; + $data_length = strlen($data); + $expected = "POST /1.1/submit-ham HTTP/1.0\r\n" . + "Host: {$this->_api_key}.rest.akismet.com\r\n" . + "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" . + "Content-Length: {$data_length}\r\n" . + "User-Agent: Gallery 3.0 | Akismet/1.11 \r\n" . + "\r\n$data"; + $this->assert_equal($expected, $request); + } +} + -- cgit v1.2.3