Changeset 43077
- Timestamp:
- 05/02/2018 12:11:50 AM (7 years ago)
- Location:
- branches/4.9
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.9
-
branches/4.9/src/wp-includes/comment.php
r43076 r43077 3148 3148 3149 3149 /** 3150 * Registers the personal data exporter for comments 3151 * 3152 * @param array $exporters An array of personal data exporters. 3153 * @return array An array of personal data exporters. 3150 * Registers the personal data exporter for comments. 3151 * 3152 * @since 4.9.6 3153 * 3154 * @param array $exporters An array of personal data exporters. 3155 * @return array $exporters An array of personal data exporters. 3154 3156 */ 3155 3157 function wp_register_comment_personal_data_exporter( $exporters ) { … … 3165 3167 * Finds and exports personal data associated with an email address from the comments table. 3166 3168 * 3167 * @param string $email_address The comment author email address. 3168 * @param int $page Comment page. 3169 * @return array An array of personal data. 3169 * @since 4.9.6 3170 * 3171 * @param string $email_address The comment author email address. 3172 * @param int $page Comment page. 3173 * @return array $return An array of personal data. 3170 3174 */ 3171 3175 function wp_comments_personal_data_exporter( $email_address, $page = 1 ) { 3172 3176 3173 // Technically, strtolower isn't necessary since get_comments will match email insensitive 3174 // But it is a good example for plugin developers whose targets might not be as generous 3175 $email_address = trim( strtolower( $email_address ) ); 3176 3177 // Limit us to 500 comments at a time to avoid timing out 3177 // Limit us to 500 comments at a time to avoid timing out. 3178 3178 $number = 500; 3179 $page = (int) $page;3179 $page = (int) $page; 3180 3180 3181 3181 $data_to_export = array(); … … 3208 3208 $value = ''; 3209 3209 3210 switch ( $key ) {3210 switch ( $key ) { 3211 3211 case 'comment_author': 3212 3212 case 'comment_author_email': … … 3228 3228 3229 3229 if ( ! empty( $value ) ) { 3230 $comment_data_to_export[] = array( 'name' => $name, 'value' => $value ); 3230 $comment_data_to_export[] = array( 3231 'name' => $name, 3232 'value' => $value, 3233 ); 3231 3234 } 3232 3235 } -
branches/4.9/tests/phpunit/tests/comment.php
r40981 r43077 778 778 $this->assertSame( '1', $comment->comment_approved ); 779 779 } 780 781 /** 782 * Testing the `wp_comments_personal_data_exporter()` function. 783 * 784 * @ticket 43440 785 */ 786 public function test_wp_comments_personal_data_exporter() { 787 $args = array( 788 'comment_post_ID' => self::$post_id, 789 'comment_author' => 'Comment Author', 790 'comment_author_email' => 'personal@local.host', 791 'comment_author_url' => 'https://local.host/', 792 'comment_author_IP' => '192.168.0.1', 793 'comment_agent' => 'SOME_AGENT', 794 'comment_date' => '2018-03-28 20:05:00', 795 'comment_content' => 'Comment', 796 ); 797 798 $c = self::factory()->comment->create( $args ); 799 800 $actual = wp_comments_personal_data_exporter( $args['comment_author_email'] ); 801 $expected = $args; 802 803 $this->assertTrue( $actual['done'] ); 804 805 // Number of exported comments. 806 $this->assertSame( 1, count( $actual['data'] ) ); 807 808 // Number of exported comment properties. 809 $this->assertSame( 8, count( $actual['data'][0]['data'] ) ); 810 811 // Exported group. 812 $this->assertSame( 'comments', $actual['data'][0]['group_id'] ); 813 $this->assertSame( 'Comments', $actual['data'][0]['group_label'] ); 814 815 // Exported comment properties. 816 $this->assertSame( $expected['comment_author'], $actual['data'][0]['data'][0]['value'] ); 817 $this->assertSame( $expected['comment_author_email'], $actual['data'][0]['data'][1]['value'] ); 818 $this->assertSame( $expected['comment_author_url'], $actual['data'][0]['data'][2]['value'] ); 819 $this->assertSame( $expected['comment_author_IP'], $actual['data'][0]['data'][3]['value'] ); 820 $this->assertSame( $expected['comment_agent'], $actual['data'][0]['data'][4]['value'] ); 821 $this->assertSame( $expected['comment_date'], $actual['data'][0]['data'][5]['value'] ); 822 $this->assertSame( $expected['comment_content'], $actual['data'][0]['data'][6]['value'] ); 823 $this->assertSame( get_comment_link( $c ), $actual['data'][0]['data'][7]['value'] ); 824 } 825 826 /** 827 * Testing the `wp_comments_personal_data_exporter()` function for no comments found. 828 * 829 * @ticket 43440 830 */ 831 public function test_wp_comments_personal_data_exporter_no_comments_found() { 832 833 $actual = wp_comments_personal_data_exporter( 'nocommentsfound@local.host' ); 834 835 $expected = array( 836 'data' => array(), 837 'done' => true, 838 ); 839 840 $this->assertSame( $expected, $actual ); 841 } 842 843 /** 844 * Testing the `wp_comments_personal_data_exporter()` function for an empty comment property. 845 * 846 * @ticket 43440 847 */ 848 public function test_wp_comments_personal_data_exporter_empty_comment_prop() { 849 $args = array( 850 'comment_post_ID' => self::$post_id, 851 'comment_author' => 'Comment Author', 852 'comment_author_email' => 'personal@local.host', 853 'comment_author_url' => 'https://local.host/', 854 'comment_author_IP' => '192.168.0.1', 855 'comment_date' => '2018-03-28 20:05:00', 856 'comment_agent' => '', 857 'comment_content' => 'Comment', 858 ); 859 860 $c = self::factory()->comment->create( $args ); 861 862 $actual = wp_comments_personal_data_exporter( $args['comment_author_email'] ); 863 864 $this->assertTrue( $actual['done'] ); 865 866 // Number of exported comments. 867 $this->assertSame( 1, count( $actual['data'] ) ); 868 869 // Number of exported comment properties. 870 $this->assertSame( 7, count( $actual['data'][0]['data'] ) ); 871 } 872 873 /** 874 * Testing the `wp_comments_personal_data_exporter()` function with an empty second page. 875 * 876 * @ticket 43440 877 */ 878 public function test_wp_comments_personal_data_exporter_empty_second_page() { 879 $args = array( 880 'comment_post_ID' => self::$post_id, 881 'comment_author' => 'Comment Author', 882 'comment_author_email' => 'personal@local.host', 883 'comment_author_url' => 'https://local.host/', 884 'comment_author_IP' => '192.168.0.1', 885 'comment_date' => '2018-03-28 20:05:00', 886 'comment_agent' => 'SOME_AGENT', 887 'comment_content' => 'Comment', 888 ); 889 890 $c = self::factory()->comment->create( $args ); 891 892 $actual = wp_comments_personal_data_exporter( $args['comment_author_email'], 2 ); 893 894 $this->assertTrue( $actual['done'] ); 895 896 // Number of exported comments. 897 $this->assertSame( 0, count( $actual['data'] ) ); 898 } 780 899 }
Note: See TracChangeset
for help on using the changeset viewer.