Make WordPress Core

Ticket #31108: tests_phpunit_tests_comment.php.patch

File tests_phpunit_tests_comment.php.patch, 4.3 KB (added by CalEvans, 11 years ago)
  • tests/phpunit/tests/comment.php

     
    7272
    7373                $this->assertSame( array(), $found );
    7474        }
     75
     76    public function test_check_comment() {
     77        /*
     78         * Setup
     79         */
     80        global $wpdb;
     81        $post_args = array( 'post_title' => 'some-post', 'post_type' => 'post' );
     82        $post      = $this->factory->post->create_and_get( $post_args );
     83        $comment_args = array( 'comment_post_ID'      => $post->ID,
     84                               'comment_approved'     => '0',
     85                               'comment_content'      => 'This is a test comment.' ,
     86                               'comment_approved'     =>0,
     87                               'comment_author_email' => 'bob@example.com',
     88                               'comment_author' => 'BobtheBuilder' );
     89
     90
     91        /*
     92         *  Test #1 Comment Whitelisting
     93         */
     94        update_option('comment_whitelist',0);
     95        $results = check_comment('BobtheBuilder', 'bob@example.com', 'http://example.com', 'This is a test comment.' , '192.168.0.1', '', '');
     96        $this->assertTrue($results);
     97        update_option('comment_whitelist',1);
     98        $results = check_comment('BobtheBuilder', 'bob@example.com', 'http://example.com', 'This is a test comment.' , '192.168.0.1', '', '');
     99        $this->assertFalse($results);
     100
     101
     102        /*
     103         * Test 2: Must have at least 2 approved comments
     104         */
     105        $comment_args['comment_approved'] = 1;
     106        $comment_ids = $this->factory->comment->create_post_comments($post->ID,5, $comment_args );
     107        for($lcvA=0;$lcvA<count($comment_ids);$lcvA++) {
     108            $comment = get_comment($comment_ids[$lcvA]);
     109            $comment->comment_approved=0;
     110            wp_update_comment((array)$comment);
     111        }
     112        $results = check_comment('BobtheBuilder', 'bob@example.com', 'http://example.com', 'This is a test comment.' , '192.168.0.1', '', '');
     113        $this->assertFalse($results);
     114
     115        for($lcvA=0;$lcvA<count($comment_ids);$lcvA++) {
     116            $comment = get_comment($comment_ids[$lcvA]);
     117            $comment->comment_approved=1;
     118            wp_update_comment((array)$comment);
     119        }
     120        $results = check_comment('BobtheBuilder', 'bob@example.com', 'http://example.com', 'This is a test comment.' , '192.168.0.1', '', '');
     121        $this->assertTrue($results);
     122       
     123
     124        /*
     125         *  Test #3 Comment Moderation
     126         */
     127        update_option('comment_moderation',1);
     128        $results = check_comment('BobtheBuilder', 'bob@example.com', 'http://example.com', 'This is a test comment.' , '192.168.0.1', '', '');
     129        $this->assertFalse($results);
     130        update_option('comment_moderation',0);
     131        $results = check_comment('BobtheBuilder', 'bob@example.com', 'http://example.com', 'This is a test comment.' , '192.168.0.1', '', '');
     132        $this->assertTrue($results);
     133
     134
     135        /*
     136         * Test #4 Number of comment links
     137         */
     138         $max_links = get_option( 'comment_max_links' );
     139         $comment_content = $comment_args['comment_content'] . "\n";;
     140         for($lcvA=0;$lcvA<$max_links;$lcvA++) {
     141            $comment_content .= '<a href="'.home_url( '?p=' . rand() ) . '">Click Me!</a>' . "\n";
     142         }
     143        $results = check_comment('BobtheBuilder', 'bob@example.com', 'http://example.com', $comment_content , '192.168.0.1', '', '');
     144        $this->assertFalse($results);
     145        update_option('comment_max_links',5);
     146        $results = check_comment('BobtheBuilder', 'bob@example.com', 'http://example.com', $comment_content , '192.168.0.1', '', '');
     147        $this->assertTrue($results);
     148
     149
     150        /*
     151         * Test #5 Moderated keywords
     152         */
     153        update_option('moderation_keys',"poop\nhiney\ncomment");
     154        $results = check_comment('BobtheBuilder', 'bob@example.com', 'http://example.com', 'This is a test comment.' , '192.168.0.1', '', '');
     155        $this->assertFalse($results);
     156        update_option('moderation_keys',"poop\nhiney\n");
     157        $results = check_comment('BobtheBuilder', 'bob@example.com', 'http://example.com', 'This is a test comment.' , '192.168.0.1', '', '');
     158        $this->assertTrue($results);
     159
     160        return;
     161
     162    }
     163
    75164}
     165
     166}