mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Comments: Update comment cache in the upgrade routine for changing the comment_type DB field value in comments table.
This ensures that comment object cache is cleared after changing the comment type to `comment` instead of an empty string. Add a unit test for `_wp_batch_update_comment_type()`. Follow-up to [47597], [47626], [48225], [48227]. Props imath, westonruter. Fixes #49236. git-svn-id: https://develop.svn.wordpress.org/trunk@48748 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group comment
|
||||
* @covers ::_wp_batch_update_comment_type
|
||||
*/
|
||||
class Tests_Batch_Update_Comment_Type extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 49236
|
||||
*/
|
||||
public function test__wp_batch_update_comment_type() {
|
||||
global $wpdb;
|
||||
|
||||
$comment_ids = self::factory()->comment->create_many( 3 );
|
||||
$comment_id_list = implode( ',', $comment_ids );
|
||||
|
||||
$wpdb->query(
|
||||
"UPDATE {$wpdb->comments}
|
||||
SET comment_type = ''
|
||||
WHERE comment_type = 'comment'
|
||||
AND comment_ID in ({$comment_id_list})" // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
);
|
||||
|
||||
clean_comment_cache( $comment_ids );
|
||||
|
||||
foreach ( $comment_ids as $comment_id ) {
|
||||
$comment = get_comment( $comment_id );
|
||||
$this->assertEmpty( $comment->comment_type );
|
||||
}
|
||||
|
||||
add_filter( 'wp_update_comment_type_batch_size', array( $this, 'filter_comment_type_batch_size' ) );
|
||||
add_filter( 'schedule_event', '__return_null' );
|
||||
|
||||
_wp_batch_update_comment_type();
|
||||
|
||||
remove_filter( 'wp_update_comment_type_batch_size', array( $this, 'filter_comment_type_batch_size' ) );
|
||||
remove_filter( 'schedule_event', '__return_null' );
|
||||
|
||||
foreach ( $comment_ids as $comment_id ) {
|
||||
$updated_comment = get_comment( $comment_id );
|
||||
$this->assertEquals( 'comment', $updated_comment->comment_type );
|
||||
}
|
||||
}
|
||||
|
||||
public function filter_comment_type_batch_size() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user