Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
56df70d
wp-admin/includes/privacy-tools.php: Fix a PHP 8.0 fatal "Parameter #…
xknown Nov 9, 2020
c44e87a
Sends json error when '_export_data_grouped' exists but not array.
hellofromtonya Nov 29, 2020
2ac2209
Removes extra fix to keep this PR focused on one function.
hellofromtonya Nov 29, 2020
f8edbcc
Merge branch 'master' into fix/php8.0/51423-wp-admin/includes/privacy…
hellofromtonya Nov 29, 2020
a1185ff
Adds tests for array_merge warning json error.
hellofromtonya Nov 29, 2020
79ac839
Abstracts setup for export contents to make it easier to add tests.
hellofromtonya Nov 29, 2020
901ff24
Adds tests to validate groups json behavior.
hellofromtonya Nov 29, 2020
00e73a0
Adds tests for json export to validate export data grouped.
hellofromtonya Nov 29, 2020
8ab0d23
Merge branch 'master' into fix/php8.0/51423-wp-admin/includes/privacy…
hellofromtonya Feb 5, 2021
324af66
Adds _doing_it_wrong when meta value exists but is not an array.
Mar 18, 2021
2f242e1
Updates the tests.
Mar 18, 2021
5baeff0
Fixes test naming.
Mar 18, 2021
ef28395
Fixes closing ) placement for __().
Mar 19, 2021
11551b8
Cast to array when not an array.
Mar 19, 2021
ae22009
Skip array_merge when not an array.
Mar 19, 2021
3a9db91
Make json contents test more robust.
Mar 19, 2021
47f7ba0
Remove extra fix (new PR).
Mar 22, 2021
2483915
Sets vars to match current values to ensure same report output results.
Mar 22, 2021
44d9507
Fixes tests.
Mar 22, 2021
11361ca
Adds more test data for invalid type.
Mar 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Abstracts setup for export contents to make it easier to add tests.
  • Loading branch information
hellofromtonya committed Nov 29, 2020
commit 79ac839f9e2b3581c97650f7d754352ef530e2eb
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,9 @@ public function test_can_succeed() {
*/
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 ) );

$report_dir = trailingslashit( self::$exports_dir . 'test_contents' );
mkdir( $report_dir );
$report_dir = $this->setup_export_contents_test();

$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' );
Expand All @@ -353,18 +344,8 @@ public function test_html_contents() {
*/
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();
$report_dir = $this->setup_export_contents_test();

$request = wp_get_user_request( self::$export_request_id );

Expand All @@ -383,18 +364,9 @@ public function test_json_contents() {
*/
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 );
$report_dir = $this->setup_export_contents_test();

$zip->extractTo( $report_dir );
$zip->close();
$this->assertTrue( file_exists( $report_dir . 'index.html' ) );

$report_contents = file_get_contents( $report_dir . 'index.html' );
Expand Down Expand Up @@ -452,24 +424,9 @@ public function test_multiple_group_export_has_toc_and_return_to_top() {
),
),
);
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 );
$report_dir = $this->setup_export_contents_test( $export_data_grouped );

$zip->extractTo( $report_dir );
$zip->close();
$this->assertTrue( file_exists( $report_dir . 'index.html' ) );

$report_contents = file_get_contents( $report_dir . 'index.html' );
Expand Down Expand Up @@ -595,24 +552,9 @@ public function test_multiple_group_export_multiple_items_group_count_in_toc() {
),
),
);
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 ) );
$report_dir = $this->setup_export_contents_test( $export_data_grouped );

// 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' );
Expand Down Expand Up @@ -707,15 +649,30 @@ public function test_multiple_group_export_single_items_no_group_count_in_toc()
),
),
);
update_post_meta( self::$export_request_id, '_export_data_grouped', $export_data_grouped );

// Generate Export File
$report_dir = $this->setup_export_contents_test( $export_data_grouped );

$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 );
}

private function setup_export_contents_test( $export_data_grouped = null ) {
// Setup Export Data to contain multiple groups.
if ( null !== $export_data_grouped ) {
update_post_meta( self::$export_request_id, '_export_data_grouped', $export_data_grouped );
}

$this->expectOutputString( '' );

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 );

Expand All @@ -725,14 +682,7 @@ public function test_multiple_group_export_single_items_no_group_count_in_toc()

$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 );

return $report_dir;
}
}