diff --git a/src/wp-admin/includes/privacy-tools.php b/src/wp-admin/includes/privacy-tools.php
index a9af16d802..aa2f856e84 100644
--- a/src/wp-admin/includes/privacy-tools.php
+++ b/src/wp-admin/includes/privacy-tools.php
@@ -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 = '
' . esc_html( $group_data['group_label'] ) . '
';
+ $group_html = '';
+ $group_html .= esc_html( $group_data['group_label'] );
+
+ $items_count = count( (array) $group_data['items'] );
+ if ( $items_count > 1 ) {
+ $group_html .= sprintf( ' (%d)', $items_count );
+ }
+
+ $group_html .= '
';
if ( ! empty( $group_data['group_description'] ) ) {
$group_html .= '' . esc_html( $group_data['group_description'] ) . '
';
diff --git a/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportGroupHtml.php b/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportGroupHtml.php
index f9f6dd5249..688f790e22 100644
--- a/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportGroupHtml.php
+++ b/tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportGroupHtml.php
@@ -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 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( 'Test Data Group
', $actual );
+ $this->assertContains( 'Test Data Group', $actual );
$this->assertContains( 'Field 1 Value', $actual );
$this->assertContains( ' | Another Field 1 Value', $actual );
$this->assertContains( ' | 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( ' | Images are not allowed | | ', $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( 'Test Data Group', $actual );
+ $this->assertContains( '(2)
', $actual );
+ $this->assertSame( 2, substr_count( $actual, '
' ) );
+ }
+
+ /**
+ * 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( 'Test Data Group
', $actual );
+ $this->assertNotContains( '', $actual );
+ $this->assertSame( 1, substr_count( $actual, '