public function testGetPostParametersWithServerFields()
 {
     // fake $_SERVER fields for testing
     $serverFields = array('SCRIPT_URI' => 'http://example.com/akismet-tests', 'HTTP_HOST' => 'example.com', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux) Firefox 3.0.5', 'HTTP_ACCEPT' => 'text/html,application/xml', 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en', 'HTTP_ACCEPT_ENCODING' => 'gzip,deflate', 'HTTP_ACCEPT_CHARSET' => 'utf-8', 'HTTP_KEEP_ALIVE' => '300', 'HTTP_CONNECTION' => 'keep-alive', 'HTTP_CACHE_CONTROL' => 'max-age=0', 'HTTP_PRAGMA' => 'Apache/2.2.9 Server at example.com', 'HTTP_DATE' => 'Wed, 22 Dec 2004 11:34:47 GMT', 'HTTP_EXPECT' => '100-continue', 'HTTP_MAX_FORWARDS' => '10', 'HTTP_RANGE' => '0-134 bytes', 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'CONTENT_LENGTH' => '134', 'SERVER_SIGNATURE' => 'Apache/2.2.9 Server at example.com', 'SERVER_SOFTWARE' => 'Apache/2.2.9 (Fedora)', 'SERVER_NAME' => 'example', 'SERVER_ADDR' => '127.0.0.255', 'SERVER_PORT' => '80', 'REMOTE_PORT' => '34623', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'POST', 'QUERY_STRING' => '', 'REQUEST_URI' => '/web/scripts/akismet-tests.php', 'SCRIPT_NAME' => '/web/scripts/akismet-tests.php', 'REQUEST_TIME' => 1231946955);
     foreach ($serverFields as $name => $value) {
         $_SERVER[$name] = $value;
     }
     $fields = array('comment_author' => 'Test Author', 'comment_author_email' => '*****@*****.**', 'comment_author_url' => 'http://myblog.example.com/', 'comment_content' => 'Hello, World!', 'comment_type' => 'comment', 'permalink' => 'http://example.com/post1', 'user_ip' => '127.0.0.1', 'user_agent' => 'Mozilla/5.0 (Linux) Firefox 3.0.5', 'referrer' => 'http://example.com/');
     $comment = new Services_Akismet2_Comment($fields);
     $parameters = $comment->getPostParameters(true);
     foreach ($fields as $name => $value) {
         $this->assertArrayHasKey($name, $parameters);
         $this->assertEquals($value, $parameters[$name]);
     }
     foreach ($serverFields as $name => $value) {
         $this->assertArrayHasKey($name, $parameters);
         $this->assertEquals($value, $parameters[$name]);
     }
 }
Beispiel #2
0
 /**
  * Submits a false-positive comment to the Akismet server
  *
  * Use this method to submit comments that are detected as spam but are not
  * actually spam.
  *
  * @param Services_Akismet2_Comment|array $comment the comment that is
  *                                                 <em>not</em> spam.
  *
  * @return Services_Akismet2 the Akismet API object.
  *
  * @throws Services_Akismet2_HttpException if there is an error
  *         communicating with the Akismet API server.
  *
  * @throws Services_Akismet2_InvalidCommentException if the specified
  *         comment is missing required fields.
  *
  * @throws Services_Akismet2_InvalidApiKeyException if the provided
  *         API key is not valid.
  *
  * @throws InvalidArgumentException if the provided comment is neither an
  *         array not an instanceof Services_Akismet2_Comment.
  */
 public function submitFalsePositive($comment)
 {
     if (is_array($comment)) {
         $comment = new Services_Akismet2_Comment($comment);
     }
     if (!$comment instanceof Services_Akismet2_Comment) {
         throw new InvalidArgumentException('Comment must be either an ' . 'array or an instance of Services_Akismet2_Comment.');
     }
     $this->validateApiKey();
     $params = $comment->getPostParameters();
     $params['blog'] = $this->blogUri;
     $this->sendRequest('submit-ham', $params, $this->apiKey);
     return $this;
 }