Make WordPress Core

Ticket #46894: 46894.6.diff

File 46894.6.diff, 28.4 KB (added by garrett-eclipse, 4 years ago)

Updated patch to include Group Counts on the TOC items, suppress Return to Top when only About group and introduce Unit Test coverage for these additions.

  • src/wp-admin/includes/privacy-tools.php

     
    215215 * Generate a single group for the personal data export report.
    216216 *
    217217 * @since 4.9.6
     218 * @since 5.4.0 Added $group_id to support the TOC implementation.
    218219 *
    219  * @param array $group_data {
     220 * @param array  $group_data {
    220221 *     The group data to render.
    221222 *
    222223 *     @type string $group_label  The user-facing heading for the group, e.g. 'Comments'.
     
    231232 *         }
    232233 *     }
    233234 * }
     235 * @param string $group_id The group identifier.
     236 * @param int    $groups_count The number of all groups
    234237 * @return string The HTML for this group and its items.
    235238 */
    236 function wp_privacy_generate_personal_data_export_group_html( $group_data ) {
    237         $group_html  = '<h2>';
     239function wp_privacy_generate_personal_data_export_group_html( $group_data, $group_id = '', $groups_count = 1 ) {
     240        $group_id_attr = sanitize_title_with_dashes( $group_data['group_label'] . '-' . $group_id );
     241
     242        $group_html  = '<h2 id="' . esc_attr( $group_id_attr ) . '">';
    238243        $group_html .= esc_html( $group_data['group_label'] );
    239244
    240245        $items_count = count( (array) $group_data['items'] );
     
    271276                $group_html .= '</table>';
    272277        }
    273278
     279        if ( 1 < $groups_count ) {
     280                $group_html .= '<div class="return_to_top">';
     281                $group_html .= '<a href="#top">' . esc_html__( '&uarr; Return to top' ) . '</a>';
     282                $group_html .= '</div>';
     283        }
     284
    274285        $group_html .= '</div>';
    275286
    276287        return $group_html;
     
    371382
    372383        // Merge in the special about group.
    373384        $groups = array_merge( array( 'about' => $about_group ), $groups );
     385        $groups_count = count( $groups );
    374386
    375387        // Convert the groups to JSON format.
    376388        $groups_json = wp_json_encode( $groups );
     
    409421        fwrite( $file, 'th { padding: 5px; text-align: left; width: 20%; }' );
    410422        fwrite( $file, 'td { padding: 5px; }' );
    411423        fwrite( $file, 'tr:nth-child(odd) { background-color: #fafafa; }' );
     424        fwrite( $file, '.return_to_top { text-align:right; }' );
    412425        fwrite( $file, '</style>' );
    413426        fwrite( $file, '<title>' );
    414427        fwrite( $file, esc_html( $title ) );
     
    415428        fwrite( $file, '</title>' );
    416429        fwrite( $file, "</head>\n" );
    417430        fwrite( $file, "<body>\n" );
    418         fwrite( $file, '<h1>' . esc_html__( 'Personal Data Export' ) . '</h1>' );
     431        fwrite( $file, '<h1 id="top">' . esc_html__( 'Personal Data Export' ) . '</h1>' );
    419432
     433        // Create TOC.
     434        if ( 1 < $groups_count ) {
     435                fwrite( $file, '<div id="table_of_contents">' );
     436                fwrite( $file, '<h2>' . esc_html__( 'Table of Contents' ) . '</h2>' );
     437                fwrite( $file, '<ul>' );
     438                foreach ( (array) $groups as $group_id => $group_data ) {
     439                        $group_label = esc_html( $group_data['group_label'] );
     440                        $group_id_attr = sanitize_title_with_dashes( $group_data['group_label'] . '-' . $group_id );
     441                        $group_items_count = count( (array) $group_data['items'] );
     442                        if ( $group_items_count > 1 ) {
     443                                $group_label .= sprintf( ' <span class="count">(%d)</span>', $group_items_count );
     444                        }
     445                        fwrite( $file, '<li>' );
     446                        fwrite( $file, '<a href="#' . esc_attr( $group_id_attr ) . '">' . $group_label . '</a>' );
     447                        fwrite( $file, '</li>' );
     448                }
     449                fwrite( $file, '</ul>' );
     450                fwrite( $file, '</div>' );
     451        }
     452
    420453        // Now, iterate over every group in $groups and have the formatter render it in HTML.
    421454        foreach ( (array) $groups as $group_id => $group_data ) {
    422                 fwrite( $file, wp_privacy_generate_personal_data_export_group_html( $group_data ) );
     455                fwrite( $file, wp_privacy_generate_personal_data_export_group_html( $group_data, $group_id, $groups_count ) );
    423456        }
    424457
    425458        fwrite( $file, "</body>\n" );
  • src/wp-includes/user.php

     
    29592959
    29602960        $user_meta = get_user_meta( $user->ID );
    29612961
    2962         $user_prop_to_export = array(
     2962        $user_props_to_export = array(
    29632963                'ID'              => __( 'User ID' ),
    29642964                'user_login'      => __( 'User Login Name' ),
    29652965                'user_nicename'   => __( 'User Nice Name' ),
     
    29752975
    29762976        $user_data_to_export = array();
    29772977
    2978         foreach ( $user_prop_to_export as $key => $name ) {
     2978        foreach ( $user_props_to_export as $key => $name ) {
    29792979                $value = '';
    29802980
    29812981                switch ( $key ) {
     
    30123012                'data'              => $user_data_to_export,
    30133013        );
    30143014
     3015        /**
     3016         * Introduce any Community Events Location data that is available.
     3017         *
     3018         * @since 5.4.0
     3019         */
     3020        if ( isset( $user_meta[ 'community-events-location' ] ) ) {
     3021                $location = maybe_unserialize( $user_meta[ 'community-events-location' ][0] );
     3022
     3023                $location_props_to_export = array(
     3024                        'description' => __( 'City' ),
     3025                        'country'     => __( 'Country' ),
     3026                        'latitude'    => __( 'Latitude' ),
     3027                        'longitude'   => __( 'Longitude' ),
     3028                        'ip'          => __( 'IP' ),
     3029                );
     3030
     3031                $location_data_to_export = array();
     3032
     3033                foreach ( $location_props_to_export as $key => $name ) {
     3034                        if ( ! empty( $location[ $key ] ) ) {
     3035                                $location_data_to_export[] = array(
     3036                                        'name'  => $name,
     3037                                        'value' => $location[ $key ],
     3038                                );
     3039                        }
     3040                }
     3041               
     3042                $data_to_export[] = array(
     3043                        'group_id'          => 'community-events-location',
     3044                        'group_label'       => __( 'Community Events Location' ),
     3045                        'group_description' => __( 'User&#8217;s location data used for the Community Events in the WordPress Events and News dashboard widget.' ),
     3046                        'item_id'           => "community-events-location-{$user->ID}",
     3047                        'data'              => $location_data_to_export,
     3048                );
     3049        }
     3050
     3051        /**
     3052         * Introduce any Session Token data that is available.
     3053         *
     3054         * @since 5.4.0
     3055         */
     3056        if ( isset( $user_meta[ 'session_tokens' ] ) ) {
     3057                $session_tokens = maybe_unserialize( $user_meta[ 'session_tokens' ][0] );
     3058
     3059                $session_tokens_props_to_export = array(
     3060                        'expiration' => __( 'Expiration' ),
     3061                        'ip'         => __( 'IP' ),
     3062                        'ua'         => __( 'User Agent' ),
     3063                        'login'      => __( 'Last Login' ),
     3064                );
     3065
     3066
     3067                foreach ( $session_tokens as $token_key => $session_token ) {
     3068                        $session_tokens_data_to_export = array();
     3069
     3070                        foreach ( $session_tokens_props_to_export as $key => $name ) {
     3071                                if ( ! empty( $session_token[ $key ] ) ) {
     3072                                        $value = $session_token[ $key ];
     3073                                        if ( in_array( $key, array( 'expiration', 'login' ) ) ) {
     3074                                                $value = date_i18n( 'F d, Y H:i A', $value );
     3075                                        }
     3076                                        $session_tokens_data_to_export[] = array(
     3077                                                'name'  => $name,
     3078                                                'value' => $value,
     3079                                        );
     3080                                }
     3081                        }
     3082
     3083                        $data_to_export[] = array(
     3084                                'group_id'          => 'session-tokens',
     3085                                'group_label'       => __( 'Session Tokens' ),
     3086                                'group_description' => __( 'User&#8217;s Session Tokens data.' ),
     3087                                'item_id'           => "session-tokens-{$user->ID}-{$token_key}",
     3088                                'data'              => $session_tokens_data_to_export,
     3089                        );
     3090                }
     3091        }
     3092
    30153093        return array(
    30163094                'data' => $data_to_export,
    30173095                'done' => true,
  • tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php

     
    260260                $report_contents = file_get_contents( $report_dir . 'index.html' );
    261261                $request         = wp_get_user_request_data( self::$export_request_id );
    262262
    263                 $this->assertContains( '<h1>Personal Data Export</h1>', $report_contents );
    264                 $this->assertContains( '<h2>About</h2>', $report_contents );
     263                $this->assertContains( '<h1 id="top">Personal Data Export</h1>', $report_contents );
     264                $this->assertContains( '<h2 id="about-about">About</h2>', $report_contents );
    265265                $this->assertContains( $request->email, $report_contents );
    266266        }
    267267
     
    294294                $this->assertContains( '"Personal Data Export for ' . $request->email . '"', $report_contents_json );
    295295                $this->assertContains( '"about"', $report_contents_json );
    296296        }
     297
     298        /**
     299         * Test the export HTML file containing one export group has no table of contents.
     300         *
     301         * @ticket 46894
     302         */
     303        public function test_single_group_export_no_toc_or_return_to_top() {
     304                $this->expectOutputString( '' );
     305                wp_privacy_generate_personal_data_export_file( self::$export_request_id );
     306                $this->assertTrue( file_exists( $this->export_file_name ) );
     307
     308                $report_dir = trailingslashit( self::$exports_dir . 'test_contents' );
     309                mkdir( $report_dir );
     310
     311                $zip        = new ZipArchive();
     312                $opened_zip = $zip->open( $this->export_file_name );
     313                $this->assertTrue( $opened_zip );
     314
     315                $zip->extractTo( $report_dir );
     316                $zip->close();
     317                $this->assertTrue( file_exists( $report_dir . 'index.html' ) );
     318
     319                $report_contents = file_get_contents( $report_dir . 'index.html' );
     320                $request         = wp_get_user_request_data( self::$export_request_id );
     321
     322                $this->assertNotContains( '<div id="table_of_contents">', $report_contents );
     323                $this->assertNotContains( '<div class="return_to_top">', $report_contents );
     324                $this->assertContains( $request->email, $report_contents );             
     325        }
     326
     327        /**
     328         * Test the export HTML file containing ore than one export group has a table of contents.
     329         *
     330         * @ticket 46894
     331         */
     332        public function test_multiple_group_export_has_toc_and_return_to_top() {
     333                $this->expectOutputString( '' );
     334
     335                // Setup Export Data to contain multiple groups
     336                $export_data_grouped = array(
     337                        'user' => array(
     338                                'group_label'       => 'User',
     339                                'group_description' => 'User&#8217;s profile data.',
     340                                'items'             => array(
     341                                        'user-1' => array(
     342                                                array(
     343                                                        'name'  => 'User ID',
     344                                                        'value' => 1
     345                                                ),
     346                                                array(
     347                                                        'name'  => 'User Login Name',
     348                                                        'value' => 'user_login'
     349                                                ),
     350                                                array(
     351                                                        'name'  => 'User Nice Name',
     352                                                        'value' => 'User Name'
     353                                                ),
     354                                                array(
     355                                                        'name'  => 'User Email',
     356                                                        'value' => 'export-requester@example.com'
     357                                                ),
     358                                                array(
     359                                                        'name'  => 'User Registration Date',
     360                                                        'value' => '2020-01-31 19:29:29'
     361                                                ),
     362                                                array(
     363                                                        'name'  => 'User Display Name',
     364                                                        'value' => 'User Name'
     365                                                ),
     366                                                array(
     367                                                        'name'  => 'User Nickname',
     368                                                        'value' => 'User'
     369                                                ),
     370                                        ),
     371                                ),
     372                        ),
     373                );
     374                update_post_meta( self::$export_request_id, '_export_data_grouped', $export_data_grouped );             
     375
     376                // Generate Export File
     377                wp_privacy_generate_personal_data_export_file( self::$export_request_id );
     378                $this->assertTrue( file_exists( $this->export_file_name ) );
     379
     380                // Cleam-up for subsequent tests
     381                update_post_meta( self::$export_request_id, '_export_data_grouped', array() );
     382
     383                $report_dir = trailingslashit( self::$exports_dir . 'test_contents' );
     384                mkdir( $report_dir );
     385
     386                $zip        = new ZipArchive();
     387                $opened_zip = $zip->open( $this->export_file_name );
     388                $this->assertTrue( $opened_zip );
     389
     390                $zip->extractTo( $report_dir );
     391                $zip->close();
     392                $this->assertTrue( file_exists( $report_dir . 'index.html' ) );
     393
     394                $report_contents = file_get_contents( $report_dir . 'index.html' );
     395                $request         = wp_get_user_request_data( self::$export_request_id );
     396
     397                $this->assertContains( '<div id="table_of_contents">', $report_contents );
     398                $this->assertContains( '<h2 id="user-user">User</h2>', $report_contents );
     399                $this->assertContains( '<div class="return_to_top">', $report_contents );
     400                $this->assertContains( $request->email, $report_contents );             
     401        }
     402
     403        /**
     404         * Test the export HTML file containing multiple export groups with multiple group items
     405         * has a table of contents with group count.
     406         *
     407         * @ticket 46894
     408         */
     409        public function test_multiple_group_export_multiple_items_group_count_in_toc() {
     410                $this->expectOutputString( '' );
     411
     412                // Setup Export Data to contain multiple groups
     413                $export_data_grouped = array(
     414                        'user' => array(
     415                                'group_label'       => 'User',
     416                                'group_description' => 'User&#8217;s profile data.',
     417                                'items'             => array(
     418                                        'user-1' => array(
     419                                                array(
     420                                                        'name'  => 'User ID',
     421                                                        'value' => 1
     422                                                ),
     423                                                array(
     424                                                        'name'  => 'User Login Name',
     425                                                        'value' => 'user_login'
     426                                                ),
     427                                                array(
     428                                                        'name'  => 'User Nice Name',
     429                                                        'value' => 'User Name'
     430                                                ),
     431                                                array(
     432                                                        'name'  => 'User Email',
     433                                                        'value' => 'export-requester@example.com'
     434                                                ),
     435                                                array(
     436                                                        'name'  => 'User Registration Date',
     437                                                        'value' => '2020-01-31 19:29:29'
     438                                                ),
     439                                                array(
     440                                                        'name'  => 'User Display Name',
     441                                                        'value' => 'User Name'
     442                                                ),
     443                                                array(
     444                                                        'name'  => 'User Nickname',
     445                                                        'value' => 'User'
     446                                                ),
     447                                        ),
     448                                ),
     449                        ),
     450                        'comments' => array(
     451                                'group_label' => 'Comments',
     452                                'group_description' => 'User&#8217;s comment data.',
     453                                'items' => array(
     454                                        'comment-2' => array(
     455                                                array(
     456                                                        'name' => 'Comment Author',
     457                                                        'value' => 'User Name'
     458                                                ),
     459                                                array(
     460                                                        'name' => 'Comment Author Email',
     461                                                        'value' => 'export-requester@example.com'
     462                                                ),
     463                                                array(
     464                                                        'name' => 'Comment Author IP',
     465                                                        'value' => '::1'
     466                                                ),
     467                                                array(
     468                                                        'name' => 'Comment Author User Agent',
     469                                                        'value' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'
     470                                                ),
     471                                                array(
     472                                                        'name' => 'Comment Date',
     473                                                        'value' => '2020-01-31 19:55:19'
     474                                                ),
     475                                                array(
     476                                                        'name' => 'Comment Content',
     477                                                        'value' => 'Test'
     478                                                ),
     479                                                array(
     480                                                        'name' => 'Comment URL',
     481                                                        'value' => '<a href="http://localhost:8888/46894/2020/01/31/hello-world/#comment-2" target="_blank" rel="noreferrer noopener">http://localhost:8888/46894/2020/01/31/hello-world/#comment-2</a>'
     482                                                ),
     483                                        ),
     484                                        'comment-3' => array(
     485                                                array(
     486                                                        'name' => 'Comment Author',
     487                                                        'value' => 'User Name'
     488                                                ),
     489                                                array(
     490                                                        'name' => 'Comment Author Email',
     491                                                        'value' => 'export-requester@example.com'
     492                                                ),
     493                                                array(
     494                                                        'name' => 'Comment Author IP',
     495                                                        'value' => '::1'
     496                                                ),
     497                                                array(
     498                                                        'name' => 'Comment Author User Agent',
     499                                                        'value' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'
     500                                                ),
     501                                                array(
     502                                                        'name' => 'Comment Date',
     503                                                        'value' => '2020-01-31 20:55:19'
     504                                                ),
     505                                                array(
     506                                                        'name' => 'Comment Content',
     507                                                        'value' => 'Test #2'
     508                                                ),
     509                                                array(
     510                                                        'name' => 'Comment URL',
     511                                                        'value' => '<a href="http://localhost:8888/46894/2020/01/31/hello-world/#comment-3" target="_blank" rel="noreferrer noopener">http://localhost:8888/46894/2020/01/31/hello-world/#comment-3</a>'
     512                                                ),
     513                                        ),
     514                                ),
     515                        ),
     516                );
     517                update_post_meta( self::$export_request_id, '_export_data_grouped', $export_data_grouped );             
     518
     519                // Generate Export File
     520                wp_privacy_generate_personal_data_export_file( self::$export_request_id );
     521                $this->assertTrue( file_exists( $this->export_file_name ) );
     522
     523                // Cleam-up for subsequent tests
     524                update_post_meta( self::$export_request_id, '_export_data_grouped', array() );
     525
     526                $report_dir = trailingslashit( self::$exports_dir . 'test_contents' );
     527                mkdir( $report_dir );
     528
     529                $zip        = new ZipArchive();
     530                $opened_zip = $zip->open( $this->export_file_name );
     531                $this->assertTrue( $opened_zip );
     532
     533                $zip->extractTo( $report_dir );
     534                $zip->close();
     535                $this->assertTrue( file_exists( $report_dir . 'index.html' ) );
     536
     537                $report_contents = file_get_contents( $report_dir . 'index.html' );
     538                $request         = wp_get_user_request_data( self::$export_request_id );
     539
     540                $this->assertContains( '<div id="table_of_contents">', $report_contents );
     541                $this->assertContains( '<a href="#comments-comments">Comments <span class="count">(2)</span></a>', $report_contents );
     542                $this->assertContains( $request->email, $report_contents );                     
     543        }
     544
     545        /**
     546         * Test the export HTML file containing multiple export groups with no multiple group items
     547         * has a table of contents without group count.
     548         *
     549         * @ticket 46894
     550         */
     551        public function test_multiple_group_export_single_items_no_group_count_in_toc() {
     552                $this->expectOutputString( '' );
     553
     554                // Setup Export Data to contain multiple groups
     555                $export_data_grouped = array(
     556                        'user' => array(
     557                                'group_label'       => 'User',
     558                                'group_description' => 'User&#8217;s profile data.',
     559                                'items'             => array(
     560                                        'user-1' => array(
     561                                                array(
     562                                                        'name'  => 'User ID',
     563                                                        'value' => 1
     564                                                ),
     565                                                array(
     566                                                        'name'  => 'User Login Name',
     567                                                        'value' => 'user_login'
     568                                                ),
     569                                                array(
     570                                                        'name'  => 'User Nice Name',
     571                                                        'value' => 'User Name'
     572                                                ),
     573                                                array(
     574                                                        'name'  => 'User Email',
     575                                                        'value' => 'export-requester@example.com'
     576                                                ),
     577                                                array(
     578                                                        'name'  => 'User Registration Date',
     579                                                        'value' => '2020-01-31 19:29:29'
     580                                                ),
     581                                                array(
     582                                                        'name'  => 'User Display Name',
     583                                                        'value' => 'User Name'
     584                                                ),
     585                                                array(
     586                                                        'name'  => 'User Nickname',
     587                                                        'value' => 'User'
     588                                                ),
     589                                        ),
     590                                ),
     591                        ),
     592                        'comments' => array(
     593                                'group_label' => 'Comments',
     594                                'group_description' => 'User&#8217;s comment data.',
     595                                'items' => array(
     596                                        'comment-2' => array(
     597                                                array(
     598                                                        'name' => 'Comment Author',
     599                                                        'value' => 'User Name'
     600                                                ),
     601                                                array(
     602                                                        'name' => 'Comment Author Email',
     603                                                        'value' => 'export-requester@example.com'
     604                                                ),
     605                                                array(
     606                                                        'name' => 'Comment Author IP',
     607                                                        'value' => '::1'
     608                                                ),
     609                                                array(
     610                                                        'name' => 'Comment Author User Agent',
     611                                                        'value' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'
     612                                                ),
     613                                                array(
     614                                                        'name' => 'Comment Date',
     615                                                        'value' => '2020-01-31 19:55:19'
     616                                                ),
     617                                                array(
     618                                                        'name' => 'Comment Content',
     619                                                        'value' => 'Test'
     620                                                ),
     621                                                array(
     622                                                        'name' => 'Comment URL',
     623                                                        'value' => '<a href="http://localhost:8888/46894/2020/01/31/hello-world/#comment-2" target="_blank" rel="noreferrer noopener">http://localhost:8888/46894/2020/01/31/hello-world/#comment-2</a>'
     624                                                ),
     625                                        ),
     626                                ),
     627                        ),
     628                );
     629                update_post_meta( self::$export_request_id, '_export_data_grouped', $export_data_grouped );             
     630
     631                // Generate Export File
     632                wp_privacy_generate_personal_data_export_file( self::$export_request_id );
     633                $this->assertTrue( file_exists( $this->export_file_name ) );
     634
     635                // Cleam-up for subsequent tests
     636                update_post_meta( self::$export_request_id, '_export_data_grouped', array() );
     637
     638                $report_dir = trailingslashit( self::$exports_dir . 'test_contents' );
     639                mkdir( $report_dir );
     640
     641                $zip        = new ZipArchive();
     642                $opened_zip = $zip->open( $this->export_file_name );
     643                $this->assertTrue( $opened_zip );
     644
     645                $zip->extractTo( $report_dir );
     646                $zip->close();
     647                $this->assertTrue( file_exists( $report_dir . 'index.html' ) );
     648
     649                $report_contents = file_get_contents( $report_dir . 'index.html' );
     650                $request         = wp_get_user_request_data( self::$export_request_id );
     651
     652                $this->assertContains( '<div id="table_of_contents">', $report_contents );
     653                $this->assertNotContains( '<span class="count">', $report_contents );
     654                $this->assertContains( $request->email, $report_contents );
     655               
     656        }
    297657}
  • tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportGroupHtml.php

     
    3939                        ),
    4040                );
    4141
    42                 $actual                = wp_privacy_generate_personal_data_export_group_html( $data );
     42                $actual                = wp_privacy_generate_personal_data_export_group_html( $data, 'test-data-group', 2 );
    4343                $expected_table_markup = '<table><tbody><tr><th>Field 1 Name</th><td>Field 1 Value</td></tr><tr><th>Field 2 Name</th><td>Field 2 Value</td></tr></tbody></table>';
    4444
    45                 $this->assertContains( '<h2>Test Data Group</h2>', $actual );
     45                $this->assertContains( '<h2 id="test-data-group-test-data-group">Test Data Group</h2>', $actual );
    4646                $this->assertContains( $expected_table_markup, $actual );
    4747        }
    4848
     
    7979                        ),
    8080                );
    8181
    82                 $actual = wp_privacy_generate_personal_data_export_group_html( $data );
     82                $actual = wp_privacy_generate_personal_data_export_group_html( $data, 'test-data-group', 2 );
    8383
    84                 $this->assertContains( '<h2>Test Data Group', $actual );
     84                $this->assertContains( '<h2 id="test-data-group-test-data-group">Test Data Group', $actual );
    8585                $this->assertContains( '<td>Field 1 Value', $actual );
    8686                $this->assertContains( '<td>Another Field 1 Value', $actual );
    8787                $this->assertContains( '<td>Field 2 Value', $actual );
     
    117117                        ),
    118118                );
    119119
    120                 $actual = wp_privacy_generate_personal_data_export_group_html( $data );
     120                $actual = wp_privacy_generate_personal_data_export_group_html( $data, 'test-data-group', 2 );
    121121
    122122                $this->assertContains( '<a href="http://wordpress.org">http://wordpress.org</a>', $actual );
    123123                $this->assertContains( '<a href="https://wordpress.org">https://wordpress.org</a>', $actual );
     
    131131         */
    132132        public function test_group_labels_escaped() {
    133133                $data = array(
    134                         'group_label' => '<div>Escape HTML in group lavels</div>',
     134                        'group_label' => '<div>Escape HTML in group labels</div>',
    135135                        'items'       => array(),
    136136                );
    137137
    138                 $actual = wp_privacy_generate_personal_data_export_group_html( $data );
     138                $actual = wp_privacy_generate_personal_data_export_group_html( $data, 'escape-html-in-group-labels', 2 );
    139139
    140                 $this->assertContains( '<h2>&lt;div&gt;Escape HTML in group lavels&lt;/div&gt;</h2>', $actual );
     140                $this->assertContains( '<h2 id="escape-html-in-group-labels-escape-html-in-group-labels">&lt;div&gt;Escape HTML in group labels&lt;/div&gt;</h2>', $actual );
    141141        }
    142142
    143143        /**
     
    162162                        ),
    163163                );
    164164
    165                 $actual = wp_privacy_generate_personal_data_export_group_html( $data );
    166 
     165                $actual = wp_privacy_generate_personal_data_export_group_html( $data, 'test-data-group', 2 );
    167166                $this->assertContains( $data['items'][0]['links']['value'], $actual );
    168167                $this->assertContains( $data['items'][0]['formatting']['value'], $actual );
    169168        }
     
    190189                        ),
    191190                );
    192191
    193                 $actual = wp_privacy_generate_personal_data_export_group_html( $data );
     192                $actual = wp_privacy_generate_personal_data_export_group_html( $data, 'test-data-group', 2 );
    194193
    195194                $this->assertNotContains( $data['items'][0]['scripts']['value'], $actual );
    196195                $this->assertContains( '<td>Testing that script tags are stripped.</td>', $actual );
     
    223222                        ),
    224223                );
    225224
    226                 $actual = wp_privacy_generate_personal_data_export_group_html( $data );
     225                $actual = wp_privacy_generate_personal_data_export_group_html( $data, 'test-data-group', 2 );
    227226
    228                 $this->assertContains( '<h2>Test Data Group', $actual );
     227                $this->assertContains( '<h2 id="test-data-group-test-data-group">Test Data Group', $actual );
    229228                $this->assertContains( '<span class="count">(2)</span></h2>', $actual );
    230229                $this->assertSame( 2, substr_count( $actual, '<table>' ) );
    231230        }
     
    248247                        ),
    249248                );
    250249
    251                 $actual = wp_privacy_generate_personal_data_export_group_html( $data );
     250                $actual = wp_privacy_generate_personal_data_export_group_html( $data, 'test-data-group', 2 );
    252251
    253                 $this->assertContains( '<h2>Test Data Group</h2>', $actual );
     252                $this->assertContains( '<h2 id="test-data-group-test-data-group">Test Data Group</h2>', $actual );
    254253                $this->assertNotContains( '<span class="count">', $actual );
    255254                $this->assertSame( 1, substr_count( $actual, '<table>' ) );
    256255        }
  • tests/phpunit/tests/user.php

     
    16511651        }
    16521652
    16531653        /**
    1654          * Testing the `wp_user_personal_data_exporter_no_user` function when no user exists.
     1654         * Testing the `wp_user_personal_data_exporter` function when no user exists.
    16551655         *
    16561656         * @ticket 43547
    16571657         */
     
    16671667        }
    16681668
    16691669        /**
    1670          * Testing the `wp_user_personal_data_exporter_no_user` function when the requested
     1670         * Testing the `wp_user_personal_data_exporter` function when the requested
    16711671         * user exists.
    16721672         *
    16731673         * @ticket 43547
     
    16851685                // Number of exported user properties.
    16861686                $this->assertSame( 11, count( $actual['data'][0]['data'] ) );
    16871687        }
     1688
     1689        /**
     1690         * Testing the `wp_user_personal_data_exporter` function
     1691         * with Community Events Location IP data.
     1692         *
     1693         * @ticket 43921
     1694         */
     1695        function test_wp_community_events_location_ip_personal_data_exporter() {
     1696                $test_user = new WP_User( self::$contrib_id );
     1697
     1698                $location_data = array( 'ip' => '0.0.0.0' );
     1699                update_user_option( $test_user->ID, 'community-events-location', $location_data, true );
     1700
     1701                $actual = wp_user_personal_data_exporter( $test_user->user_email );
     1702
     1703                $this->assertTrue( $actual['done'] );
     1704
     1705                // Contains Community Events Location.
     1706                $this->assertEquals( 'Community Events Location', $actual['data'][1]['group_label'] );
     1707
     1708                // Contains location IP.
     1709                $this->assertEquals( 'IP', $actual['data'][1]['data'][0]['name'] );
     1710                $this->assertEquals( '0.0.0.0', $actual['data'][1]['data'][0]['value'] );
     1711        }
     1712
     1713        /**
     1714         * Testing the `wp_user_personal_data_exporter` function
     1715         * with Community Events Location city data.
     1716         *
     1717         * @ticket 43921
     1718         */
     1719        function test_wp_community_events_location_city_personal_data_exporter() {
     1720                $test_user = new WP_User( self::$contrib_id );
     1721
     1722                $location_data = array(
     1723                        'description' => 'Cincinnati',
     1724                        'country'     => 'US',
     1725                        'latitude'    => '39.1271100',
     1726                        'longitude'   => '-84.5143900',
     1727                );
     1728                update_user_option( $test_user->ID, 'community-events-location', $location_data, true );
     1729
     1730                $actual = wp_user_personal_data_exporter( $test_user->user_email );
     1731
     1732                $this->assertTrue( $actual['done'] );
     1733
     1734                // Contains Community Events Location.
     1735                $this->assertEquals( 'Community Events Location', $actual['data'][1]['group_label'] );
     1736
     1737                // Contains location city.
     1738                $this->assertEquals( 'City', $actual['data'][1]['data'][0]['name'] );           
     1739                $this->assertEquals( 'Cincinnati', $actual['data'][1]['data'][0]['value'] );
     1740
     1741                // Contains location country.
     1742                $this->assertEquals( 'Country', $actual['data'][1]['data'][1]['name'] );               
     1743                $this->assertEquals( 'US', $actual['data'][1]['data'][1]['value'] );
     1744
     1745                // Contains location latitude.
     1746                $this->assertEquals( 'Latitude', $actual['data'][1]['data'][2]['name'] );               
     1747                $this->assertEquals( '39.1271100', $actual['data'][1]['data'][2]['value'] );
     1748
     1749                // Contains location longitude.
     1750                $this->assertEquals( 'Longitude', $actual['data'][1]['data'][3]['name'] );             
     1751                $this->assertEquals( '-84.5143900', $actual['data'][1]['data'][3]['value'] );
     1752
     1753        }
     1754
     1755        /**
     1756         * Testing the `wp_user_personal_data_exporter` function
     1757         * with Session Tokens data.
     1758         *
     1759         * @ticket 45889
     1760         */
     1761        function test_wp_session_tokens_personal_data_exporter() {
     1762                $test_user = new WP_User( self::$contrib_id );
     1763
     1764                $session_tokens_data = array(
     1765                        'yft87y56457687sfd897867545fg76ds78iyuhgjyui7865' => array(
     1766                                'expiration' => 1580461981,
     1767                                'ip'         => '0.0.0.0',
     1768                                'ua'         => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
     1769                                'login'      => 1580289181,
     1770                        ),
     1771                );
     1772                update_user_option( $test_user->ID, 'session_tokens', $session_tokens_data, true );
     1773
     1774                $actual = wp_user_personal_data_exporter( $test_user->user_email );
     1775
     1776                $this->assertTrue( $actual['done'] );
     1777
     1778                // Contains Session Tokens.
     1779                $this->assertEquals( 'Session Tokens', $actual['data'][1]['group_label'] );
     1780
     1781                // Contains Expiration.
     1782                $this->assertEquals( 'Expiration', $actual['data'][1]['data'][0]['name'] );
     1783                $this->assertEquals( 'January 31, 2020 09:13 AM', $actual['data'][1]['data'][0]['value'] );
     1784
     1785                // Contains IP.
     1786                $this->assertEquals( 'IP', $actual['data'][1]['data'][1]['name'] );
     1787                $this->assertEquals( '0.0.0.0', $actual['data'][1]['data'][1]['value'] );
     1788
     1789                // Contains IP.
     1790                $this->assertEquals( 'User Agent', $actual['data'][1]['data'][2]['name'] );
     1791                $this->assertEquals( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36', $actual['data'][1]['data'][2]['value'] );
     1792
     1793                // Contains IP.
     1794                $this->assertEquals( 'Last Login', $actual['data'][1]['data'][3]['name'] );
     1795                $this->assertEquals( 'January 29, 2020 09:13 AM', $actual['data'][1]['data'][3]['value'] );
     1796        }
    16881797}