Ticket #46894: 46894.4.diff
File 46894.4.diff, 5.9 KB (added by , 5 years ago) |
---|
-
src/wp-admin/includes/privacy-tools.php
234 234 * @return string The HTML for this group and its items. 235 235 */ 236 236 function wp_privacy_generate_personal_data_export_group_html( $group_data ) { 237 $group_html = '<h2 >';237 $group_html = '<h2 id="' . esc_attr( sanitize_title_with_dashes( $group_data['group_label'] ) ) . '">'; 238 238 $group_html .= esc_html( $group_data['group_label'] ); 239 239 240 240 $items_count = count( (array) $group_data['items'] ); … … 271 271 $group_html .= '</table>'; 272 272 } 273 273 274 $group_html .= '<div class="return_to_top">'; 275 $group_html .= '<a href="#top">' . esc_html__( '↑ Return to top' ) . '</a>'; 274 276 $group_html .= '</div>'; 275 277 278 $group_html .= '</div>'; 279 276 280 return $group_html; 277 281 } 278 282 … … 350 354 fwrite( $file, 'th { padding: 5px; text-align: left; width: 20%; }' ); 351 355 fwrite( $file, 'td { padding: 5px; }' ); 352 356 fwrite( $file, 'tr:nth-child(odd) { background-color: #fafafa; }' ); 357 fwrite( $file, '.return_to_top { text-align:right; }' ); 353 358 fwrite( $file, '</style>' ); 354 359 fwrite( $file, '<title>' ); 355 360 fwrite( $file, esc_html( $title ) ); … … 360 365 fwrite( $file, "<body>\n" ); 361 366 362 367 // Heading. 363 fwrite( $file, '<h1 >' . esc_html__( 'Personal Data Export' ) . '</h1>' );368 fwrite( $file, '<h1 id="top">' . esc_html__( 'Personal Data Export' ) . '</h1>' ); 364 369 365 370 // And now, all the Groups. 366 371 $groups = get_post_meta( $request_id, '_export_data_grouped', true ); … … 396 401 // Merge in the special about group. 397 402 $groups = array_merge( array( 'about' => $about_group ), $groups ); 398 403 404 // Create TOC. 405 if ( count( $groups ) > 1 ) { 406 fwrite( $file, '<div id="table_of_contents">' ); 407 fwrite( $file, '<h2>' . esc_html__( 'Table of Contents' ) . '</h2>' ); 408 fwrite( $file, '<ul>' ); 409 410 foreach ( (array) $groups as $group_id => $group_data ) { 411 fwrite( $file, '<li>' ); 412 fwrite( $file, '<a href="#' . esc_attr( sanitize_title_with_dashes( $group_data['group_label'] ) ) . '">' . esc_html( $group_data['group_label'] ) . '</a>' ); 413 fwrite( $file, '</li>' ); 414 } 415 416 fwrite( $file, '</ul>' ); 417 fwrite( $file, '</div>' ); 418 } 419 399 420 // Now, iterate over every group in $groups and have the formatter render it in HTML. 400 421 foreach ( (array) $groups as $group_id => $group_data ) { 401 422 fwrite( $file, wp_privacy_generate_personal_data_export_group_html( $group_data ) ); -
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</h2>', $report_contents ); 265 265 $this->assertContains( $request->email, $report_contents ); 266 266 } 267 267 } -
tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportGroupHtml.php
42 42 $actual = wp_privacy_generate_personal_data_export_group_html( $data ); 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</h2>', $actual ); 46 46 $this->assertContains( $expected_table_markup, $actual ); 47 47 } 48 48 … … 81 81 82 82 $actual = wp_privacy_generate_personal_data_export_group_html( $data ); 83 83 84 $this->assertContains( '<h2 >Test Data Group', $actual );84 $this->assertContains( '<h2 id="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 ); … … 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 138 $actual = wp_privacy_generate_personal_data_export_group_html( $data ); 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"><div>Escape HTML in group labels</div></h2>', $actual ); 141 141 } 142 142 143 143 /** … … 225 225 226 226 $actual = wp_privacy_generate_personal_data_export_group_html( $data ); 227 227 228 $this->assertContains( '<h2 >Test Data Group', $actual );228 $this->assertContains( '<h2 id="test-data-group">Test Data Group', $actual ); 229 229 $this->assertContains( '<span class="count">(2)</span></h2>', $actual ); 230 230 $this->assertSame( 2, substr_count( $actual, '<table>' ) ); 231 231 } … … 250 250 251 251 $actual = wp_privacy_generate_personal_data_export_group_html( $data ); 252 252 253 $this->assertContains( '<h2 >Test Data Group</h2>', $actual );253 $this->assertContains( '<h2 id="test-data-group">Test Data Group</h2>', $actual ); 254 254 $this->assertNotContains( '<span class="count">', $actual ); 255 255 $this->assertSame( 1, substr_count( $actual, '<table>' ) ); 256 256 }