diff --git a/tests/phpunit/tests/functions/wpScheduledDelete.php b/tests/phpunit/tests/functions/wpScheduledDelete.php new file mode 100644 index 0000000000000..38044d44a1827 --- /dev/null +++ b/tests/phpunit/tests/functions/wpScheduledDelete.php @@ -0,0 +1,173 @@ +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 ) ); + } +}