| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @group comment |
| 5 | */ |
| 6 | class Tests_Comment_WpAllowComment extends WP_UnitTestCase { |
| 7 | protected static $post_id; |
| 8 | protected static $comment_id; |
| 9 | |
| 10 | function setUp() { |
| 11 | parent::setUp(); |
| 12 | |
| 13 | self::$post_id = self::factory()->post->create(); |
| 14 | self::$comment_id = self::factory()->comment->create( array( |
| 15 | 'comment_post_ID' => self::$post_id, |
| 16 | 'comment_approved' => '1', |
| 17 | 'comment_author' => 'Bob', |
| 18 | 'comment_author_email' => 'bobthebuilder@example.com', |
| 19 | 'comment_author_url' => 'http://example.com', |
| 20 | 'comment_content' => 'Yes, we can!', |
| 21 | ) ); |
| 22 | |
| 23 | update_option( 'comment_whitelist', 0 ); |
| 24 | } |
| 25 | |
| 26 | function tearDown() { |
| 27 | wp_delete_post( self::$post_id, true ); |
| 28 | wp_delete_comment( self::$comment_id, true ); |
| 29 | } |
| 30 | |
| 31 | public function test_allow_comment_if_comment_author_emails_differ() { |
| 32 | $now = time(); |
| 33 | $comment_data = array( |
| 34 | 'comment_post_ID' => self::$post_id, |
| 35 | 'comment_author' => 'Bob', |
| 36 | 'comment_author_email' => 'sideshowbob@example.com', |
| 37 | 'comment_author_url' => 'http://example.com', |
| 38 | 'comment_content' => 'Yes, we can!', |
| 39 | 'comment_author_IP' => '192.168.0.1', |
| 40 | 'comment_parent' => 0, |
| 41 | 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ), |
| 42 | 'comment_agent' => 'Bobbot/2.1', |
| 43 | 'comment_type' => '', |
| 44 | ); |
| 45 | |
| 46 | $result = wp_allow_comment( $comment_data ); |
| 47 | |
| 48 | $this->assertSame( 1, $result ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @expectedException WPDieException |
| 53 | */ |
| 54 | public function test_die_as_duplicate_if_comment_author_name_and_emails_match() { |
| 55 | $now = time(); |
| 56 | $comment_data = array( |
| 57 | 'comment_post_ID' => self::$post_id, |
| 58 | 'comment_author' => 'Bob', |
| 59 | 'comment_author_email' => 'bobthebuilder@example.com', |
| 60 | 'comment_author_url' => 'http://example.com', |
| 61 | 'comment_content' => 'Yes, we can!', |
| 62 | 'comment_author_IP' => '192.168.0.1', |
| 63 | 'comment_parent' => 0, |
| 64 | 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ), |
| 65 | 'comment_agent' => 'Bobbot/2.1', |
| 66 | 'comment_type' => '', |
| 67 | ); |
| 68 | |
| 69 | $result = wp_allow_comment( $comment_data ); |
| 70 | } |
| 71 | } |