Ticket #44141: 44141.2.diff
File 44141.2.diff, 7.1 KB (added by , 6 years ago) |
---|
-
src/wp-includes/comment.php
diff --git src/wp-includes/comment.php src/wp-includes/comment.php index 4c78eb9..9b09a1c 100644
function wp_comments_personal_data_eraser( $email_address, $page = 1 ) { 3440 3440 ) 3441 3441 ); 3442 3442 3443 /* translators: Name of a comment's author after being anonymized. */ 3443 3444 $anon_author = __( 'Anonymous' ); 3444 3445 $messages = array(); 3445 3446 … … function wp_comments_personal_data_eraser( $email_address, $page = 1 ) { 3486 3487 $updated = $wpdb->update( $wpdb->comments, $anonymized_comment, $args ); 3487 3488 3488 3489 if ( $updated ) { 3490 update_comment_meta( $comment_id, '_wp_anonymized', true ); 3489 3491 $items_removed = true; 3490 3492 clean_comment_cache( $comment_id ); 3491 3493 } else { -
src/wp-includes/functions.php
diff --git src/wp-includes/functions.php src/wp-includes/functions.php index 60229ee..d5682ed 100644
function wp_privacy_anonymize_ip( $ip_addr, $ipv6_fallback = false ) { 6212 6212 function wp_privacy_anonymize_data( $type, $data = '' ) { 6213 6213 6214 6214 switch ( $type ) { 6215 case 'email':6216 $anonymous = 'deleted@site.invalid';6217 break;6218 case 'url':6219 $anonymous = 'https://site.invalid';6220 break;6221 6215 case 'ip': 6222 6216 $anonymous = wp_privacy_anonymize_ip( $data ); 6223 6217 break; -
tests/phpunit/tests/comment.php
diff --git tests/phpunit/tests/comment.php tests/phpunit/tests/comment.php index 7f63c62..3eecf7e 100644
class Tests_Comment extends WP_UnitTestCase { 815 815 /** 816 816 * The `wp_comments_personal_data_eraser()` function should erase user's comments. 817 817 * 818 * @group privacy 818 819 * @ticket 43442 819 820 */ 820 821 public function test_wp_comments_personal_data_eraser() { … … class Tests_Comment extends WP_UnitTestCase { 856 857 'comment_ID' => (string) $comment_id, 857 858 'user_id' => '0', // Anonymized. 858 859 'comment_author' => 'Anonymous', // Anonymized. 859 'comment_author_email' => ' deleted@site.invalid', // Anonymized.860 'comment_author_url' => ' https://site.invalid', // Anonymized.860 'comment_author_email' => '', // Anonymized. 861 'comment_author_url' => '', // Anonymized. 861 862 'comment_author_IP' => '192.168.0.0', // Anonymized. 862 863 'comment_date' => '2018-04-14 17:20:00', 863 864 'comment_date_gmt' => '2018-04-14 17:20:00', … … class Tests_Comment extends WP_UnitTestCase { 866 867 ); 867 868 868 869 $this->assertSame( $expected, $actual ); 870 // Ensure the comment was marked as anonymized in meta. 871 $this->assertSame( '1', get_comment_meta( $comment_id, '_wp_anonymized', true ) ); 869 872 } 870 873 871 874 /** 872 875 * Testing the `wp_comments_personal_data_eraser()` function's output on an empty first page. 873 876 * 877 * @group privacy 874 878 * @ticket 43442 875 879 */ 876 880 public function test_wp_comments_personal_data_eraser_empty_first_page_output() { … … class Tests_Comment extends WP_UnitTestCase { 889 893 /** 890 894 * Testing the `wp_comments_personal_data_eraser()` function's output, for the non-empty first page. 891 895 * 896 * @group privacy 892 897 * @ticket 43442 893 898 */ 894 899 public function test_wp_comments_personal_data_eraser_non_empty_first_page_output() { … … class Tests_Comment extends WP_UnitTestCase { 920 925 /** 921 926 * Testing the `wp_comments_personal_data_eraser()` function's output, for an empty second page. 922 927 * 928 * @group privacy 923 929 * @ticket 43442 924 930 */ 925 931 public function test_wp_comments_personal_data_eraser_empty_second_page_output() { … … class Tests_Comment extends WP_UnitTestCase { 951 957 /** 952 958 * Testing the `wp_anonymize_comment` filter, to prevent comment anonymization. 953 959 * 960 * @group privacy 954 961 * @ticket 43442 955 962 */ 956 963 public function test_wp_anonymize_comment_filter_to_prevent_comment_anonymization() { … … class Tests_Comment extends WP_UnitTestCase { 987 994 /** 988 995 * Testing the `wp_anonymize_comment` filter, to prevent comment anonymization, with a custom message. 989 996 * 997 * @group privacy 990 998 * @ticket 43442 991 999 */ 992 1000 public function test_wp_anonymize_comment_filter_to_prevent_comment_anonymization_with_custom_message() { -
tests/phpunit/tests/functions/anonymization.php
diff --git tests/phpunit/tests/functions/anonymization.php tests/phpunit/tests/functions/anonymization.php index a5c9c8a..65052c0 100644
2 2 /** 3 3 * Test anonymization functions. 4 4 * 5 * @package WordPress 5 * @package WordPress\UnitTests 6 6 * 7 * @since 5.0.07 * @since 4.9.6 8 8 */ 9 9 10 10 /** … … 13 13 * @group functions.php 14 14 * @group privacy 15 15 * 16 * @since 5.0.016 * @since 4.9.6 17 17 */ 18 18 class Tests_Functions_Anonymization extends WP_UnitTestCase { 19 19 /** … … class Tests_Functions_Anonymization extends WP_UnitTestCase { 42 42 /** 43 43 * Provide test cases for `test_wp_privacy_anonymize_ip()`. 44 44 * 45 * @since 5.0.0Moved from `Test_WP_Community_Events::data_get_unsafe_client_ip_anonymization()`.45 * @since 4.9.6 Moved from `Test_WP_Community_Events::data_get_unsafe_client_ip_anonymization()`. 46 46 * 47 47 * @return array { 48 48 * @type array { … … class Tests_Functions_Anonymization extends WP_UnitTestCase { 212 212 * Test email anonymization of `wp_privacy_anonymize_data()`. 213 213 */ 214 214 public function test_anonymize_email() { 215 $this->assert Equals( 'deleted@site.invalid', wp_privacy_anonymize_data( 'email', 'bar@example.com' ) );215 $this->assertSame( '', wp_privacy_anonymize_data( 'email', 'bar@example.com' ) ); 216 216 } 217 217 218 218 /** 219 219 * Test url anonymization of `wp_privacy_anonymize_data()`. 220 220 */ 221 221 public function test_anonymize_url() { 222 $this->assert Equals( 'https://site.invalid', wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' ) );222 $this->assertSame( '', wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' ) ); 223 223 } 224 224 225 225 /** … … class Tests_Functions_Anonymization extends WP_UnitTestCase { 244 244 $text = __( 'Four score and seven years ago' ); 245 245 $this->assertEquals( 'This content was deleted by the author.', wp_privacy_anonymize_data( 'longtext', $text ) ); 246 246 } 247 248 /** 249 * Test text anonymization when a filter is added. 250 * 251 * @ticket 44141 252 */ 253 public function test_anonymize_with_filter() { 254 add_filter( 'wp_privacy_anonymize_data', array( $this, 'filter_wp_privacy_anonymize_data' ), 10, 3 ); 255 $actual_email = wp_privacy_anonymize_data( 'email', 'bar@example.com' ); 256 $actual_url = wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' ); 257 remove_filter( 'wp_privacy_anonymize_data', array( $this, 'filter_wp_privacy_anonymize_data' ), 10 ); 258 259 $this->assertSame( '', $actual_email ); 260 $this->assertSame( 'http://local.host/why-this-was-removed', $actual_url ); 261 } 262 263 /** 264 * Change the anonymized value for URLs. 265 * 266 * @since 4.9.7 267 * 268 * @param string $anonymous Anonymized data. 269 * @param string $type Type of the data. 270 * @param string $data Original data. 271 * @return string $anonymous Anonymized data. 272 */ 273 public function filter_wp_privacy_anonymize_data( $anonymous, $type, $data ) { 274 if ( 'url' === $type && 'example.com' === parse_url( $data, PHP_URL_HOST ) ) { 275 return 'http://local.host/why-this-was-removed'; 276 } 277 return $anonymous; 278 } 279 247 280 }