forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build/Test: Add Tests for
wp_scheduled_delete
.
Props pbearne. Fixes #59938. git-svn-id: https://develop.svn.wordpress.org/trunk@57224 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
1 parent
e3731cc
commit 54a09a7
Showing
1 changed file
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
<?php | ||
|
||
/** | ||
* Tests for the wp_scheduled_delete function. | ||
* | ||
* @group Functions.php | ||
* | ||
* @covers ::wp_scheduled_delete | ||
*/ | ||
class Tests_Functions_wpScheduledDelete extends WP_UnitTestCase { | ||
|
||
protected static $comment_id; | ||
protected static $page_id; | ||
|
||
public function tear_down() { | ||
// Remove comment. | ||
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. | ||
* | ||
* @ticket 59938 | ||
* | ||
*/ | ||
public function test_wp_scheduled_delete() { | ||
self::$page_id = self::factory()->post->create( | ||
array( | ||
'post_type' => 'page', | ||
'post_status' => '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 ) ); | ||
|
||
wp_scheduled_delete(); | ||
|
||
$this->assertEmpty( get_post( self::$page_id ) ); | ||
} | ||
|
||
/** | ||
* Don't delete old trashed post/pages if status not trash. | ||
* Remove the trash meta status. | ||
* | ||
* @ticket 59938 | ||
* | ||
*/ | ||
public function test_wp_scheduled_delete_not_trash() { | ||
self::$page_id = self::factory()->post->create( | ||
array( | ||
'post_type' => 'page', | ||
'post_status' => 'published', | ||
) | ||
); | ||
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 ) ); | ||
|
||
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 ) ); | ||
} | ||
|
||
|
||
/** | ||
* Don't delete old trashed post/pages if old enough. | ||
* | ||
* @ticket 59938 | ||
* | ||
*/ | ||
public function test_wp_scheduled_delete_not_old() { | ||
self::$page_id = self::factory()->post->create( | ||
array( | ||
'post_type' => 'page', | ||
'post_status' => 'trash', | ||
) | ||
); | ||
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 ) ); | ||
|
||
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 ) ); | ||
} | ||
|
||
/** | ||
* Delete old trashed comments. | ||
* | ||
* @ticket 59938 | ||
* | ||
*/ | ||
public function test_wp_scheduled_delete_comment() { | ||
self::$comment_id = self::factory()->comment->create( | ||
array( | ||
'comment_approved' => 'trash', | ||
) | ||
); | ||
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 ) ); | ||
|
||
wp_scheduled_delete(); | ||
|
||
$this->assertEmpty( get_comment( self::$comment_id ) ); | ||
} | ||
|
||
/** | ||
* Don't delete old trashed comments if status not trash. | ||
* Remove the trash meta status. | ||
* | ||
* @ticket 59938 | ||
* | ||
*/ | ||
public function test_wp_scheduled_delete_not_trash_comment() { | ||
self::$comment_id = self::factory()->comment->create( | ||
array( | ||
'comment_approved' => '1', | ||
) | ||
); | ||
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 ) ); | ||
|
||
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 ) ); | ||
} | ||
|
||
|
||
/** | ||
* Don't delete old trashed comments if old enough. | ||
* | ||
* @ticket 59938 | ||
* | ||
*/ | ||
public function test_wp_scheduled_delete_not_old_comment() { | ||
self::$comment_id = self::factory()->comment->create( | ||
array( | ||
'comment_approved' => 'trash', | ||
) | ||
); | ||
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 ) ); | ||
|
||
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 ) ); | ||
} | ||
} |