mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Tests: Use more specific assertions in wp_scheduled_delete() tests.
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
This commit is contained in:
parent
8e88bc8efa
commit
67296ea571
@ -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
|
||||
*/
|
||||
@ -17,18 +17,19 @@ class Tests_Functions_wpScheduledDelete extends WP_UnitTestCase {
|
||||
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(
|
||||
@ -40,21 +41,21 @@ class Tests_Functions_wpScheduledDelete extends WP_UnitTestCase {
|
||||
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'.
|
||||
*
|
||||
* 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',
|
||||
@ -64,23 +65,22 @@ class Tests_Functions_wpScheduledDelete extends WP_UnitTestCase {
|
||||
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',
|
||||
@ -90,20 +90,19 @@ class Tests_Functions_wpScheduledDelete extends WP_UnitTestCase {
|
||||
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(
|
||||
@ -114,21 +113,21 @@ class Tests_Functions_wpScheduledDelete extends WP_UnitTestCase {
|
||||
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'.
|
||||
*
|
||||
* 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',
|
||||
@ -137,23 +136,22 @@ class Tests_Functions_wpScheduledDelete extends WP_UnitTestCase {
|
||||
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',
|
||||
@ -162,12 +160,12 @@ class Tests_Functions_wpScheduledDelete extends WP_UnitTestCase {
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user