Skip to content

Commit

Permalink
Tests: Use more specific assertions in wp_scheduled_delete() tests.
Browse files Browse the repository at this point in the history
Includes clarifying test method names and descriptions.

Follow-up to [57224].

See #59938.

git-svn-id: https://develop.svn.wordpress.org/trunk@57237 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jan 2, 2024
1 parent 8e88bc8 commit 67296ea
Showing 1 changed file with 38 additions and 40 deletions.
78 changes: 38 additions & 40 deletions tests/phpunit/tests/functions/wpScheduledDelete.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/**
* Tests for the wp_scheduled_delete function.
* Tests for the wp_scheduled_delete() function.
*
* @group Functions.php
* @group functions
*
* @covers ::wp_scheduled_delete
*/
Expand All @@ -17,18 +17,19 @@ public function tear_down() {
if ( self::$comment_id ) {
wp_delete_comment( self::$comment_id );
}

// Remove page.
if ( self::$page_id ) {
wp_delete_post( self::$page_id );
}

parent::tear_down();
}

/**
* Delete old trashed post/pages.
* Tests that old trashed posts/pages are deleted.
*
* @ticket 59938
*
*/
public function test_wp_scheduled_delete() {
self::$page_id = self::factory()->post->create(
Expand All @@ -40,21 +41,21 @@ public function test_wp_scheduled_delete() {
add_post_meta( self::$page_id, '_wp_trash_meta_time', time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS + 1 ) );
add_post_meta( self::$page_id, '_wp_trash_meta_status', 'published' );

$this->assertNotEmpty( get_post( self::$page_id ) );
$this->assertInstanceOf( 'WP_Post', get_post( self::$page_id ) );

wp_scheduled_delete();

$this->assertEmpty( get_post( self::$page_id ) );
$this->assertNull( get_post( self::$page_id ) );
}

/**
* Don't delete old trashed post/pages if status not trash.
* Remove the trash meta status.
* Tests that old trashed posts/pages are not deleted if status is not 'trash'.
*
* @ticket 59938
* Ensures that the trash meta status is removed.
*
* @ticket 59938
*/
public function test_wp_scheduled_delete_not_trash() {
public function test_wp_scheduled_delete_status_not_trash() {
self::$page_id = self::factory()->post->create(
array(
'post_type' => 'page',
Expand All @@ -64,23 +65,22 @@ public function test_wp_scheduled_delete_not_trash() {
add_post_meta( self::$page_id, '_wp_trash_meta_time', time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS + 1 ) );
add_post_meta( self::$page_id, '_wp_trash_meta_status', 'published' );

$this->assertNotEmpty( get_post( self::$page_id ) );
$this->assertInstanceOf( 'WP_Post', get_post( self::$page_id ) );

wp_scheduled_delete();

$this->assertNotEmpty( get_post( self::$page_id ) );
$this->assertEmpty( get_post_meta( self::$page_id, '_wp_trash_meta_time', true ) );
$this->assertEmpty( get_post_meta( self::$page_id, '_wp_trash_meta_status', true ) );
$this->assertInstanceOf( 'WP_Post', get_post( self::$page_id ) );
$this->assertSame( '', get_post_meta( self::$page_id, '_wp_trash_meta_time', true ) );
$this->assertSame( '', get_post_meta( self::$page_id, '_wp_trash_meta_status', true ) );
}


/**
* Don't delete old trashed post/pages if old enough.
* Tests that old trashed posts/pages are not deleted if not old enough.
*
* @ticket 59938
*
*/
public function test_wp_scheduled_delete_not_old() {
public function test_wp_scheduled_delete_page_not_old_enough() {
self::$page_id = self::factory()->post->create(
array(
'post_type' => 'page',
Expand All @@ -90,20 +90,19 @@ public function test_wp_scheduled_delete_not_old() {
add_post_meta( self::$page_id, '_wp_trash_meta_time', time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ) );
add_post_meta( self::$page_id, '_wp_trash_meta_status', 'published' );

$this->assertNotEmpty( get_post( self::$page_id ) );
$this->assertInstanceOf( 'WP_Post', get_post( self::$page_id ) );

wp_scheduled_delete();

$this->assertNotEmpty( get_post( self::$page_id ) );
$this->assertNotEmpty( get_post_meta( self::$page_id, '_wp_trash_meta_time', true ) );
$this->assertNotEmpty( get_post_meta( self::$page_id, '_wp_trash_meta_status', true ) );
$this->assertInstanceOf( 'WP_Post', get_post( self::$page_id ) );
$this->assertIsNumeric( get_post_meta( self::$page_id, '_wp_trash_meta_time', true ) );
$this->assertSame( 'published', get_post_meta( self::$page_id, '_wp_trash_meta_status', true ) );
}

/**
* Delete old trashed comments.
* Tests that old trashed comments are deleted.
*
* @ticket 59938
*
*/
public function test_wp_scheduled_delete_comment() {
self::$comment_id = self::factory()->comment->create(
Expand All @@ -114,21 +113,21 @@ public function test_wp_scheduled_delete_comment() {
add_comment_meta( self::$comment_id, '_wp_trash_meta_time', time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS + 1 ) );
add_post_meta( self::$comment_id, '_wp_trash_meta_status', 'published' );

$this->assertNotEmpty( get_comment( self::$comment_id ) );
$this->assertInstanceOf( 'WP_Comment', get_comment( self::$comment_id ) );

wp_scheduled_delete();

$this->assertEmpty( get_comment( self::$comment_id ) );
$this->assertNull( get_comment( self::$comment_id ) );
}

/**
* Don't delete old trashed comments if status not trash.
* Remove the trash meta status.
* Tests that old trashed comments are not deleted if status is not 'trash'.
*
* @ticket 59938
* Ensures that the trash meta status is removed.
*
* @ticket 59938
*/
public function test_wp_scheduled_delete_not_trash_comment() {
public function test_wp_scheduled_delete_comment_status_not_trash() {
self::$comment_id = self::factory()->comment->create(
array(
'comment_approved' => '1',
Expand All @@ -137,23 +136,22 @@ public function test_wp_scheduled_delete_not_trash_comment() {
add_comment_meta( self::$comment_id, '_wp_trash_meta_time', time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS + 1 ) );
add_comment_meta( self::$comment_id, '_wp_trash_meta_status', 'published' );

$this->assertNotEmpty( get_comment( self::$comment_id ) );
$this->assertInstanceOf( 'WP_Comment', get_comment( self::$comment_id ) );

wp_scheduled_delete();

$this->assertNotEmpty( get_comment( self::$comment_id ) );
$this->assertEmpty( get_comment_meta( self::$comment_id, '_wp_trash_meta_time', true ) );
$this->assertEmpty( get_comment_meta( self::$comment_id, '_wp_trash_meta_status', true ) );
$this->assertInstanceOf( 'WP_Comment', get_comment( self::$comment_id ) );
$this->assertSame( '', get_comment_meta( self::$comment_id, '_wp_trash_meta_time', true ) );
$this->assertSame( '', get_comment_meta( self::$comment_id, '_wp_trash_meta_status', true ) );
}


/**
* Don't delete old trashed comments if old enough.
* Tests that old trashed comments are not deleted if not old enough.
*
* @ticket 59938
*
*/
public function test_wp_scheduled_delete_not_old_comment() {
public function test_wp_scheduled_delete_comment_not_old_enough() {
self::$comment_id = self::factory()->comment->create(
array(
'comment_approved' => 'trash',
Expand All @@ -162,12 +160,12 @@ public function test_wp_scheduled_delete_not_old_comment() {
add_comment_meta( self::$comment_id, '_wp_trash_meta_time', time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ) );
add_comment_meta( self::$comment_id, '_wp_trash_meta_status', 'published' );

$this->assertNotEmpty( get_comment( self::$comment_id ) );
$this->assertInstanceOf( 'WP_Comment', get_comment( self::$comment_id ) );

wp_scheduled_delete();

$this->assertNotEmpty( get_comment( self::$comment_id ) );
$this->assertNotEmpty( get_comment_meta( self::$comment_id, '_wp_trash_meta_time', true ) );
$this->assertNotEmpty( get_comment_meta( self::$comment_id, '_wp_trash_meta_status', true ) );
$this->assertInstanceOf( 'WP_Comment', get_comment( self::$comment_id ) );
$this->assertIsNumeric( get_comment_meta( self::$comment_id, '_wp_trash_meta_time', true ) );
$this->assertSame( 'published', get_comment_meta( self::$comment_id, '_wp_trash_meta_status', true ) );
}
}

0 comments on commit 67296ea

Please sign in to comment.