Make WordPress Core

Ticket #31108: 31108.patch

File 31108.patch, 3.7 KB (added by rachelbaker, 11 years ago)

Separated out the tests and made minor formatting adjustments.

  • tests/phpunit/tests/comment.php

     
    148148                        unset( $_SERVER['REMOTE_ADDR'] );
    149149                }
    150150        }
     151
     152        public function test_check_comment() {
     153                $author       = 'BobtheBuilder';
     154                $author_email = 'bob@example.com';
     155                $author_url   = 'http://example.com';
     156                $comment      = 'Can we fix it? Yes, we can (thanks to Wendy).';
     157                $author_ip    = '192.168.0.1';
     158                $user_agent   = '';
     159                $comment_type = '';
     160
     161                update_option( 'comment_whitelist', 0 );
     162                $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type );
     163                $this->assertTrue( $results );
     164
     165                update_option( 'comment_whitelist', 1 );
     166                $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type );
     167                $this->assertFalse( $results );
     168        }
     169
     170        public function test_check_comment_previously_approved() {
     171                $post_id = $this->factory->post->create();
     172                $prev_args = array(
     173                        'comment_post_ID'      => $post_id,
     174                        'comment_content'      => 'Can we build it?',
     175                        'comment_approved'     => 0,
     176                        'comment_author_email' => 'bob@example.com',
     177                        'comment_author'       => 'BobtheBuilder',
     178                );
     179                $prev_comment_id = $this->factory->comment->create( $prev_args );
     180
     181                $author       = 'BobtheBuilder';
     182                $author_email = 'bob@example.com';
     183                $author_url   = 'http://example.com';
     184                $comment      = 'Can we fix it? Yes, we can (thanks to Wendy).';
     185                $author_ip    = '192.168.0.1';
     186                $user_agent   = '';
     187                $comment_type = '';
     188
     189                $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type );
     190                $this->assertFalse( $results );
     191
     192                // Approve the previous comment.
     193                wp_update_comment( array(
     194                        'comment_ID'       => $prev_comment_id,
     195                        'comment_approved' => 1,
     196                ) );
     197                $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type );
     198                $this->assertTrue( $results );
     199        }
     200
     201        public function test_check_comment_moderation_keys() {
     202                $author       = 'WendytheBuilder';
     203                $author_email = 'wendy@example.com';
     204                $author_url   = 'http://example.com';
     205                $comment      = 'Has anyone seen Scoop?';
     206                $author_ip    = '192.168.0.1';
     207                $user_agent   = '';
     208                $comment_type = '';
     209
     210                update_option( 'comment_whitelist', 0 );
     211
     212                update_option( 'moderation_keys',"poop\nhiney\nscoop" );
     213                $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type );
     214                $this->assertFalse( $results );
     215
     216                update_option( 'moderation_keys',"poop\nhiney\n" );
     217                $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type );
     218                $this->assertTrue( $results );
     219        }
     220
     221        public function test_check_comment_max_links() {
     222                $author       = 'BobtheBuilder';
     223                $author_email = 'bob@example.com';
     224                $author_url   = 'http://example.com';
     225                $comment      = 'This is a comment with <a href="http://example.com">multiple</a> <a href="http://bob.example.com">links</a>.';
     226                $author_ip    = '192.168.0.1';
     227                $user_agent   = '';
     228                $comment_type = '';
     229
     230                update_option( 'comment_whitelist', 0 );
     231
     232                update_option( 'comment_max_links', 2 );
     233                $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type );
     234                $this->assertFalse( $results );
     235
     236                update_option( 'comment_max_links', 3 );
     237                $results = check_comment( $author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type );
     238                $this->assertTrue( $results );
     239        }
    151240}