Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wp-admin/includes/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ function populate_options( array $options = array() ) {
'mailserver_port' => 110,
'default_category' => 1,
'default_comment_status' => 'open',
'default_ping_status' => 'open',
'default_pingback_flag' => 1,
'default_ping_status' => 'closed',
'default_pingback_flag' => 0,
'posts_per_page' => 10,
/* translators: Default date format, see https://www.php.net/manual/datetime.format.php */
'date_format' => __( 'F j, Y' ),
Expand Down
149 changes: 149 additions & 0 deletions tests/phpunit/tests/comment/defaultPingStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php

/**
* Unit tests covering default ping status and pingback flag settings.
*
* @group comment
* @group option
*
* @covers ::populate_options
* @covers ::get_default_comment_status
* @covers ::wp_insert_post
* @covers ::_publish_post_hook
*/
class Tests_Comment_DefaultPingStatus extends WP_UnitTestCase {

/**
* Original default_ping_status option value.
*
* @var string
*/
private $original_ping_status;

/**
* Original default_pingback_flag option value.
*
* @var int|string
*/
private $original_pingback_flag;

public function set_up() {
parent::set_up();

$this->original_ping_status = get_option( 'default_ping_status' );
$this->original_pingback_flag = get_option( 'default_pingback_flag' );
}

public function tear_down() {
update_option( 'default_ping_status', $this->original_ping_status );
update_option( 'default_pingback_flag', $this->original_pingback_flag );

parent::tear_down();
}

/**
* Tests that default_ping_status defaults to 'closed' for fresh installations.
*/
public function test_default_ping_status_defaults_to_closed() {
$this->assertSame( 'closed', get_option( 'default_ping_status' ) );
}

/**
* Tests that default_pingback_flag defaults to 0 for fresh installations.
*/
public function test_default_pingback_flag_defaults_to_zero() {
$this->assertSame( 0, (int) get_option( 'default_pingback_flag' ) );
}

/**
* Tests that newly created posts default to ping_status 'closed'.
*/
public function test_new_post_defaults_to_closed_ping_status() {
$post = self::factory()->post->create_and_get();

$this->assertSame( 'closed', $post->ping_status );
$this->assertFalse( pings_open( $post ) );
}

/**
* Tests that an explicit ping_status 'open' is respected on post creation.
*/
public function test_new_post_respects_explicit_open_ping_status() {
$post = self::factory()->post->create_and_get(
array( 'ping_status' => 'open' )
);

$this->assertSame( 'open', $post->ping_status );
$this->assertTrue( pings_open( $post ) );
}

/**
* Tests that get_default_comment_status() returns 'closed' for pingback and trackback.
*/
public function test_get_default_comment_status_returns_closed_for_pingback_and_trackback() {
$this->assertSame( 'closed', get_default_comment_status( 'post', 'pingback' ) );
$this->assertSame( 'closed', get_default_comment_status( 'post', 'trackback' ) );
$this->assertSame( 'open', get_default_comment_status( 'post', 'comment' ) );
}

/**
* Tests that modifying default_ping_status option updates new post creation defaults.
*/
public function test_updating_default_ping_status_option_updates_new_post_defaults() {
update_option( 'default_ping_status', 'open' );

$this->assertSame( 'open', get_default_comment_status( 'post', 'pingback' ) );

$post = self::factory()->post->create_and_get();
$this->assertSame( 'open', $post->ping_status );
$this->assertTrue( pings_open( $post ) );
}

/**
* Tests that publishing a post does not queue _pingme postmeta when default_pingback_flag is 0.
*/
public function test_publish_post_does_not_queue_pingme_when_flag_is_zero() {
update_option( 'default_pingback_flag', 0 );

$post_id = self::factory()->post->create(
array(
'post_status' => 'publish',
'post_content' => 'Link: <a href="https://example.com/target">Target</a>',
)
);

$this->assertSame( '', get_post_meta( $post_id, '_pingme', true ) );
}

/**
* Tests that publishing a post queues _pingme postmeta when default_pingback_flag is enabled.
*/
public function test_publish_post_queues_pingme_when_flag_is_enabled() {
update_option( 'default_pingback_flag', 1 );

$post_id = self::factory()->post->create(
array(
'post_status' => 'publish',
'post_content' => 'Link: <a href="https://example.com/target">Target</a>',
)
);

$this->assertSame( '1', get_post_meta( $post_id, '_pingme', true ) );
}

/**
* Tests that populate_options() does not overwrite existing site settings during upgrades.
*/
public function test_populate_options_does_not_overwrite_existing_settings() {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
require_once ABSPATH . 'wp-admin/includes/schema.php';

update_option( 'default_ping_status', 'open' );
update_option( 'default_pingback_flag', 1 );

populate_options();

$this->assertSame( 'open', get_option( 'default_ping_status' ) );
$this->assertSame( 1, (int) get_option( 'default_pingback_flag' ) );
}
}
4 changes: 3 additions & 1 deletion tests/phpunit/tests/comment/pingsOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public function test_post_does_not_exist() {
* @ticket 54159
*/
public function test_post_exist_status_open() {
$post = self::factory()->post->create_and_get();
$post = self::factory()->post->create_and_get(
array( 'ping_status' => 'open' )
);
$this->assertTrue( pings_open( $post ) );
}

Expand Down
6 changes: 4 additions & 2 deletions tests/phpunit/tests/post/wpInsertPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ public function test_insert_programmatic_sanitized() {

/**
* @ticket 31168
* @ticket 38207
*/
public function test_wp_insert_post_default_comment_ping_status_open() {
$post_id = self::factory()->post->create(
Expand All @@ -663,7 +664,7 @@ public function test_wp_insert_post_default_comment_ping_status_open() {
$post = get_post( $post_id );

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

/**
Expand All @@ -684,6 +685,7 @@ public function test_wp_insert_post_page_default_comment_ping_status_closed() {

/**
* @ticket 31168
* @ticket 38207
*/
public function test_wp_insert_post_cpt_default_comment_ping_status_open() {
register_post_type(
Expand All @@ -704,7 +706,7 @@ public function test_wp_insert_post_cpt_default_comment_ping_status_open() {
_unregister_post_type( 'cpt' );

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

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/phpunit/tests/wp/sendHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ function ( $headers ) {
}
);

$post_id = self::factory()->post->create(
array(
'ping_status' => 'open',
)
);
$this->go_to( get_permalink( $post_id ) );
}

/**
* @ticket 56840
* @ticket 38207
*/
public function test_send_headers_does_not_set_x_pingback_when_pings_are_closed() {
add_action(
'wp_headers',
function ( $headers ) {
$this->assertArrayNotHasKey( 'X-Pingback', $headers );
}
);

$post_id = self::factory()->post->create();
$this->go_to( get_permalink( $post_id ) );
}
Expand Down
6 changes: 3 additions & 3 deletions tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -13254,7 +13254,7 @@ mockedApiResponse.PostsCollection = [
"author": 0,
"featured_media": 0,
"comment_status": "open",
"ping_status": "open",
"ping_status": "closed",
"sticky": false,
"template": "",
"format": "standard",
Expand Down Expand Up @@ -13372,7 +13372,7 @@ mockedApiResponse.PostModel = {
"author": 0,
"featured_media": 0,
"comment_status": "open",
"ping_status": "open",
"ping_status": "closed",
"sticky": false,
"template": "",
"format": "standard",
Expand Down Expand Up @@ -14939,7 +14939,7 @@ mockedApiResponse.settings = {
"page_on_front": 0,
"page_for_posts": 0,
"page_for_privacy_policy": 0,
"default_ping_status": "open",
"default_ping_status": "closed",
"default_comment_status": "open",
"site_logo": null,
"site_icon": 0
Expand Down
Loading