WordPress.org

Make WordPress Core

Ticket #43913: 43913.2.diff

File 43913.2.diff, 4.0 KB (added by birgire, 3 years ago)
  • src/wp-admin/includes/user.php

    diff --git src/wp-admin/includes/user.php src/wp-admin/includes/user.php
    index 4e9a836..d3d2961 100644
    function _wp_privacy_resend_request( $request_id ) { 
    609609}
    610610
    611611/**
    612  * Marks a request as completed by the admin and logs the datetime.
     612 * Marks a request as completed by the admin and logs the current timestamp.
    613613 *
    614614 * @since 4.9.6
    615615 * @access private
    616616 *
    617  * @param int $request_id Request ID.
    618  * @return int|WP_Error Request ID on succes or WP_Error.
     617 * @param  int          $request_id Request ID.
     618 * @return int|WP_Error $request    Request ID on success or WP_Error.
    619619 */
    620620function _wp_privacy_completed_request( $request_id ) {
    621621        $request_id   = absint( $request_id );
    function _wp_privacy_completed_request( $request_id ) { 
    625625                return new WP_Error( 'privacy_request_error', __( 'Invalid request.' ) );
    626626        }
    627627
    628         update_post_meta( $request_id, '_wp_user_request_confirmed_timestamp', time() );
     628        update_post_meta( $request_id, '_wp_user_request_completed_timestamp', time() );
    629629
    630630        $request = wp_update_post( array(
    631631                'ID'          => $request_id,
    632                 'post_status' => 'request-confirmed',
     632                'post_status' => 'request-completed',
    633633        ) );
    634634
    635635        return $request;
    abstract class WP_Privacy_Requests_Table extends WP_List_Table { 
    10161016                }
    10171017
    10181018                $query = "
    1019                         SELECT post_status, COUNT( * ) AS num_posts 
    1020                         FROM {$wpdb->posts} 
     1019                        SELECT post_status, COUNT( * ) AS num_posts
     1020                        FROM {$wpdb->posts}
    10211021                        WHERE post_type = %s
    10221022                        AND post_name = %s
    10231023                        GROUP BY post_status";
  • new file tests/phpunit/tests/privacy/wpPrivacyCompletedRequest.php

    diff --git tests/phpunit/tests/privacy/wpPrivacyCompletedRequest.php tests/phpunit/tests/privacy/wpPrivacyCompletedRequest.php
    new file mode 100644
    index 0000000..d6d7404
    - +  
     1<?php
     2/**
     3 * Test the `_wp_privacy_completed_request()` function.
     4 *
     5 * @package WordPress\UnitTests
     6 *
     7 * @since 4.9.6
     8 */
     9
     10/**
     11 * Tests_PrivacyCompletedRequest class.
     12 *
     13 * @group privacy
     14 * @covers _wp_privacy_completed_request
     15 *
     16 * @since 4.9.6
     17 */
     18class Tests_PrivacyCompletedRequest extends WP_UnitTestCase {
     19        /**
     20         * Request ID
     21         *
     22         * @since 4.9.6
     23         *
     24         * @var int $request_id
     25         */
     26        protected static $request_id;
     27
     28        /**
     29         * Create fixtures.
     30         *
     31         * @param WP_UnitTest_Factory $factory Factory.
     32         */
     33        public static function wpSetUpBeforeClass( $factory ) {
     34                self::$request_id = wp_create_user_request( 'requester@example.com', 'export_personal_data' );
     35        }
     36
     37        /**
     38         * The function should return error for invalid request ID.
     39         *
     40         * @ticket 43913
     41         */
     42        public function test__wp_privacy_completed_request_should_return_error_for_invalid_request_id() {
     43                $actual = _wp_privacy_completed_request( 0 );
     44                $this->assertWPError( $actual );
     45                $this->assertSame( 'privacy_request_error', $actual->get_error_code() );
     46
     47                $actual = _wp_privacy_completed_request( PHP_INT_MAX );
     48                $this->assertWPError( $actual );
     49                $this->assertSame( 'privacy_request_error', $actual->get_error_code() );
     50        }
     51
     52        /**
     53         * The function should mark a request as completed.
     54         *
     55         * @ticket 43913
     56         */
     57        public function test__wp_privacy_completed_request_should_mark_request_completed() {
     58                $this->assertSame( 'request-pending', get_post_status( self::$request_id ) );
     59                $this->assertSame( self::$request_id, _wp_privacy_completed_request( self::$request_id ) );
     60                $this->assertSame( 'request-completed', get_post_status( self::$request_id ) );
     61        }
     62
     63        /**
     64         * The function should log the request timestamp.
     65         *
     66         * @ticket 43913
     67         */
     68        public function test__wp_privacy_completed_request_should_log_request_timestamp() {
     69                $this->assertEmpty( get_post_meta( self::$request_id, '_wp_user_request_completed_timestamp', true ) );
     70                $this->assertSame( self::$request_id, _wp_privacy_completed_request( self::$request_id ) );
     71                $this->assertNotEmpty( get_post_meta( self::$request_id, '_wp_user_request_completed_timestamp', true ) );
     72        }
     73}