1 | Index: tests/comment/query.php |
---|
2 | =================================================================== |
---|
3 | --- tests/comment/query.php (revision 1326) |
---|
4 | +++ tests/comment/query.php (working copy) |
---|
5 | @@ -25,7 +25,8 @@ |
---|
6 | * @ticket 21101 |
---|
7 | */ |
---|
8 | function test_get_comment_comment_approved_1() { |
---|
9 | - $comment_id = $this->factory->comment->create(); |
---|
10 | + $comment_args = array( 'comment_post_ID' => $this->factory->post->create() ); |
---|
11 | + $comment_id = $this->factory->comment->create( $comment_args ); |
---|
12 | $comments_approved_1 = get_comments( array( 'status' => 'approve' ) ); |
---|
13 | |
---|
14 | $this->assertEquals( 1, count( $comments_approved_1 ) ); |
---|
15 | @@ -80,9 +81,10 @@ |
---|
16 | * @ticket 21003 |
---|
17 | */ |
---|
18 | function test_orderby_meta() { |
---|
19 | - $comment_id = $this->factory->comment->create(); |
---|
20 | - $comment_id2 = $this->factory->comment->create(); |
---|
21 | - $comment_id3 = $this->factory->comment->create(); |
---|
22 | + $comment_args = array( 'comment_post_ID' => $this->factory->post->create() ); |
---|
23 | + $comment_id = $this->factory->comment->create( $comment_args ); |
---|
24 | + $comment_id2 = $this->factory->comment->create( $comment_args ); |
---|
25 | + $comment_id3 = $this->factory->comment->create( $comment_args ); |
---|
26 | |
---|
27 | add_comment_meta( $comment_id, 'key', 'value1', true ); |
---|
28 | add_comment_meta( $comment_id, 'key1', 'value1', true ); |
---|
29 | @@ -153,4 +155,36 @@ |
---|
30 | $this->assertEquals( 10, count( get_comments( array( 'status' => 'trash' ) ) ) ); |
---|
31 | $this->assertEquals( 10, count( get_comments( array( 'status' => 'spam' ) ) ) ); |
---|
32 | } |
---|
33 | + |
---|
34 | + /** |
---|
35 | + * Ticket @23931 |
---|
36 | + */ |
---|
37 | + function test_wp_insert_comment_data_filter() { |
---|
38 | + $comment_args = array( |
---|
39 | + 'comment_post_ID' => $this->factory->post->create(), |
---|
40 | + 'comment_content' => 'not-filtered', |
---|
41 | + ); |
---|
42 | + $filter = function ( $comment_data ) { |
---|
43 | + $comment_data['comment_content'] = 'filtered'; |
---|
44 | + return $comment_data; |
---|
45 | + }; |
---|
46 | + add_filter( 'wp_insert_comment_data', $filter ); |
---|
47 | + $comment_id = $this->factory->comment->create( $comment_args ); |
---|
48 | + remove_filter( 'wp_insert_comment_data', $filter ); |
---|
49 | + $comment = get_comment( $comment_id ); |
---|
50 | + $this->assertEquals( 'filtered', $comment->comment_content ); |
---|
51 | + } |
---|
52 | + |
---|
53 | + /** |
---|
54 | + * Ticket @23931 |
---|
55 | + */ |
---|
56 | + function test_error_when_not_supplying_comment_post_id() { |
---|
57 | + $r = $this->factory->comment->create( array() ); |
---|
58 | + $this->assertInstanceOf( 'WP_Error', $r ); |
---|
59 | + $this->assertEquals( 'invalid_comment_post_id', $r->get_error_code() ); |
---|
60 | + |
---|
61 | + $post_id = $this->factory->post->create(); |
---|
62 | + $r = $this->factory->comment->create( array( 'comment_post_ID' => $post_id ) ); |
---|
63 | + $this->assertInternalType( 'int', $r ); |
---|
64 | + } |
---|
65 | } |
---|