Ticket #46894: 46894.6.diff
File 46894.6.diff, 28.4 KB (added by , 4 years ago) |
---|
-
src/wp-admin/includes/privacy-tools.php
215 215 * Generate a single group for the personal data export report. 216 216 * 217 217 * @since 4.9.6 218 * @since 5.4.0 Added $group_id to support the TOC implementation. 218 219 * 219 * @param array $group_data {220 * @param array $group_data { 220 221 * The group data to render. 221 222 * 222 223 * @type string $group_label The user-facing heading for the group, e.g. 'Comments'. … … 231 232 * } 232 233 * } 233 234 * } 235 * @param string $group_id The group identifier. 236 * @param int $groups_count The number of all groups 234 237 * @return string The HTML for this group and its items. 235 238 */ 236 function wp_privacy_generate_personal_data_export_group_html( $group_data ) { 237 $group_html = '<h2>'; 239 function 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 ) . '">'; 238 243 $group_html .= esc_html( $group_data['group_label'] ); 239 244 240 245 $items_count = count( (array) $group_data['items'] ); … … 271 276 $group_html .= '</table>'; 272 277 } 273 278 279 if ( 1 < $groups_count ) { 280 $group_html .= '<div class="return_to_top">'; 281 $group_html .= '<a href="#top">' . esc_html__( '↑ Return to top' ) . '</a>'; 282 $group_html .= '</div>'; 283 } 284 274 285 $group_html .= '</div>'; 275 286 276 287 return $group_html; … … 371 382 372 383 // Merge in the special about group. 373 384 $groups = array_merge( array( 'about' => $about_group ), $groups ); 385 $groups_count = count( $groups ); 374 386 375 387 // Convert the groups to JSON format. 376 388 $groups_json = wp_json_encode( $groups ); … … 409 421 fwrite( $file, 'th { padding: 5px; text-align: left; width: 20%; }' ); 410 422 fwrite( $file, 'td { padding: 5px; }' ); 411 423 fwrite( $file, 'tr:nth-child(odd) { background-color: #fafafa; }' ); 424 fwrite( $file, '.return_to_top { text-align:right; }' ); 412 425 fwrite( $file, '</style>' ); 413 426 fwrite( $file, '<title>' ); 414 427 fwrite( $file, esc_html( $title ) ); … … 415 428 fwrite( $file, '</title>' ); 416 429 fwrite( $file, "</head>\n" ); 417 430 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>' ); 419 432 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 420 453 // Now, iterate over every group in $groups and have the formatter render it in HTML. 421 454 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 ) ); 423 456 } 424 457 425 458 fwrite( $file, "</body>\n" ); -
src/wp-includes/user.php
2959 2959 2960 2960 $user_meta = get_user_meta( $user->ID ); 2961 2961 2962 $user_prop _to_export = array(2962 $user_props_to_export = array( 2963 2963 'ID' => __( 'User ID' ), 2964 2964 'user_login' => __( 'User Login Name' ), 2965 2965 'user_nicename' => __( 'User Nice Name' ), … … 2975 2975 2976 2976 $user_data_to_export = array(); 2977 2977 2978 foreach ( $user_prop _to_export as $key => $name ) {2978 foreach ( $user_props_to_export as $key => $name ) { 2979 2979 $value = ''; 2980 2980 2981 2981 switch ( $key ) { … … 3012 3012 'data' => $user_data_to_export, 3013 3013 ); 3014 3014 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’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’s Session Tokens data.' ), 3087 'item_id' => "session-tokens-{$user->ID}-{$token_key}", 3088 'data' => $session_tokens_data_to_export, 3089 ); 3090 } 3091 } 3092 3015 3093 return array( 3016 3094 'data' => $data_to_export, 3017 3095 'done' => true, -
tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportFile.php
260 260 $report_contents = file_get_contents( $report_dir . 'index.html' ); 261 261 $request = wp_get_user_request_data( self::$export_request_id ); 262 262 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 ); 265 265 $this->assertContains( $request->email, $report_contents ); 266 266 } 267 267 … … 294 294 $this->assertContains( '"Personal Data Export for ' . $request->email . '"', $report_contents_json ); 295 295 $this->assertContains( '"about"', $report_contents_json ); 296 296 } 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’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’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’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’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’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 } 297 657 } -
tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportGroupHtml.php
39 39 ), 40 40 ); 41 41 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 ); 43 43 $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>'; 44 44 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 ); 46 46 $this->assertContains( $expected_table_markup, $actual ); 47 47 } 48 48 … … 79 79 ), 80 80 ); 81 81 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 ); 83 83 84 $this->assertContains( '<h2 >Test Data Group', $actual );84 $this->assertContains( '<h2 id="test-data-group-test-data-group">Test Data Group', $actual ); 85 85 $this->assertContains( '<td>Field 1 Value', $actual ); 86 86 $this->assertContains( '<td>Another Field 1 Value', $actual ); 87 87 $this->assertContains( '<td>Field 2 Value', $actual ); … … 117 117 ), 118 118 ); 119 119 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 ); 121 121 122 122 $this->assertContains( '<a href="http://wordpress.org">http://wordpress.org</a>', $actual ); 123 123 $this->assertContains( '<a href="https://wordpress.org">https://wordpress.org</a>', $actual ); … … 131 131 */ 132 132 public function test_group_labels_escaped() { 133 133 $data = array( 134 'group_label' => '<div>Escape HTML in group la vels</div>',134 'group_label' => '<div>Escape HTML in group labels</div>', 135 135 'items' => array(), 136 136 ); 137 137 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 ); 139 139 140 $this->assertContains( '<h2 ><div>Escape HTML in group lavels</div></h2>', $actual );140 $this->assertContains( '<h2 id="escape-html-in-group-labels-escape-html-in-group-labels"><div>Escape HTML in group labels</div></h2>', $actual ); 141 141 } 142 142 143 143 /** … … 162 162 ), 163 163 ); 164 164 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 ); 167 166 $this->assertContains( $data['items'][0]['links']['value'], $actual ); 168 167 $this->assertContains( $data['items'][0]['formatting']['value'], $actual ); 169 168 } … … 190 189 ), 191 190 ); 192 191 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 ); 194 193 195 194 $this->assertNotContains( $data['items'][0]['scripts']['value'], $actual ); 196 195 $this->assertContains( '<td>Testing that script tags are stripped.</td>', $actual ); … … 223 222 ), 224 223 ); 225 224 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 ); 227 226 228 $this->assertContains( '<h2 >Test Data Group', $actual );227 $this->assertContains( '<h2 id="test-data-group-test-data-group">Test Data Group', $actual ); 229 228 $this->assertContains( '<span class="count">(2)</span></h2>', $actual ); 230 229 $this->assertSame( 2, substr_count( $actual, '<table>' ) ); 231 230 } … … 248 247 ), 249 248 ); 250 249 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 ); 252 251 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 ); 254 253 $this->assertNotContains( '<span class="count">', $actual ); 255 254 $this->assertSame( 1, substr_count( $actual, '<table>' ) ); 256 255 } -
tests/phpunit/tests/user.php
1651 1651 } 1652 1652 1653 1653 /** 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. 1655 1655 * 1656 1656 * @ticket 43547 1657 1657 */ … … 1667 1667 } 1668 1668 1669 1669 /** 1670 * Testing the `wp_user_personal_data_exporter _no_user` function when the requested1670 * Testing the `wp_user_personal_data_exporter` function when the requested 1671 1671 * user exists. 1672 1672 * 1673 1673 * @ticket 43547 … … 1685 1685 // Number of exported user properties. 1686 1686 $this->assertSame( 11, count( $actual['data'][0]['data'] ) ); 1687 1687 } 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 } 1688 1797 }