Changeset 42987
- Timestamp:
- 04/18/2018 10:54:23 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment.php
r42888 r42987 3277 3277 3278 3278 /** 3279 * Registers the personal data exporter for comments 3280 * 3281 * @param array $exporters An array of personal data exporters. 3282 * @return array An array of personal data exporters. 3279 * Registers the personal data exporter for comments. 3280 * 3281 * @since 4.9.6 3282 * 3283 * @param array $exporters An array of personal data exporters. 3284 * @return array $exporters An array of personal data exporters. 3283 3285 */ 3284 3286 function wp_register_comment_personal_data_exporter( $exporters ) { … … 3294 3296 * Finds and exports personal data associated with an email address from the comments table. 3295 3297 * 3296 * @param string $email_address The comment author email address. 3297 * @param int $page Comment page. 3298 * @return array An array of personal data. 3298 * @since 4.9.6 3299 * 3300 * @param string $email_address The comment author email address. 3301 * @param int $page Comment page. 3302 * @return array $return An array of personal data. 3299 3303 */ 3300 3304 function wp_comments_personal_data_exporter( $email_address, $page = 1 ) { 3301 3305 3302 // Technically, strtolower isn't necessary since get_comments will match email insensitive 3303 // But it is a good example for plugin developers whose targets might not be as generous 3304 $email_address = trim( strtolower( $email_address ) ); 3305 3306 // Limit us to 500 comments at a time to avoid timing out 3306 // Limit us to 500 comments at a time to avoid timing out. 3307 3307 $number = 500; 3308 $page = (int) $page;3308 $page = (int) $page; 3309 3309 3310 3310 $data_to_export = array(); … … 3337 3337 $value = ''; 3338 3338 3339 switch ( $key ) {3339 switch ( $key ) { 3340 3340 case 'comment_author': 3341 3341 case 'comment_author_email': … … 3357 3357 3358 3358 if ( ! empty( $value ) ) { 3359 $comment_data_to_export[] = array( 'name' => $name, 'value' => $value ); 3359 $comment_data_to_export[] = array( 3360 'name' => $name, 3361 'value' => $value, 3362 ); 3360 3363 } 3361 3364 } -
trunk/tests/phpunit/tests/comment.php
r42343 r42987 892 892 $this->assertSame( '1', $comment->comment_approved ); 893 893 } 894 895 /** 896 * Testing the `wp_comments_personal_data_exporter()` function. 897 * 898 * @ticket 43440 899 */ 900 public function test_wp_comments_personal_data_exporter() { 901 $args = array( 902 'comment_post_ID' => self::$post_id, 903 'comment_author' => 'Comment Author', 904 'comment_author_email' => 'personal@local.host', 905 'comment_author_url' => 'https://local.host/', 906 'comment_author_IP' => '192.168.0.1', 907 'comment_agent' => 'SOME_AGENT', 908 'comment_date' => '2018-03-28 20:05:00', 909 'comment_content' => 'Comment', 910 ); 911 912 $c = self::factory()->comment->create( $args ); 913 914 $actual = wp_comments_personal_data_exporter( $args['comment_author_email'] ); 915 $expected = $args; 916 917 $this->assertTrue( $actual['done'] ); 918 919 // Number of exported comments. 920 $this->assertSame( 1, count( $actual['data'] ) ); 921 922 // Number of exported comment properties. 923 $this->assertSame( 8, count( $actual['data'][0]['data'] ) ); 924 925 // Exported group. 926 $this->assertSame( 'comments', $actual['data'][0]['group_id'] ); 927 $this->assertSame( 'Comments', $actual['data'][0]['group_label'] ); 928 929 // Exported comment properties. 930 $this->assertSame( $expected['comment_author'], $actual['data'][0]['data'][0]['value'] ); 931 $this->assertSame( $expected['comment_author_email'], $actual['data'][0]['data'][1]['value'] ); 932 $this->assertSame( $expected['comment_author_url'], $actual['data'][0]['data'][2]['value'] ); 933 $this->assertSame( $expected['comment_author_IP'], $actual['data'][0]['data'][3]['value'] ); 934 $this->assertSame( $expected['comment_agent'], $actual['data'][0]['data'][4]['value'] ); 935 $this->assertSame( $expected['comment_date'], $actual['data'][0]['data'][5]['value'] ); 936 $this->assertSame( $expected['comment_content'], $actual['data'][0]['data'][6]['value'] ); 937 $this->assertSame( get_comment_link( $c ), $actual['data'][0]['data'][7]['value'] ); 938 } 939 940 /** 941 * Testing the `wp_comments_personal_data_exporter()` function for no comments found. 942 * 943 * @ticket 43440 944 */ 945 public function test_wp_comments_personal_data_exporter_no_comments_found() { 946 947 $actual = wp_comments_personal_data_exporter( 'nocommentsfound@local.host' ); 948 949 $expected = array( 950 'data' => array(), 951 'done' => true, 952 ); 953 954 $this->assertSame( $expected, $actual ); 955 } 956 957 /** 958 * Testing the `wp_comments_personal_data_exporter()` function for an empty comment property. 959 * 960 * @ticket 43440 961 */ 962 public function test_wp_comments_personal_data_exporter_empty_comment_prop() { 963 $args = array( 964 'comment_post_ID' => self::$post_id, 965 'comment_author' => 'Comment Author', 966 'comment_author_email' => 'personal@local.host', 967 'comment_author_url' => 'https://local.host/', 968 'comment_author_IP' => '192.168.0.1', 969 'comment_date' => '2018-03-28 20:05:00', 970 'comment_agent' => '', 971 'comment_content' => 'Comment', 972 ); 973 974 $c = self::factory()->comment->create( $args ); 975 976 $actual = wp_comments_personal_data_exporter( $args['comment_author_email'] ); 977 978 $this->assertTrue( $actual['done'] ); 979 980 // Number of exported comments. 981 $this->assertSame( 1, count( $actual['data'] ) ); 982 983 // Number of exported comment properties. 984 $this->assertSame( 7, count( $actual['data'][0]['data'] ) ); 985 } 986 987 /** 988 * Testing the `wp_comments_personal_data_exporter()` function with an empty second page. 989 * 990 * @ticket 43440 991 */ 992 public function test_wp_comments_personal_data_exporter_empty_second_page() { 993 $args = array( 994 'comment_post_ID' => self::$post_id, 995 'comment_author' => 'Comment Author', 996 'comment_author_email' => 'personal@local.host', 997 'comment_author_url' => 'https://local.host/', 998 'comment_author_IP' => '192.168.0.1', 999 'comment_date' => '2018-03-28 20:05:00', 1000 'comment_agent' => 'SOME_AGENT', 1001 'comment_content' => 'Comment', 1002 ); 1003 1004 $c = self::factory()->comment->create( $args ); 1005 1006 $actual = wp_comments_personal_data_exporter( $args['comment_author_email'], 2 ); 1007 1008 $this->assertTrue( $actual['done'] ); 1009 1010 // Number of exported comments. 1011 $this->assertSame( 0, count( $actual['data'] ) ); 1012 } 894 1013 }
Note: See TracChangeset
for help on using the changeset viewer.