mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 21:08:44 +01:00
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
This commit is contained in:
parent
e3731cc113
commit
54a09a7ec9
173
tests/phpunit/tests/functions/wpScheduledDelete.php
Normal file
173
tests/phpunit/tests/functions/wpScheduledDelete.php
Normal file
@ -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 ) );
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user