Skip to content

Commit 048cc4b

Browse files
committed
Tests: Cover default comment status options and filtering.
Cover closed default options and distinct comment and ping defaults for a supported custom post type. Verify that the `get_default_comment_status` filter receives its arguments and changes the returned value. Developed in: #15151 Props shailu25. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@65099 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 71183db commit 048cc4b

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Tests for get_default_comment_status().
4+
*
5+
* @group comment
6+
*
7+
* @covers ::get_default_comment_status
8+
*/
9+
class Tests_Comment_GetDefaultCommentStatus extends WP_UnitTestCase {
10+
11+
/**
12+
* @ticket 65819
13+
*/
14+
public function test_posts_use_closed_default_comment_status_option() {
15+
update_option( 'default_comment_status', 'closed' );
16+
17+
$this->assertSame( 'closed', get_default_comment_status( 'post' ) );
18+
$this->assertSame( 'closed', get_default_comment_status() );
19+
}
20+
21+
/**
22+
* @ticket 65819
23+
*/
24+
public function test_posts_use_closed_default_ping_status_option() {
25+
update_option( 'default_ping_status', 'closed' );
26+
27+
$this->assertSame( 'closed', get_default_comment_status( 'post', 'pingback' ) );
28+
}
29+
30+
/**
31+
* @ticket 65819
32+
*/
33+
public function test_supported_custom_post_type_uses_opposed_comment_and_ping_options() {
34+
register_post_type(
35+
'with_comments_cpt',
36+
array(
37+
'public' => true,
38+
'supports' => array( 'comments', 'trackbacks' ),
39+
)
40+
);
41+
42+
update_option( 'default_comment_status', 'open' );
43+
update_option( 'default_ping_status', 'closed' );
44+
45+
$this->assertSame( 'open', get_default_comment_status( 'with_comments_cpt' ) );
46+
$this->assertSame( 'closed', get_default_comment_status( 'with_comments_cpt', 'trackback' ) );
47+
}
48+
49+
/**
50+
* @ticket 65819
51+
*/
52+
public function test_filter_receives_status_post_type_and_comment_type() {
53+
$filter = new MockAction();
54+
add_filter( 'get_default_comment_status', array( $filter, 'filter_append' ), 10, 3 );
55+
56+
update_option( 'default_comment_status', 'open' );
57+
58+
$result = get_default_comment_status( 'post', 'comment' );
59+
60+
$this->assertSame( 'open_append', $result );
61+
$this->assertSame( 1, $filter->get_call_count() );
62+
$this->assertSame( array( 'open', 'post', 'comment' ), $filter->get_args()[0] );
63+
}
64+
}

0 commit comments

Comments
 (0)