Privacy: Introduce a JSON file into the personal data export.

The produced ZIP archive will now include an `export.json` file along with the current `index.html`.

Props xkon.
Fixes #49029. See #46424.

git-svn-id: https://develop.svn.wordpress.org/trunk@47146 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-01-31 01:34:17 +00:00
parent 13a9ab716e
commit b894d8665a
2 changed files with 94 additions and 36 deletions
@@ -237,11 +237,11 @@ class Tests_Privacy_WpPrivacyGeneratePersonalDataExportFile extends WP_UnitTestC
}
/**
* Test the export file has all the expected parts.
* Test the export HTML file has all the expected parts.
*
* @ticket 44233
*/
public function test_contents() {
public function test_html_contents() {
$this->expectOutputString( '' );
wp_privacy_generate_personal_data_export_file( self::$export_request_id );
$this->assertTrue( file_exists( $this->export_file_name ) );
@@ -264,4 +264,34 @@ class Tests_Privacy_WpPrivacyGeneratePersonalDataExportFile extends WP_UnitTestC
$this->assertContains( '<h2>About</h2>', $report_contents );
$this->assertContains( $request->email, $report_contents );
}
/**
* Test the export JSON file has all the expected parts.
*
* @ticket 49029
*/
public function test_json_contents() {
$this->expectOutputString( '' );
wp_privacy_generate_personal_data_export_file( self::$export_request_id );
$this->assertTrue( file_exists( $this->export_file_name ) );
$report_dir = trailingslashit( self::$exports_dir . 'test_contents' );
mkdir( $report_dir );
$zip = new ZipArchive();
$opened_zip = $zip->open( $this->export_file_name );
$this->assertTrue( $opened_zip );
$zip->extractTo( $report_dir );
$zip->close();
$request = wp_get_user_request_data( self::$export_request_id );
$this->assertTrue( file_exists( $report_dir . 'export.json' ) );
$report_contents_json = file_get_contents( $report_dir . 'export.json' );
$this->assertContains( '"Personal Data Export for ' . $request->email . '"', $report_contents_json );
$this->assertContains( '"about"', $report_contents_json );
}
}