Skip to content
Open
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
49 changes: 49 additions & 0 deletions tests/phpunit/tests/post/wpInsertPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -1558,4 +1558,53 @@ public function test_scheduled_post_with_a_past_date_should_be_published() {

$this->assertSame( 'future', get_post_status( $post_id ) );
}

/**
* @ticket 59354
* @covers ::wp_insert_post
*/
public function test_extra_queries_when_updating_tags() {
// First we creat a post with a tag, for the basis of our test.
$post_id = wp_insert_post(
array(
'post_title' => 'title',
'tags_input' => 'new_tag',
)
);

$starting_number_of_queries = get_num_queries();

// We now update the post, while having tags as parameters.
$post_id = wp_insert_post(
array(
'post_title' => 'title',
'tags_input' => 'new_tag',
)
);

$queries_added_by_updating_post_with_tag_parameters = get_num_queries() - $starting_number_of_queries;

// We now update the post, again while having tags as parameters.
$post_id = wp_insert_post(
array(
'post_title' => 'title',
'tags_input' => 'new_tag',
)
);

$queries_added_by_updating_post_with_tag_parameters_again = get_num_queries() - $queries_added_by_updating_post_with_tag_parameters - $starting_number_of_queries;

$this->assertSame( $queries_added_by_updating_post_with_tag_parameters_again, $queries_added_by_updating_post_with_tag_parameters, 'The two inserts should perform the same amount of queries.' );

// We now update the post, but while NOT having tags as parameters.
$post_id = wp_insert_post(
array(
'post_title' => 'title',
)
);

$queries_added_by_updating_post_with_no_tag_parameters = get_num_queries() - $queries_added_by_updating_post_with_tag_parameters_again - $queries_added_by_updating_post_with_tag_parameters - $starting_number_of_queries;

$this->assertLessThan( $queries_added_by_updating_post_with_tag_parameters, $queries_added_by_updating_post_with_no_tag_parameters, 'Inserts without tag parameters should perform less amount of queries with ones with tag parameters.' );
}
}