WordPress.org

Make WordPress Core

Ticket #51423: 51423-setup_export_contents_test

File 51423-setup_export_contents_test, 2.0 KB (added by hellofromTonya, 7 weeks ago)

Comments Tests_Privacy_WpPrivacyGeneratePersonalDataExportFile::setup_export_contents_test

Line 
1diff --git a/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php b/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php
2index 89cb1eeac7..9d02615300 100644
3--- a/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php
4+++ b/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php
5@@ -387,7 +387,21 @@ class Tests_Privacy_WpPrivacyGeneratePersonalDataExportFile extends WP_UnitTestC
6                $this->assertSame( $expected, $actual_json );
7        }
8 
9+       /**
10+        * Set up the export contents.
11+        *
12+        * Tasks:
13+        *      - Delete or update the '_export_data_grouped' post meta.
14+        *      - Run `wp_privacy_generate_personal_data_export_file()`.
15+        *      - Unzip the export package in a temporary directory to give the test access to the export files.
16+        *
17+        * @param mixed $export_data_grouped Optional. '_export_data_grouped' post meta value. When null, delete the meta;
18+        *                                   else update to the given value.
19+        *
20+        * @return string Returns export report directory path.
21+        */
22        private function setup_export_contents_test( $export_data_grouped = null ) {
23+               // Delete or update the given meta.
24                if ( null === $export_data_grouped ) {
25                        delete_post_meta( self::$export_request_id, '_export_data_grouped' );
26                } else {
27@@ -399,13 +413,14 @@ class Tests_Privacy_WpPrivacyGeneratePersonalDataExportFile extends WP_UnitTestC
28                wp_privacy_generate_personal_data_export_file( self::$export_request_id );
29                $this->assertTrue( file_exists( $this->export_file_name ) );
30 
31+               // Create a temporary export directory for the test's export files.
32                $report_dir = trailingslashit( self::$exports_dir . 'test_contents' );
33                mkdir( $report_dir );
34 
35+               // Unzip the current test's export file to give the test access to .html and .json files.
36                $zip        = new ZipArchive();
37                $opened_zip = $zip->open( $this->export_file_name );
38                $this->assertTrue( $opened_zip );
39-
40                $zip->extractTo( $report_dir );
41                $zip->close();
42