Ticket #46895: 46895.4.diff
File 46895.4.diff, 3.5 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>' . esc_html( $group_data['group_label'] ) . '</h2>';238 237 238 $group_html = '<h2>'; 239 $group_html .= esc_html( $group_data['group_label'] ); 240 241 $items_count = count( (array) $group_data['items'] ); 242 if ( $items_count > 1 ) { 243 $group_html .= sprintf( ' <span class="count">(%d)</span>', $items_count ); 244 } 245 246 $group_html .= '</h2>'; 247 239 248 if ( ! empty( $group_data['group_description'] ) ) { 240 249 $group_html .= '<p>' . esc_html( $group_data['group_description'] ) . '</p>'; 241 250 } -
tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportGroupHtml.php
50 50 * Test when a multiple data items are passed. 51 51 * 52 52 * @ticket 44044 53 * @ticket 46895 Updated to remove </h2> from test to avoid Count introducing failure. 53 54 */ 54 55 public function test_group_html_generation_multiple_data_items() { 55 56 $data = array( … … 80 81 81 82 $actual = wp_privacy_generate_personal_data_export_group_html( $data ); 82 83 83 $this->assertContains( '<h2>Test Data Group </h2>', $actual );84 $this->assertContains( '<h2>Test Data Group', $actual ); 84 85 $this->assertContains( '<td>Field 1 Value', $actual ); 85 86 $this->assertContains( '<td>Another Field 1 Value', $actual ); 86 87 $this->assertContains( '<td>Field 2 Value', $actual ); … … 197 198 $this->assertNotContains( $data['items'][0]['images']['value'], $actual ); 198 199 $this->assertContains( '<th>Images are not allowed</th><td></td>', $actual ); 199 200 } 201 202 /** 203 * Test group count is displayed for multiple items. 204 * 205 * @ticket 46895 206 */ 207 public function test_group_html_generation_should_display_group_count_when_multiple_items() { 208 $data = array( 209 'group_label' => 'Test Data Group', 210 'items' => array( 211 array( 212 array( 213 'name' => 'Field 1 Name', 214 'value' => 'Field 1 Value', 215 ), 216 ), 217 array( 218 array( 219 'name' => 'Field 2 Name', 220 'value' => 'Field 2 Value', 221 ), 222 ), 223 ), 224 ); 225 226 $actual = wp_privacy_generate_personal_data_export_group_html( $data ); 227 228 $this->assertContains( '<h2>Test Data Group', $actual ); 229 $this->assertContains( '<span class="count">(2)</span></h2>', $actual ); 230 $this->assertSame( 2, substr_count( $actual, '<table>' ) ); 231 } 232 233 /** 234 * Test group count is not displayed for a single item. 235 * 236 * @ticket 46895 237 */ 238 public function test_group_html_generation_should_not_display_group_count_when_single_item() { 239 $data = array( 240 'group_label' => 'Test Data Group', 241 'items' => array( 242 array( 243 array( 244 'name' => 'Field 1 Name', 245 'value' => 'Field 1 Value', 246 ), 247 ), 248 ), 249 ); 250 251 $actual = wp_privacy_generate_personal_data_export_group_html( $data ); 252 253 $this->assertContains( '<h2>Test Data Group</h2>', $actual ); 254 $this->assertNotContains( '<span class="count">', $actual ); 255 $this->assertSame( 1, substr_count( $actual, '<table>' ) ); 256 } 200 257 }