From a583f61558cbe10742b1bb02335f3c62b6d16b7e Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Tue, 8 May 2018 23:28:47 +0000 Subject: [PATCH] Privacy: Mark processed requests as completed instead of confirmed. r43008 refactored the request flow to make several improvements, but accidentally marked `completed` requests as `confirmed`. This commit restores the intended statuses, so that the data and corresponding UI reflect reality. Props allendav, birgire. Fixes #43913. git-svn-id: https://develop.svn.wordpress.org/trunk@43183 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/user.php | 10 +-- .../privacy/wpPrivacyCompletedRequest.php | 73 +++++++++++++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 tests/phpunit/tests/privacy/wpPrivacyCompletedRequest.php diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php index 3c5c4ae72d..2d3d276dcc 100644 --- a/src/wp-admin/includes/user.php +++ b/src/wp-admin/includes/user.php @@ -609,13 +609,13 @@ function _wp_privacy_resend_request( $request_id ) { } /** - * Marks a request as completed by the admin and logs the datetime. + * Marks a request as completed by the admin and logs the current timestamp. * * @since 4.9.6 * @access private * - * @param int $request_id Request ID. - * @return int|WP_Error Request ID on succes or WP_Error. + * @param int $request_id Request ID. + * @return int|WP_Error $request Request ID on success or WP_Error. */ function _wp_privacy_completed_request( $request_id ) { $request_id = absint( $request_id ); @@ -625,11 +625,11 @@ function _wp_privacy_completed_request( $request_id ) { return new WP_Error( 'privacy_request_error', __( 'Invalid request.' ) ); } - update_post_meta( $request_id, '_wp_user_request_confirmed_timestamp', time() ); + update_post_meta( $request_id, '_wp_user_request_completed_timestamp', time() ); $request = wp_update_post( array( 'ID' => $request_id, - 'post_status' => 'request-confirmed', + 'post_status' => 'request-completed', ) ); return $request; diff --git a/tests/phpunit/tests/privacy/wpPrivacyCompletedRequest.php b/tests/phpunit/tests/privacy/wpPrivacyCompletedRequest.php new file mode 100644 index 0000000000..71884dc7d8 --- /dev/null +++ b/tests/phpunit/tests/privacy/wpPrivacyCompletedRequest.php @@ -0,0 +1,73 @@ +assertWPError( $actual ); + $this->assertSame( 'privacy_request_error', $actual->get_error_code() ); + + $actual = _wp_privacy_completed_request( PHP_INT_MAX ); + $this->assertWPError( $actual ); + $this->assertSame( 'privacy_request_error', $actual->get_error_code() ); + } + + /** + * The function should mark a request as completed. + * + * @ticket 43913 + */ + public function test_wp_privacy_completed_request_should_mark_request_completed() { + $this->assertSame( 'request-pending', get_post_status( self::$request_id ) ); + $this->assertSame( self::$request_id, _wp_privacy_completed_request( self::$request_id ) ); + $this->assertSame( 'request-completed', get_post_status( self::$request_id ) ); + } + + /** + * The function should log the request timestamp. + * + * @ticket 43913 + */ + public function test_wp_privacy_completed_request_should_log_request_timestamp() { + $this->assertEmpty( get_post_meta( self::$request_id, '_wp_user_request_completed_timestamp', true ) ); + $this->assertSame( self::$request_id, _wp_privacy_completed_request( self::$request_id ) ); + $this->assertNotEmpty( get_post_meta( self::$request_id, '_wp_user_request_completed_timestamp', true ) ); + } +}