Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default_comment_status to closed #1110

Merged
merged 8 commits into from Sep 22, 2022
2 changes: 1 addition & 1 deletion src/wp-admin/includes/schema.php
Expand Up @@ -412,7 +412,7 @@ function populate_options() {
'mailserver_pass' => 'password',
'mailserver_port' => 110,
'default_category' => 1,
'default_comment_status' => 'open',
'default_comment_status' => 'closed',
'default_ping_status' => 'open',
'default_pingback_flag' => 1,
'posts_per_page' => 10,
Expand Down
8 changes: 7 additions & 1 deletion tests/phpunit/tests/comment-submission.php
Expand Up @@ -7,9 +7,15 @@ class Tests_Comment_Submission extends WP_UnitTestCase {

protected $preprocess_comment_data = array();

function setUp() {
public function setUp() {
parent::setUp();
require_once ABSPATH . WPINC . '/class-phpass.php';
update_option( 'default_comment_status', 'open' );
}

public function tearDown() {
update_option( 'default_comment_status', 'closed' );
parent::tearDown();
}

public function test_submitting_comment_to_invalid_post_returns_error() {
Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/tests/comment.php
Expand Up @@ -10,6 +10,12 @@ class Tests_Comment extends WP_UnitTestCase {
public function setUp() {
parent::setUp();
reset_phpmailer_instance();
update_option( 'default_comment_status', 'open' );
}

public function tearDown() {
update_option( 'default_comment_status', 'closed' );
parent::tearDown();
}

public static function wpSetUpBeforeClass( $factory ) {
Expand Down
10 changes: 10 additions & 0 deletions tests/phpunit/tests/comment/commentForm.php
Expand Up @@ -4,6 +4,16 @@
* @group comment
*/
class Tests_Comment_CommentForm extends WP_UnitTestCase {
public function setUp() {
parent::setUp();
update_option( 'default_comment_status', 'open' );
}

public function tearDown() {
update_option( 'default_comment_status', 'closed' );
parent::tearDown();
}

public function test_default_markup_for_submit_button_and_wrapper() {
$p = self::factory()->post->create();

Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/tests/feed/rss2.php
Expand Up @@ -18,6 +18,8 @@ class Tests_Feeds_RSS2 extends WP_UnitTestCase {
* Setup a new user and attribute some posts.
*/
public static function wpSetUpBeforeClass( $factory ) {
update_option( 'default_comment_status', 'open' );

// Create a user
self::$user_id = $factory->user->create(
array(
Expand Down Expand Up @@ -57,6 +59,10 @@ public static function wpSetUpBeforeClass( $factory ) {
}
}

public static function wpTearDownAfterClass() {
update_option( 'default_comment_status', 'closed' );
}

/**
* Setup.
*/
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/tests/post.php
Expand Up @@ -1043,7 +1043,7 @@ function test_wp_insert_post_default_comment_ping_status_open() {
);
$post = get_post( $post_id );

$this->assertEquals( 'open', $post->comment_status );
$this->assertEquals( 'closed', $post->comment_status );
$this->assertEquals( 'open', $post->ping_status );
}

Expand All @@ -1069,7 +1069,7 @@ function test_wp_insert_post_page_default_comment_ping_status_closed() {
/**
* @see https://core.trac.wordpress.org/ticket/31168
*/
function test_wp_insert_post_cpt_default_comment_ping_status_open() {
function test_wp_insert_post_cpt_default_comment_ping_status() {
$post_type = rand_str( 20 );
register_post_type( $post_type, array( 'supports' => array( 'comments', 'trackbacks' ) ) );
$post_id = self::factory()->post->create(
Expand All @@ -1083,7 +1083,7 @@ function test_wp_insert_post_cpt_default_comment_ping_status_open() {
);
$post = get_post( $post_id );

$this->assertEquals( 'open', $post->comment_status );
$this->assertEquals( 'closed', $post->comment_status );
$this->assertEquals( 'open', $post->ping_status );
_unregister_post_type( $post_type );
}
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/rest-api.php
Expand Up @@ -16,11 +16,13 @@ class Tests_REST_API extends WP_UnitTestCase {
public function setUp() {
// Override the normal server with our spying server.
$GLOBALS['wp_rest_server'] = new Spy_REST_Server();
update_option( 'default_comment_status', 'open' );
parent::setUp();
}

public function tearDown() {
remove_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) );
update_option( 'default_comment_status', 'closed' );
parent::tearDown();
}

Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/rest-api/rest-comments-controller.php
Expand Up @@ -27,6 +27,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
protected $endpoint;

public static function wpSetUpBeforeClass( $factory ) {
update_option( 'default_comment_status', 'open' );
self::$superadmin_id = $factory->user->create(
array(
'role' => 'administrator',
Expand Down Expand Up @@ -111,6 +112,8 @@ public static function wpTearDownAfterClass() {
wp_delete_post( self::$trash_id, true );
wp_delete_post( self::$approved_id, true );
wp_delete_post( self::$hold_id, true );

update_option( 'default_comment_status', 'closed' );
}

public function setUp() {
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/rest-api/rest-schema-setup.php
Expand Up @@ -22,6 +22,7 @@ public function setUp() {
global $wp_rest_server;
$this->server = $wp_rest_server = new Spy_REST_Server;
do_action( 'rest_api_init' );
update_option( 'default_comment_status', 'open' );

add_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 );
}
Expand All @@ -33,6 +34,8 @@ public function tearDown() {
global $wp_rest_server;
$wp_rest_server = null;

update_option( 'default_comment_status', 'closed' );

remove_filter( 'pre_http_request', array( $this, 'mock_embed_request' ), 10, 3 );
}

Expand Down
11 changes: 9 additions & 2 deletions tests/phpunit/tests/schema.php
Expand Up @@ -8,7 +8,14 @@ class Tests_Schema extends WP_UnitTestCase {
public function test_default_avatar_option() {
$setting = get_option( 'show_avatars' );

$this->assertEquals( '0', $setting );
$this->assertNotEquals( '1', $setting );
$this->assertSame( '0', $setting );
$this->assertNotSame( '1', $setting );
}

public function test_comments_off_by_default() {
$setting = get_option( 'default_comment_status' );

$this->assertSame( 'closed', $setting );
$this->assertNotSame( 'open', $setting );
}
}
9 changes: 9 additions & 0 deletions tests/phpunit/tests/xmlrpc/wp/newComment.php
Expand Up @@ -4,6 +4,15 @@
* @group xmlrpc
*/
class Tests_XMLRPC_wp_newComment extends WP_XMLRPC_UnitTestCase {
public function setUp() {
parent::setUp();
update_option( 'default_comment_status', 'open' );
}

public function tearDown() {
update_option( 'default_comment_status', 'closed' );
parent::tearDown();
}

function test_valid_comment() {
$this->make_user_by_role( 'administrator' );
Expand Down