65758 added check for post status in wp_privacy_send_personal_data_export_email() - #12759
65758 added check for post status in wp_privacy_send_personal_data_export_email()#12759pbearne wants to merge 11 commits into
Conversation
This reverts commit ad5031e.
This reverts commit 1e26103.
…_export_email() Co-authored-by: Junie <[email protected]>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @[email protected]. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Pull request overview
This pull request tightens the behavior of wp_privacy_send_personal_data_export_email() by ensuring it only sends export emails for requests in appropriate lifecycle states, and updates locale-related tests to confirm the correct request.
Changes:
- Add a request status validation gate to
wp_privacy_send_personal_data_export_email()(only allowrequest-confirmed/request-completed). - Fix two unit tests to confirm the newly-created request ID (instead of the shared fixture request ID) before attempting to send an export email.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php | Updates locale-related tests to confirm the correct request before sending the export email. |
| src/wp-admin/includes/privacy-tools.php | Adds request status validation to prevent sending export emails for requests in invalid states. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
src/wp-admin/includes/privacy-tools.php:604
- This new status guard is a behavior change (requests in request-pending/request-failed will now return WP_Error instead of attempting to send). There doesn’t appear to be a targeted unit test asserting the new failure mode for wp_privacy_send_personal_data_export_email(); the updated export-page test currently hits this guard only because the fixture request is unconfirmed.
Add a dedicated test in tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php that creates an export_personal_data request, leaves it unconfirmed (or marks it request-failed), and asserts a WP_Error is returned with this message.
if ( ! in_array( $request->status, array( 'request-confirmed', 'request-completed' ), true ) ) {
return new WP_Error( 'invalid_request', __( 'Invalid request status when sending personal data export email.' ) );
}
tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:506
- This test is named and documented as exercising the wp_mail() failure path, but it now expects the new “Invalid request status…” message. That happens because the shared request fixture (self::$request_id) is created as request-pending and never confirmed in this test class, so wp_privacy_send_personal_data_export_email() bails out before attempting to send mail. This makes the test stop validating the intended behavior and can hide regressions in the actual mail-failure handling.
Create and confirm a request for this test (or confirm the existing one) and keep asserting the “Unable to send…” message to ensure you’re testing the wp_mail() failure branch.
public function test_send_error_on_last_page_of_last_exporter_when_mail_delivery_fails() {
// Cause `wp_mail()` to return false, to simulate mail delivery failure. Filter removed in tearDown.
add_filter( 'wp_mail_from', '__return_empty_string' );
// Process data, given the last exporter, on the last page and send as email.
$this->_setup_expected_failure( '{"success":false,"data":"Invalid request status when sending personal data export email."}' );
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:506
- This test is named and documented as a mail-delivery-failure scenario, but it now expects an "Invalid request status" error. Because the shared fixture request created in wpSetUpBeforeClass() is never confirmed (it stays
request-pending),wp_privacy_send_personal_data_export_email()returns early on the new status check andwp_mail()is never exercised—making thewp_mail_fromfilter irrelevant and leaving the mail-failure behavior untested in this code path.
To keep this test aligned with its intent, confirm the request before processing and restore the expected message for an actual wp_mail() failure. If you also want coverage for the new invalid-status guard, add a separate test that leaves the request unconfirmed and asserts the new message.
// Cause `wp_mail()` to return false, to simulate mail delivery failure. Filter removed in tearDown.
add_filter( 'wp_mail_from', '__return_empty_string' );
// Process data, given the last exporter, on the last page and send as email.
$this->_setup_expected_failure( '{"success":false,"data":"Invalid request status when sending personal data export email."}' );
mindctrl
left a comment
There was a problem hiding this comment.
I'm getting multiple test failures running the privacy group of tests.
npm run test:php -- --group privacy
There were 6 errors:
1) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_wp_privacy_process_personal_data_export_page with data set #4 (array(true, array()))
WPDieException:
/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:274
2) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_raw_data_post_meta with data set #0 (true)
WPDieException:
/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:443
3) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_add_post_meta_with_groups_data_only_available_when_export_file_generated with data set #0 (true)
WPDieException:
/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:482
4) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_add_post_meta_with_groups_data_only_available_when_export_file_generated with data set #1 (false)
WPDieException:
/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:482
5) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_return_response_without_export_file_url_when_sent_as_email_for_last_exporter_on_last_page
WPDieException:
/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:555
6) Tests_Privacy_wpPrivacyProcessPersonalDataExportPage::test_request_status_transitions_correctly with data set #0 ('request-completed', 'last', 'last', 'last', true, 'last')
WPDieException:
/var/www/tests/phpunit/includes/abstract-testcase.php:578
/var/www/src/wp-includes/functions.php:3890
/var/www/src/wp-includes/functions.php:4611
/var/www/src/wp-includes/functions.php:4684
/var/www/src/wp-admin/includes/privacy-tools.php:884
/var/www/tests/phpunit/tests/privacy/wpPrivacyProcessPersonalDataExportPage.php:609
ERRORS!
Tests: 250, Assertions: 508, Errors: 6.
It looks like we need more lines similar to this: _wp_privacy_account_request_confirmed( self::$request_id ); to confirm the request.
…rtPage tests Co-authored-by: Junie <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/wp-admin/includes/privacy-tools.php:604
- The new status gate is a behavior change (requests in
request-pending/other statuses will now error). Please add a unit test covering this path (e.g., create anexport_personal_datauser request left inrequest-pendingand assertwp_privacy_send_personal_data_export_email()returns aWP_Errorwith the expected error code/message), to prevent regressions and document the intended contract.
if ( ! in_array( $request->status, array( 'request-confirmed', 'request-completed' ), true ) ) {
return new WP_Error( 'invalid_request', __( 'Invalid request status when sending personal data export email.' ) );
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/wp-admin/includes/privacy-tools.php:604
- The new request-status guard changes behavior (pending/failed requests now return a WP_Error) but there’s no unit test asserting this new failure mode. Adding a PHPUnit test (e.g., set the request post_status to
request-pendingand assertwp_privacy_send_personal_data_export_email()returnsinvalid_request) would prevent regressions and document the intended contract.
if ( ! in_array( $request->status, array( 'request-confirmed', 'request-completed' ), true ) ) {
return new WP_Error( 'invalid_request', __( 'Invalid request status when sending personal data export email.' ) );
}
Trac ticket: https://core.trac.wordpress.org/ticket/65758