Privacy: Display group items count in the personal data export file if there's more than one item in the group.
Props birgire, garrett-eclipse, pputzer. Fixes #46895. git-svn-id: https://develop.svn.wordpress.org/trunk@46209 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
946cadaf3d
commit
6922b15e3a
@ -234,7 +234,15 @@ function _wp_personal_data_cleanup_requests() {
|
||||
* @return string The HTML for this group and its items.
|
||||
*/
|
||||
function wp_privacy_generate_personal_data_export_group_html( $group_data ) {
|
||||
$group_html = '<h2>' . esc_html( $group_data['group_label'] ) . '</h2>';
|
||||
$group_html = '<h2>';
|
||||
$group_html .= esc_html( $group_data['group_label'] );
|
||||
|
||||
$items_count = count( (array) $group_data['items'] );
|
||||
if ( $items_count > 1 ) {
|
||||
$group_html .= sprintf( ' <span class="count">(%d)</span>', $items_count );
|
||||
}
|
||||
|
||||
$group_html .= '</h2>';
|
||||
|
||||
if ( ! empty( $group_data['group_description'] ) ) {
|
||||
$group_html .= '<p>' . esc_html( $group_data['group_description'] ) . '</p>';
|
||||
|
@ -50,6 +50,7 @@ class Tests_Privacy_WpPrivacyGeneratePersonalDataExportGroupHtml extends WP_Unit
|
||||
* Test when a multiple data items are passed.
|
||||
*
|
||||
* @ticket 44044
|
||||
* @ticket 46895 Updated to remove </h2> from test to avoid Count introducing failure.
|
||||
*/
|
||||
public function test_group_html_generation_multiple_data_items() {
|
||||
$data = array(
|
||||
@ -80,7 +81,7 @@ class Tests_Privacy_WpPrivacyGeneratePersonalDataExportGroupHtml extends WP_Unit
|
||||
|
||||
$actual = wp_privacy_generate_personal_data_export_group_html( $data );
|
||||
|
||||
$this->assertContains( '<h2>Test Data Group</h2>', $actual );
|
||||
$this->assertContains( '<h2>Test Data Group', $actual );
|
||||
$this->assertContains( '<td>Field 1 Value', $actual );
|
||||
$this->assertContains( '<td>Another Field 1 Value', $actual );
|
||||
$this->assertContains( '<td>Field 2 Value', $actual );
|
||||
@ -197,4 +198,60 @@ class Tests_Privacy_WpPrivacyGeneratePersonalDataExportGroupHtml extends WP_Unit
|
||||
$this->assertNotContains( $data['items'][0]['images']['value'], $actual );
|
||||
$this->assertContains( '<th>Images are not allowed</th><td></td>', $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test group count is displayed for multiple items.
|
||||
*
|
||||
* @ticket 46895
|
||||
*/
|
||||
public function test_group_html_generation_should_display_group_count_when_multiple_items() {
|
||||
$data = array(
|
||||
'group_label' => 'Test Data Group',
|
||||
'items' => array(
|
||||
array(
|
||||
array(
|
||||
'name' => 'Field 1 Name',
|
||||
'value' => 'Field 1 Value',
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'name' => 'Field 2 Name',
|
||||
'value' => 'Field 2 Value',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$actual = wp_privacy_generate_personal_data_export_group_html( $data );
|
||||
|
||||
$this->assertContains( '<h2>Test Data Group', $actual );
|
||||
$this->assertContains( '<span class="count">(2)</span></h2>', $actual );
|
||||
$this->assertSame( 2, substr_count( $actual, '<table>' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test group count is not displayed for a single item.
|
||||
*
|
||||
* @ticket 46895
|
||||
*/
|
||||
public function test_group_html_generation_should_not_display_group_count_when_single_item() {
|
||||
$data = array(
|
||||
'group_label' => 'Test Data Group',
|
||||
'items' => array(
|
||||
array(
|
||||
array(
|
||||
'name' => 'Field 1 Name',
|
||||
'value' => 'Field 1 Value',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$actual = wp_privacy_generate_personal_data_export_group_html( $data );
|
||||
|
||||
$this->assertContains( '<h2>Test Data Group</h2>', $actual );
|
||||
$this->assertNotContains( '<span class="count">', $actual );
|
||||
$this->assertSame( 1, substr_count( $actual, '<table>' ) );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user