-
Notifications
You must be signed in to change notification settings - Fork 3.2k
51423: wp_privacy_process_personal_data_export_page() fixes type match for array_merge (PHP 8) #776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hellofromtonya
wants to merge
2
commits into
WordPress:master
Choose a base branch
from
hellofromtonya:fix/php8.0/51423-wp_privacy_process_personal_data_export_page
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,7 +160,21 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { | |
| self::$exporter_key_first = 'custom-exporter-first'; | ||
| self::$exporter_key_last = 'custom-exporter-last'; | ||
|
|
||
| $data = array( | ||
| $data = self::get_response_data(); | ||
|
|
||
| self::$response_first_page = array( | ||
| 'done' => false, | ||
| 'data' => $data, | ||
| ); | ||
|
|
||
| self::$response_last_page = array( | ||
| 'done' => true, | ||
| 'data' => $data, | ||
| ); | ||
| } | ||
|
|
||
| private static function get_response_data() { | ||
| return array( | ||
| array( | ||
| 'group_id' => 'custom-exporter-group-id', | ||
| 'group_label' => 'Custom Exporter Group Label', | ||
|
|
@@ -169,21 +183,11 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { | |
| 'data' => array( | ||
| array( | ||
| 'name' => 'Email', | ||
| 'value' => self::$requester_email, | ||
| 'value' => '[email protected]', | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| self::$response_first_page = array( | ||
| 'done' => false, | ||
| 'data' => $data, | ||
| ); | ||
|
|
||
| self::$response_last_page = array( | ||
| 'done' => true, | ||
| 'data' => $data, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -412,6 +416,115 @@ public function test_send_error_when_invalid_request_action_name( $send_as_email | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * The function should store export raw data. | ||
| * | ||
| * @ticket 51423 | ||
| * | ||
| * @dataProvider data_stores_raw_export_data | ||
| * | ||
| * @param string $response The response from the personal data exporter for the given page. | ||
| * @param int $exporter_index The index of the personal data exporter. Begins at 1. | ||
| * @param int $page The page of personal data for this exporter. Begins at 1. | ||
| * @param array $expected Expected '_export_data_raw' meta. | ||
| */ | ||
| public function test_should_stores_raw_export_data( $response, $exporter_index, $page, $expected, $export_data = null ) { | ||
| if ( null === $export_data ) { | ||
| $this->assertEmpty( get_post_meta( self::$request_id, '_export_data_raw', true ) ); | ||
| } else { | ||
| update_post_meta( self::$request_id, '_export_data_raw', $export_data ); | ||
| } | ||
|
|
||
| // Set to bail out to avoid post meta from being deleted. | ||
| $response['done'] = false; | ||
| $expect_error = ( null !== $export_data && ! is_array( $export_data ) ); | ||
|
|
||
| if ( $expect_error ) { | ||
| $this->_setup_expected_failure( '{"success":false,"data":"Warning: array_merge(): Expected parameter 1 to be an array, ' . gettype( $export_data ) . ' given."}' ); | ||
| } else { | ||
| $this->expectOutputString( '' ); | ||
| } | ||
|
|
||
| wp_privacy_process_personal_data_export_page( | ||
| $response, | ||
| $exporter_index, | ||
| self::$requester_email, | ||
| $page, | ||
| self::$request_id, | ||
| true, | ||
| self::$exporter_key_first | ||
| ); | ||
|
|
||
| $actual = get_post_meta( self::$request_id, '_export_data_raw', true ); | ||
| $this->assertSame( $expected, $actual ); | ||
| } | ||
|
|
||
| public function data_stores_raw_export_data() { | ||
| $data = self::get_response_data(); | ||
| $export_data = array( 'test' => 'data' ); | ||
| $merged_export_data = array_merge( $export_data, $data ); | ||
|
|
||
| return array( | ||
| '1st exporter & page 1 with no export data stores response[data]' => array( | ||
| 'response' => array( | ||
| 'done' => false, | ||
| 'data' => $data, | ||
| ), | ||
| 'exporter_index' => 1, | ||
| 'page' => 1, | ||
| 'expected' => $data, | ||
| ), | ||
| '1st exporter & page 1 with (array) export data stores response[data]' => array( | ||
| 'response' => array( | ||
| 'done' => false, | ||
| 'data' => $data, | ||
| ), | ||
| 'exporter_index' => 1, | ||
| 'page' => 1, | ||
| 'expected' => $data, | ||
| 'export_data' => $export_data, | ||
| ), | ||
| 'not 1st exporter with no export data stores response[data]' => array( | ||
| 'response' => array( | ||
| 'done' => false, | ||
| 'data' => $data, | ||
| ), | ||
| 'exporter_index' => 2, | ||
| 'page' => 1, | ||
| 'expected' => $data, | ||
| ), | ||
| 'not 1st exporter with (array) export data stores export data merged with response[data]' => array( | ||
| 'response' => array( | ||
| 'done' => false, | ||
| 'data' => $data, | ||
| ), | ||
| 'exporter_index' => 2, | ||
| 'page' => 1, | ||
| 'expected' => $merged_export_data, | ||
| 'export_data' => $export_data, | ||
| ), | ||
| '1st exporter, page > 1, with (string) export data updates export data merged with response[data]' => array( | ||
| 'response' => array( | ||
| 'done' => false, | ||
| 'data' => $data, | ||
| ), | ||
| 'exporter_index' => 1, | ||
| 'page' => 2, | ||
| 'expected' => $data, | ||
| 'export_data' => 'not an array', | ||
| ), | ||
| 'not 1st exporter, page 1, no export data updates to response[data]' => array( | ||
| 'response' => array( | ||
| 'done' => false, | ||
| 'data' => $data, | ||
| ), | ||
| 'exporter_index' => 2, | ||
| 'page' => 1, | ||
| 'expected' => $data, | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * The function should store export raw data until the export finishes. Then the meta key should be deleted. | ||
| * | ||
|
|
@@ -420,7 +533,6 @@ public function test_send_error_when_invalid_request_action_name( $send_as_email | |
| * @dataProvider data_send_as_email_options | ||
| * | ||
| * @param bool Whether the final results of the export should be emailed to the user. | ||
| * | ||
| */ | ||
| public function test_raw_data_post_meta( $send_as_email ) { | ||
| $this->assertEmpty( get_post_meta( self::$request_id, '_export_data_raw', true ) ); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserves the original warning when/if '_export_data_raw' exists but is not an array type.
< PHP 7.3
PHP 7.3-7.4
PHP 8
See it in action here https://3v4l.org/3EbKY