From 238504d36f31cdb90cd1cb74e0449be56d5a78d5 Mon Sep 17 00:00:00 2001 From: iandunn Date: Thu, 17 May 2018 16:38:01 +0000 Subject: [PATCH] Tests: Add case for `wp_privacy_delete_old_export_files()`. Props allendav. See #43546. git-svn-id: https://develop.svn.wordpress.org/trunk@43292 602fd350-edb4-49c9-b593-d223f7449a82 --- .../privacy/wpPrivacyDeleteOldExportFiles.php | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 tests/phpunit/tests/privacy/wpPrivacyDeleteOldExportFiles.php diff --git a/tests/phpunit/tests/privacy/wpPrivacyDeleteOldExportFiles.php b/tests/phpunit/tests/privacy/wpPrivacyDeleteOldExportFiles.php new file mode 100644 index 0000000000..61629513fd --- /dev/null +++ b/tests/phpunit/tests/privacy/wpPrivacyDeleteOldExportFiles.php @@ -0,0 +1,146 @@ +assertTrue( true ); + } + + /** + * Return the path to a non-existent folder. + * + * @since 4.9.6 + * + * @param string $exports_dir The default personal data export directory. + * + * @return string The path to a folder that doesn't exist. + */ + public function filter_bad_exports_dir( $exports_dir ) { + $upload_dir = wp_upload_dir(); + + return trailingslashit( $upload_dir['basedir'] ) . 'invalid-12345'; + } + + /** + * The function should delete files that are past the expiration date. + * + * @since 4.9.6 + */ + public function test_expired_files_should_be_deleted() { + wp_privacy_delete_old_export_files(); + + $this->assertFalse( file_exists( self::$expired_export_file ) ); + } + + /** + * The function should not delete files that are not past the expiration date. + * + * @since 4.9.6 + */ + public function test_unexpired_files_should_not_be_deleted() { + wp_privacy_delete_old_export_files(); + + $this->assertTrue( file_exists( self::$active_export_file ) ); + } + + /** + * The function should never delete the index file, even if it's past the expiration date. + * + * @since 4.9.6 + */ + public function test_index_file_should_never_be_deleted() { + wp_privacy_delete_old_export_files(); + + $this->assertTrue( file_exists( self::$index_path ) ); + } +}