mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-07 10:40:11 +00:00
Privacy: Introduce wp_privacy_additional_user_data filter to make it easier to include additional user meta in a personal data export.
Props pbiron, xkon, garrett-eclipse, azaozz. Fixes #47509. git-svn-id: https://develop.svn.wordpress.org/trunk@47270 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1794,4 +1794,133 @@ class Tests_User extends WP_UnitTestCase {
|
||||
$this->assertEquals( 'Last Login', $actual['data'][1]['data'][3]['name'] );
|
||||
$this->assertEquals( 'January 29, 2020 09:13 AM', $actual['data'][1]['data'][3]['value'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing the `wp_privacy_additional_user_profile_data` filter works.
|
||||
*
|
||||
* @ticket 47509
|
||||
*/
|
||||
function test_filter_wp_privacy_additional_user_profile_data() {
|
||||
$test_user = new WP_User( self::$contrib_id );
|
||||
|
||||
add_filter( 'wp_privacy_additional_user_profile_data', array( $this, 'export_additional_user_profile_data' ) );
|
||||
|
||||
$actual = wp_user_personal_data_exporter( $test_user->user_email );
|
||||
|
||||
remove_filter( 'wp_privacy_additional_user_profile_data', array( $this, 'export_additional_user_profile_data' ) );
|
||||
|
||||
$this->assertTrue( $actual['done'] );
|
||||
|
||||
// Number of exported users.
|
||||
$this->assertSame( 1, count( $actual['data'] ) );
|
||||
|
||||
// Number of exported user properties (the 11 core properties,
|
||||
// plus 1 additional from the filter).
|
||||
$this->assertSame( 12, count( $actual['data'][0]['data'] ) );
|
||||
|
||||
// Check that the item added by the filter was retained.
|
||||
$this->assertSame(
|
||||
1,
|
||||
count(
|
||||
wp_list_filter(
|
||||
$actual['data'][0]['data'],
|
||||
array(
|
||||
'name' => 'Test Additional Data Name',
|
||||
'value' => 'Test Additional Data Value',
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// _doing_wrong() should be called because the filter callback
|
||||
// adds a item with a 'name' that is the same as one generated by core.
|
||||
$this->setExpectedIncorrectUsage( 'wp_user_personal_data_exporter' );
|
||||
add_filter( 'wp_privacy_additional_user_profile_data', array( $this, 'export_additional_user_profile_data_with_dup_name' ) );
|
||||
|
||||
$actual = wp_user_personal_data_exporter( $test_user->user_email );
|
||||
|
||||
remove_filter( 'wp_privacy_additional_user_profile_data', array( $this, 'export_additional_user_profile_data' ) );
|
||||
|
||||
$this->assertTrue( $actual['done'] );
|
||||
|
||||
// Number of exported users.
|
||||
$this->assertSame( 1, count( $actual['data'] ) );
|
||||
|
||||
// Number of exported user properties
|
||||
// (the 11 core properties, plus 1 additional from the filter).
|
||||
$this->assertSame( 12, count( $actual['data'][0]['data'] ) );
|
||||
|
||||
// Check that the duplicate 'name' => 'User ID' was stripped.
|
||||
$this->assertSame(
|
||||
1,
|
||||
count(
|
||||
wp_list_filter(
|
||||
$actual['data'][0]['data'],
|
||||
array(
|
||||
'name' => 'User ID',
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Check that the item added by the filter was retained.
|
||||
$this->assertSame(
|
||||
1,
|
||||
count(
|
||||
wp_list_filter(
|
||||
$actual['data'][0]['data'],
|
||||
array(
|
||||
'name' => 'Test Additional Data Name',
|
||||
'value' => 'Test Additional Data Value',
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter callback to add additional profile data to the User Group on Export Requests.
|
||||
*
|
||||
* @ticket 47509
|
||||
*
|
||||
* @return array $additional_profile_data The additional user data.
|
||||
*/
|
||||
public function export_additional_user_profile_data() {
|
||||
$additional_profile_data = array(
|
||||
// This item should be retained and included in the export.
|
||||
array(
|
||||
'name' => 'Test Additional Data Name',
|
||||
'value' => 'Test Additional Data Value',
|
||||
),
|
||||
);
|
||||
|
||||
return $additional_profile_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter callback to add additional profile data to the User Group on Export Requests.
|
||||
*
|
||||
* This callback should generate a `_doing_it_wrong()`.
|
||||
*
|
||||
* @ticket 47509
|
||||
*
|
||||
* @return array $additional_profile_data The additional user data.
|
||||
*/
|
||||
public function export_additional_user_profile_data_with_dup_name() {
|
||||
$additional_profile_data = array(
|
||||
// This item should be stripped out by wp_user_personal_data_exporter()
|
||||
// because it's 'name' duplicates one exported by core.
|
||||
array(
|
||||
'name' => 'User ID',
|
||||
'value' => 'Some User ID',
|
||||
),
|
||||
// This item should be retained and included in the export.
|
||||
array(
|
||||
'name' => 'Test Additional Data Name',
|
||||
'value' => 'Test Additional Data Value',
|
||||
),
|
||||
);
|
||||
|
||||
return $additional_profile_data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user