<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[50613] trunk: Code Modernization: Check if the `_export_data_grouped` post meta is an array when generating a personal data export file.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/50613">50613</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/50613","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-03-29 19:35:36 +0000 (Mon, 29 Mar 2021)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Code Modernization: Check if the `_export_data_grouped` post meta is an array when generating a personal data export file.
This avoids a fatal error on PHP 8 in `wp_privacy_generate_personal_data_export_file()` if the `_export_data_grouped` post meta exists but is not an array.
Additionally, refactor unit tests for the function to:
* Reduce redundant code
* Switch to data provider
* Test on the full HTML output instead of select pieces of the output
* Expand unhappy path coverage
Follow-up to <a href="https://core.trac.wordpress.org/changeset/43012">[43012]</a>, <a href="https://core.trac.wordpress.org/changeset/44786">[44786]</a>, <a href="https://core.trac.wordpress.org/changeset/47146">[47146]</a>, <a href="https://core.trac.wordpress.org/changeset/47278">[47278]</a>.
Props hellofromTonya, jrf, xknown.
See <a href="https://core.trac.wordpress.org/ticket/51423">#51423</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesprivacytoolsphp">trunk/src/wp-admin/includes/privacy-tools.php</a></li>
<li><a href="#trunktestsphpunittestsprivacywpPrivacyGeneratePersonalDataExportFilephp">trunk/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesprivacytoolsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/privacy-tools.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/privacy-tools.php 2021-03-29 18:05:47 UTC (rev 50612)
+++ trunk/src/wp-admin/includes/privacy-tools.php 2021-03-29 19:35:36 UTC (rev 50613)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -362,9 +362,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $email_address
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // And now, all the Groups.
- $groups = get_post_meta( $request_id, '_export_data_grouped', true );
-
</del><span class="cx" style="display: block; padding: 0 10px"> // First, build an "About" group on the fly for this report.
</span><span class="cx" style="display: block; padding: 0 10px"> $about_group = array(
</span><span class="cx" style="display: block; padding: 0 10px"> /* translators: Header for the About section in a personal data export. */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -393,10 +390,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Merge in the special about group.
- $groups = array_merge( array( 'about' => $about_group ), $groups );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // And now, all the Groups.
+ $groups = get_post_meta( $request_id, '_export_data_grouped', true );
+ if ( is_array( $groups ) ) {
+ // Merge in the special "About" group.
+ $groups = array_merge( array( 'about' => $about_group ), $groups );
+ $groups_count = count( $groups );
+ } else {
+ if ( false !== $groups ) {
+ _doing_it_wrong(
+ __FUNCTION__,
+ /* translators: %s: Post meta key. */
+ sprintf( __( 'The %s post meta must be an array.' ), '<code>_export_data_grouped</code>' ),
+ '5.8.0'
+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $groups_count = count( $groups );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $groups = null;
+ $groups_count = 0;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Convert the groups to JSON format.
</span><span class="cx" style="display: block; padding: 0 10px"> $groups_json = wp_json_encode( $groups );
</span></span></pre></div>
<a id="trunktestsphpunittestsprivacywpPrivacyGeneratePersonalDataExportFilephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php 2021-03-29 18:05:47 UTC (rev 50612)
+++ trunk/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php 2021-03-29 19:35:36 UTC (rev 50613)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -214,6 +214,75 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 51423
+ *
+ * @dataProvider data_export_data_grouped_invalid_type
+ *
+ * @param mixed $groups '_export_data_grouped' post meta value.
+ */
+ public function test_doing_it_wrong_for_export_data_grouped_invalid_type( $groups ) {
+ update_post_meta( self::$export_request_id, '_export_data_grouped', $groups );
+
+ $this->setExpectedIncorrectUsage( 'wp_privacy_generate_personal_data_export_file' );
+
+ wp_privacy_generate_personal_data_export_file( self::$export_request_id );
+ }
+
+ public function data_export_data_grouped_invalid_type() {
+ return array(
+ array( 10 ),
+ array( 'WordPress' ),
+ array( null ),
+ array( true ),
+ array( false ),
+ array( new stdClass() ),
+ array( serialize( array( 10, 'WordPress', null, true, false ) ) ),
+ array(
+ json_encode(
+ array(
+ 'user' => array(
+ 'group_label' => 'User',
+ 'group_description' => 'User’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',
+ ),
+ ),
+ ),
+ ),
+ )
+ ),
+ ),
+ );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Test that an index.php file can be added to the export directory.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 44233
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -240,29 +309,42 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Test the export HTML file has all the expected parts.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 44233
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 46894
+ * @ticket 51423
+ *
+ * @dataProvider data_contents
+ *
+ * @param mixed $groups '_export_data_grouped' post meta value.
+ * @param string[] $expected_content Optional. Expected content. Use "html" key for this test.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_html_contents( $groups, array $expected_content = array() ) {
+ // Set the _doing_it_wrong assertion.
+ if ( ! is_array( $groups ) ) {
+ $this->setExpectedIncorrectUsage( 'wp_privacy_generate_personal_data_export_file' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $report_dir = trailingslashit( self::$exports_dir . 'test_contents' );
- mkdir( $report_dir );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $request = wp_get_user_request( self::$export_request_id );
+ $report_dir = $this->setup_export_contents_test( $groups );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $zip = new ZipArchive();
- $opened_zip = $zip->open( $this->export_file_name );
- $this->assertTrue( $opened_zip );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertFileExists( $report_dir . 'index.html' );
+ $actual_contents = file_get_contents( $report_dir . 'index.html' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $zip->extractTo( $report_dir );
- $zip->close();
- $this->assertTrue( file_exists( $report_dir . 'index.html' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected = "<!DOCTYPE html>\n";
+ $expected .= "<html>\n";
+ $expected .= "<head>\n";
+ $expected .= "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n";
+ $expected .= "<style type='text/css'>body { color: black; font-family: Arial, sans-serif; font-size: 11pt; margin: 15px auto; width: 860px; }table { background: #f0f0f0; border: 1px solid #ddd; margin-bottom: 20px; width: 100%; }th { padding: 5px; text-align: left; width: 20%; }td { padding: 5px; }tr:nth-child(odd) { background-color: #fafafa; }.return-to-top { text-align: right; }</style><title>Personal Data Export for {$request->email}</title></head>\n";
+ $expected .= "<body>\n";
+ $expected .= '<h1 id="top">Personal Data Export</h1>';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $report_contents = file_get_contents( $report_dir . 'index.html' );
- $request = wp_get_user_request( self::$export_request_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_array( $groups ) && isset( $expected_content['html'] ) ) {
+ $expected .= $this->replace_timestamp_placeholder( $actual_contents, $expected_content['html'] );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $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 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected .= "</body>\n";
+ $expected .= "</html>\n";
+
+ $this->assertSame( $expected, $actual_contents );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -269,39 +351,51 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Test the export JSON file has all the expected parts.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 49029
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 46894
+ * @ticket 51423
+ *
+ * @dataProvider data_contents
+ *
+ * @param mixed $groups '_export_data_grouped' post meta value.
+ * @param string[] $expected_content Optional. Expected content. Use "json" key for this test.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_json_contents( $groups, array $expected_content = array() ) {
+ // Set the _doing_it_wrong assertion.
+ if ( ! is_array( $groups ) ) {
+ $this->setExpectedIncorrectUsage( 'wp_privacy_generate_personal_data_export_file' );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $report_dir = trailingslashit( self::$exports_dir . 'test_contents' );
- mkdir( $report_dir );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $request = wp_get_user_request( self::$export_request_id );
+ $report_dir = $this->setup_export_contents_test( $groups );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $zip = new ZipArchive();
- $opened_zip = $zip->open( $this->export_file_name );
- $this->assertTrue( $opened_zip );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertFileExists( $report_dir . 'index.html' );
+ $actual_json = file_get_contents( $report_dir . 'export.json' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $zip->extractTo( $report_dir );
- $zip->close();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expected = '{"Personal Data Export for ' . $request->email . '":';
+ if ( ! is_array( $groups ) ) {
+ $expected .= 'null}';
+ } else {
+ // "About" group: to avoid time difference, use the report's "on" timestamp.
+ $about_group = '{"about":{"group_label":"About","group_description":"Overview of export report.","items":{"about-1":[{"name":"Report generated for","value":"' . $request->email . '"},{"name":"For site","value":"Test Blog"},{"name":"At URL","value":"http:\/\/example.org"},{"name":"On","value":"{{TIMESTAMP}}"}]}}';
+ $expected .= $this->replace_timestamp_placeholder( $actual_json, $about_group );
+ if ( isset( $expected_content['json'] ) ) {
+ $expected .= $expected_content['json'];
+ }
+ $expected .= '}}';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $request = wp_get_user_request( self::$export_request_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertSame( $expected, $actual_json );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertTrue( file_exists( $report_dir . 'export.json' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private function setup_export_contents_test( $export_data_grouped = null ) {
+ if ( null === $export_data_grouped ) {
+ delete_post_meta( self::$export_request_id, '_export_data_grouped' );
+ } else {
+ update_post_meta( self::$export_request_id, '_export_data_grouped', $export_data_grouped );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $report_contents_json = file_get_contents( $report_dir . 'export.json' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->expectOutputString( '' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $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( '' );
</del><span class="cx" style="display: block; padding: 0 10px"> wp_privacy_generate_personal_data_export_file( self::$export_request_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertTrue( file_exists( $this->export_file_name ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -314,344 +408,213 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $zip->extractTo( $report_dir );
</span><span class="cx" style="display: block; padding: 0 10px"> $zip->close();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertTrue( file_exists( $report_dir . 'index.html' ) );
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $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 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $report_dir;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Test the export HTML file containing ore than one export group has a table of contents.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Replace expected content's timestamp placeholder with the actual content's timestamp.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @ticket 46894
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Used when the expected content has a placeholder, i.e. used to avoid second time differences
+ * between the test and code.
+ *
+ * @param string $actual_content Content with the actual timestamp.
+ * @param string $expected_content Expected content that has the timestamp placeholder
+ * to be replaced with the actual timestamp.
+ * @return string Updated expected content on success; else original expected content.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_multiple_group_export_has_toc_and_return_to_top() {
- $this->expectOutputString( '' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private function replace_timestamp_placeholder( $actual_content, $expected_content ) {
+ $placeholder_pos = stripos( $expected_content, '{{TIMESTAMP}}' );
+ if ( false === $placeholder_pos ) {
+ return $expected_content;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Setup Export Data to contain multiple groups
- $export_data_grouped = array(
- 'user' => array(
- 'group_label' => 'User',
- 'group_description' => 'User’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 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $needle = substr( $expected_content, 0, $placeholder_pos );
+ $needle_pos = strpos( $actual_content, $needle ) + strlen( $needle );
+ $timestamp = substr( $actual_content, $needle_pos, 19 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 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 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return str_replace( '{{TIMESTAMP}}', $timestamp, $expected_content );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * 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’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',
- ),
- ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function data_contents() {
+ return array(
+ // Unhappy path.
+ 'should contain null when integer' => array(
+ 'groups' => 10,
+ ),
+ 'should contain null when boolean' => array(
+ 'groups' => true,
+ ),
+ 'should contain null when string' => array(
+ 'groups' => 'string',
+ ),
+ 'should contain null when object' => array(
+ 'groups' => new stdClass(),
+ ),
+ 'should contain only about when _export_data_grouped does not exist' => array(
+ 'groups' => null,
+ ),
+ 'should contain only about when empty array' => array(
+ 'groups' => array(),
+ 'expected_content' => array(
+ 'html' => '<h2 id="about-about">About</h2><p>Overview of export report.</p><div><table><tbody><tr><th>Report generated for</th><td>export-requester@example.com</td></tr><tr><th>For site</th><td>Test Blog</td></tr><tr><th>At URL</th><td><a href="http://example.org">http://example.org</a></td></tr><tr><th>On</th><td>{{TIMESTAMP}}</td></tr></tbody></table></div>',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'comments' => array(
- 'group_label' => 'Comments',
- 'group_description' => 'User’s comment data.',
- 'items' => array(
- 'comment-2' => array(
- array(
- 'name' => 'Comment Author',
- 'value' => 'User Name',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Happy path.
+ 'should contain about and export data groups when single group exists' => array(
+ 'groups' => array(
+ 'user' => array(
+ 'group_label' => 'User',
+ 'group_description' => 'User’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',
+ ),
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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="noopener">http://localhost:8888/46894/2020/01/31/hello-world/#comment-2</a>',
- ),
</del><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '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="noopener">http://localhost:8888/46894/2020/01/31/hello-world/#comment-3</a>',
- ),
- ),
</del><span class="cx" style="display: block; padding: 0 10px"> ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'expected_content' => array(
+ 'html' => '<div id="table_of_contents"><h2>Table of Contents</h2><ul><li><a href="#about-about">About</a></li><li><a href="#user-user">User</a></li></ul></div><h2 id="about-about">About</h2><p>Overview of export report.</p><div><table><tbody><tr><th>Report generated for</th><td>export-requester@example.com</td></tr><tr><th>For site</th><td>Test Blog</td></tr><tr><th>At URL</th><td><a href="http://example.org">http://example.org</a></td></tr><tr><th>On</th><td>{{TIMESTAMP}}</td></tr></tbody></table><div class="return-to-top"><a href="#top"><span aria-hidden="true">↑ </span> Go
to top</a></div></div><h2 id="user-user">User</h2><p>User’s profile data.</p><div><table><tbody><tr><th>User ID</th><td>1</td></tr><tr><th>User Login Name</th><td>user_login</td></tr><tr><th>User Nice Name</th><td>User Name</td></tr><tr><th>User Email</th><td>export-requester@example.com</td></tr><tr><th>User Registration Date</th><td>2020-01-31 19:29:29</td></tr><tr><th>User Display Name</th><td>User Name</td></tr><tr><th>User Nickname</th><td>User</td></tr></tbody></table><div class="return-to-top"><a href="#top"><span aria-hidden="true">↑ </span> Go to top</a></div>&l
t;/div>',
+ 'json' => ',"user":{"group_label":"User","group_description":"User’s profile data.","items":{"user-1":[{"name":"User ID","value":1},{"name":"User Login Name","value":"user_login"},{"name":"User Nice Name","value":"User Name"},{"name":"User Email","value":"export-requester@example.com"},{"name":"User Registration Date","value":"2020-01-31 19:29:29"},{"name":"User Display Name","value":"User Name"},{"name":"User Nickname","value":"User"}]}}',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- );
- 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’s profile data.',
- 'items' => array(
- 'user-1' => array(
- array(
- 'name' => 'User ID',
- 'value' => 1,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'should contain about and export data groups when multiple groups exist' => array(
+ 'groups' => array(
+ 'user' => array(
+ 'group_label' => 'User',
+ 'group_description' => 'User’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',
+ ),
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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',
- ),
</del><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ),
- ),
- 'comments' => array(
- 'group_label' => 'Comments',
- 'group_description' => 'User’s comment data.',
- 'items' => array(
- 'comment-2' => array(
- array(
- 'name' => 'Comment Author',
- 'value' => 'User Name',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'comments' => array(
+ 'group_label' => 'Comments',
+ 'group_description' => 'User’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="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="noopener">http://localhost:8888/46894/2020/01/31/hello-world/#comment-3</a>',
+ ),
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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="noopener">http://localhost:8888/46894/2020/01/31/hello-world/#comment-2</a>',
- ),
</del><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'expected_content' => array(
+ 'html' => '<div id="table_of_contents"><h2>Table of Contents</h2><ul><li><a href="#about-about">About</a></li><li><a href="#user-user">User</a></li><li><a href="#comments-comments">Comments <span class="count">(2)</span></a></li></ul></div><h2 id="about-about">About</h2><p>Overview of export report.</p><div><table><tbody><tr><th>Report generated for</th><td>export-requester@example.com</td></tr><tr><th>For site</th><td>Test Blog</td></tr><tr><th>At URL</th><td><a href="http://example.org">http://example.org</a></td></tr><tr><th>On</th><td>{{TIMESTAMP}}</td></tr></tbody></table><d
iv class="return-to-top"><a href="#top"><span aria-hidden="true">↑ </span> Go to top</a></div></div><h2 id="user-user">User</h2><p>User’s profile data.</p><div><table><tbody><tr><th>User ID</th><td>1</td></tr><tr><th>User Login Name</th><td>user_login</td></tr><tr><th>User Nice Name</th><td>User Name</td></tr><tr><th>User Email</th><td>export-requester@example.com</td></tr><tr><th>User Registration Date</th><td>2020-01-31 19:29:29</td></tr><tr><th>User Display Name</th><td>User Name</td></tr><tr><th>User Nickname</th><td>User</td></tr></tbody></table><div class="return-to-top&qu
ot;><a href="#top"><span aria-hidden="true">↑ </span> Go to top</a></div></div><h2 id="comments-comments">Comments <span class="count">(2)</span></h2><p>User’s comment data.</p><div><table><tbody><tr><th>Comment Author</th><td>User Name</td></tr><tr><th>Comment Author Email</th><td>export-requester@example.com</td></tr><tr><th>Comment Author IP</th><td>::1</td></tr><tr><th>Comment Author User Agent</th><td>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</td></tr><tr><th>Comment Date</th><td>2020-01-31 19:55:19</td></tr><tr><th>Comment Content</th><td>Test</t
d></tr><tr><th>Comment URL</th><td><a href="http://localhost:8888/46894/2020/01/31/hello-world/#comment-2">http://localhost:8888/46894/2020/01/31/hello-world/#comment-2</a></td></tr></tbody></table><table><tbody><tr><th>Comment Author</th><td>User Name</td></tr><tr><th>Comment Author Email</th><td>export-requester@example.com</td></tr><tr><th>Comment Author IP</th><td>::1</td></tr><tr><th>Comment Author User Agent</th><td>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</td></tr><tr><th>Comment Date</th><td>2020-01-31 20:55:19</td></tr><tr><th>Comment Content</th><td>Test #2</td></tr><tr><th>Commen
t URL</th><td><a href="http://localhost:8888/46894/2020/01/31/hello-world/#comment-3">http://localhost:8888/46894/2020/01/31/hello-world/#comment-3</a></td></tr></tbody></table><div class="return-to-top"><a href="#top"><span aria-hidden="true">↑ </span> Go to top</a></div></div>',
+ 'json' => ',"user":{"group_label":"User","group_description":"User’s profile data.","items":{"user-1":[{"name":"User ID","value":1},{"name":"User Login Name","value":"user_login"},{"name":"User Nice Name","value":"User Name"},{"name":"User Email","value":"export-requester@example.com"},{"name":"User Registration Date","value":"2020-01-31 19:29:29"},{"name":"User Display Name","value":"User Name"},{"name":"User Nickname","value":"User"}]}},"comments":{"group_label":"Comments","group_description":"User’s comment data.","items":{"comment-2":[{"name&qu
ot;:"Comment Author","value":"User Name"},{"name":"Comment Author Email","value":"export-requester@example.com"},{"name":"Comment Author IP","value":"::1"},{"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"},{"name":"Comment Date","value":"2020-01-31 19:55:19"},{"name":"Comment Content","value":"Test"},{"name":"Comment URL","value":"<a href=\"http:\/\/localhost:8888\/46894\/2020\/01\/31\/hello-world\/#comment-2\" target=\"_blank\" rel=\"noopener\">http:\/\/localhost:8888\/46894\/2020\/01\/31\/hello-world\/#comment-2<\/a>"}],"comment-3":[{"name
":"Comment Author","value":"User Name"},{"name":"Comment Author Email","value":"export-requester@example.com"},{"name":"Comment Author IP","value":"::1"},{"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"},{"name":"Comment Date","value":"2020-01-31 20:55:19"},{"name":"Comment Content","value":"Test #2"},{"name":"Comment URL","value":"<a href=\"http:\/\/localhost:8888\/46894\/2020\/01\/31\/hello-world\/#comment-3\" target=\"_blank\" rel=\"noopener\">http:\/\/localhost:8888\/46894\/2020\/01\/31\/hello-world\/#comment-3<\/a>"}]}}',
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 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 );
-
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>