Privacy: Add a table of contents to Personal Data Export report for easier navigation.

Props xkon, garrett-eclipse, birgire, karmatosed.
Fixes #46894.

git-svn-id: https://develop.svn.wordpress.org/trunk@47278 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-02-11 21:26:25 +00:00
parent d6352c544b
commit b8e935b2f2
3 changed files with 415 additions and 22 deletions
@@ -260,8 +260,8 @@ class Tests_Privacy_WpPrivacyGeneratePersonalDataExportFile extends WP_UnitTestC
$report_contents = file_get_contents( $report_dir . 'index.html' );
$request = wp_get_user_request( self::$export_request_id );
$this->assertContains( '<h1>Personal Data Export</h1>', $report_contents );
$this->assertContains( '<h2>About</h2>', $report_contents );
$this->assertContains( '<h1 id="top">Personal Data Export</h1>', $report_contents );
$this->assertContains( '<h2 id="about-about">About</h2>', $report_contents );
$this->assertContains( $request->email, $report_contents );
}
@@ -294,4 +294,364 @@ class Tests_Privacy_WpPrivacyGeneratePersonalDataExportFile extends WP_UnitTestC
$this->assertContains( '"Personal Data Export for ' . $request->email . '"', $report_contents_json );
$this->assertContains( '"about"', $report_contents_json );
}
/**
* Test the export HTML file containing one export group has no table of contents.
*
* @ticket 46894
*/
public function test_single_group_export_no_toc_or_return_to_top() {
$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();
$this->assertTrue( file_exists( $report_dir . 'index.html' ) );
$report_contents = file_get_contents( $report_dir . 'index.html' );
$request = wp_get_user_request( self::$export_request_id );
$this->assertNotContains( '<div id="table_of_contents">', $report_contents );
$this->assertNotContains( '<div class="return_to_top">', $report_contents );
$this->assertContains( $request->email, $report_contents );
}
/**
* Test the export HTML file containing ore than one export group has a table of contents.
*
* @ticket 46894
*/
public function test_multiple_group_export_has_toc_and_return_to_top() {
$this->expectOutputString( '' );
// Setup Export Data to contain multiple groups
$export_data_grouped = array(
'user' => array(
'group_label' => 'User',
'group_description' => 'User&#8217;s profile data.',
'items' => array(
'user-1' => array(
array(
'name' => 'User ID',
'value' => 1,
),
array(
'name' => 'User Login Name',
'value' => 'user_login',
),
array(
'name' => 'User Nice Name',
'value' => 'User Name',
),
array(
'name' => 'User Email',
'value' => 'export-requester@example.com',
),
array(
'name' => 'User Registration Date',
'value' => '2020-01-31 19:29:29',
),
array(
'name' => 'User Display Name',
'value' => 'User Name',
),
array(
'name' => 'User Nickname',
'value' => 'User',
),
),
),
),
);
update_post_meta( self::$export_request_id, '_export_data_grouped', $export_data_grouped );
// Generate Export File
wp_privacy_generate_personal_data_export_file( self::$export_request_id );
$this->assertTrue( file_exists( $this->export_file_name ) );
// Cleam-up for subsequent tests
update_post_meta( self::$export_request_id, '_export_data_grouped', array() );
$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();
$this->assertTrue( file_exists( $report_dir . 'index.html' ) );
$report_contents = file_get_contents( $report_dir . 'index.html' );
$request = wp_get_user_request( self::$export_request_id );
$this->assertContains( '<div id="table_of_contents">', $report_contents );
$this->assertContains( '<h2 id="user-user">User</h2>', $report_contents );
$this->assertContains( '<div class="return_to_top">', $report_contents );
$this->assertContains( $request->email, $report_contents );
}
/**
* Test the export HTML file containing multiple export groups with multiple group items
* has a table of contents with group count.
*
* @ticket 46894
*/
public function test_multiple_group_export_multiple_items_group_count_in_toc() {
$this->expectOutputString( '' );
// Setup Export Data to contain multiple groups
$export_data_grouped = array(
'user' => array(
'group_label' => 'User',
'group_description' => 'User&#8217;s profile data.',
'items' => array(
'user-1' => array(
array(
'name' => 'User ID',
'value' => 1,
),
array(
'name' => 'User Login Name',
'value' => 'user_login',
),
array(
'name' => 'User Nice Name',
'value' => 'User Name',
),
array(
'name' => 'User Email',
'value' => 'export-requester@example.com',
),
array(
'name' => 'User Registration Date',
'value' => '2020-01-31 19:29:29',
),
array(
'name' => 'User Display Name',
'value' => 'User Name',
),
array(
'name' => 'User Nickname',
'value' => 'User',
),
),
),
),
'comments' => array(
'group_label' => 'Comments',
'group_description' => 'User&#8217;s comment data.',
'items' => array(
'comment-2' => array(
array(
'name' => 'Comment Author',
'value' => 'User Name',
),
array(
'name' => 'Comment Author Email',
'value' => 'export-requester@example.com',
),
array(
'name' => 'Comment Author IP',
'value' => '::1',
),
array(
'name' => 'Comment Author User Agent',
'value' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
),
array(
'name' => 'Comment Date',
'value' => '2020-01-31 19:55:19',
),
array(
'name' => 'Comment Content',
'value' => 'Test',
),
array(
'name' => 'Comment URL',
'value' => '<a href="http://localhost:8888/46894/2020/01/31/hello-world/#comment-2" target="_blank" rel="noreferrer noopener">http://localhost:8888/46894/2020/01/31/hello-world/#comment-2</a>',
),
),
'comment-3' => array(
array(
'name' => 'Comment Author',
'value' => 'User Name',
),
array(
'name' => 'Comment Author Email',
'value' => 'export-requester@example.com',
),
array(
'name' => 'Comment Author IP',
'value' => '::1',
),
array(
'name' => 'Comment Author User Agent',
'value' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
),
array(
'name' => 'Comment Date',
'value' => '2020-01-31 20:55:19',
),
array(
'name' => 'Comment Content',
'value' => 'Test #2',
),
array(
'name' => 'Comment URL',
'value' => '<a href="http://localhost:8888/46894/2020/01/31/hello-world/#comment-3" target="_blank" rel="noreferrer noopener">http://localhost:8888/46894/2020/01/31/hello-world/#comment-3</a>',
),
),
),
),
);
update_post_meta( self::$export_request_id, '_export_data_grouped', $export_data_grouped );
// Generate Export File
wp_privacy_generate_personal_data_export_file( self::$export_request_id );
$this->assertTrue( file_exists( $this->export_file_name ) );
// Cleam-up for subsequent tests
update_post_meta( self::$export_request_id, '_export_data_grouped', array() );
$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();
$this->assertTrue( file_exists( $report_dir . 'index.html' ) );
$report_contents = file_get_contents( $report_dir . 'index.html' );
$request = wp_get_user_request( self::$export_request_id );
$this->assertContains( '<div id="table_of_contents">', $report_contents );
$this->assertContains( '<a href="#comments-comments">Comments <span class="count">(2)</span></a>', $report_contents );
$this->assertContains( $request->email, $report_contents );
}
/**
* Test the export HTML file containing multiple export groups with no multiple group items
* has a table of contents without group count.
*
* @ticket 46894
*/
public function test_multiple_group_export_single_items_no_group_count_in_toc() {
$this->expectOutputString( '' );
// Setup Export Data to contain multiple groups
$export_data_grouped = array(
'user' => array(
'group_label' => 'User',
'group_description' => 'User&#8217;s profile data.',
'items' => array(
'user-1' => array(
array(
'name' => 'User ID',
'value' => 1,
),
array(
'name' => 'User Login Name',
'value' => 'user_login',
),
array(
'name' => 'User Nice Name',
'value' => 'User Name',
),
array(
'name' => 'User Email',
'value' => 'export-requester@example.com',
),
array(
'name' => 'User Registration Date',
'value' => '2020-01-31 19:29:29',
),
array(
'name' => 'User Display Name',
'value' => 'User Name',
),
array(
'name' => 'User Nickname',
'value' => 'User',
),
),
),
),
'comments' => array(
'group_label' => 'Comments',
'group_description' => 'User&#8217;s comment data.',
'items' => array(
'comment-2' => array(
array(
'name' => 'Comment Author',
'value' => 'User Name',
),
array(
'name' => 'Comment Author Email',
'value' => 'export-requester@example.com',
),
array(
'name' => 'Comment Author IP',
'value' => '::1',
),
array(
'name' => 'Comment Author User Agent',
'value' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
),
array(
'name' => 'Comment Date',
'value' => '2020-01-31 19:55:19',
),
array(
'name' => 'Comment Content',
'value' => 'Test',
),
array(
'name' => 'Comment URL',
'value' => '<a href="http://localhost:8888/46894/2020/01/31/hello-world/#comment-2" target="_blank" rel="noreferrer noopener">http://localhost:8888/46894/2020/01/31/hello-world/#comment-2</a>',
),
),
),
),
);
update_post_meta( self::$export_request_id, '_export_data_grouped', $export_data_grouped );
// Generate Export File
wp_privacy_generate_personal_data_export_file( self::$export_request_id );
$this->assertTrue( file_exists( $this->export_file_name ) );
// Cleam-up for subsequent tests
update_post_meta( self::$export_request_id, '_export_data_grouped', array() );
$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();
$this->assertTrue( file_exists( $report_dir . 'index.html' ) );
$report_contents = file_get_contents( $report_dir . 'index.html' );
$request = wp_get_user_request( self::$export_request_id );
$this->assertContains( '<div id="table_of_contents">', $report_contents );
$this->assertNotContains( '<span class="count">', $report_contents );
$this->assertContains( $request->email, $report_contents );
}
}