| | 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 | // Done. |
| | 918 | $this->assertSame( true, $actual['done'] ); |
| | 919 | |
| | 920 | // Number of exported comments. |
| | 921 | $this->assertSame( 1, count( $actual['data'] ) ); |
| | 922 | |
| | 923 | // Number of exported comment properties. |
| | 924 | $this->assertSame( 8, count( $actual['data'][0]['data'] ) ); |
| | 925 | |
| | 926 | // Exported group. |
| | 927 | $this->assertSame( 'comments', $actual['data'][0]['group_id'] ); |
| | 928 | $this->assertSame( 'Comments', $actual['data'][0]['group_label'] ); |
| | 929 | |
| | 930 | // Exported comment properties. |
| | 931 | $this->assertSame( $expected['comment_author'], $actual['data'][0]['data'][0]['value'] ); |
| | 932 | $this->assertSame( $expected['comment_author_email'], $actual['data'][0]['data'][1]['value'] ); |
| | 933 | $this->assertSame( $expected['comment_author_url'], $actual['data'][0]['data'][2]['value'] ); |
| | 934 | $this->assertSame( $expected['comment_author_IP'], $actual['data'][0]['data'][3]['value'] ); |
| | 935 | $this->assertSame( $expected['comment_agent'], $actual['data'][0]['data'][4]['value'] ); |
| | 936 | $this->assertSame( $expected['comment_date'], $actual['data'][0]['data'][5]['value'] ); |
| | 937 | $this->assertSame( $expected['comment_content'], $actual['data'][0]['data'][6]['value'] ); |
| | 938 | $this->assertSame( get_comment_link( $c ), $actual['data'][0]['data'][7]['value'] ); |
| | 939 | } |
| | 940 | |
| | 941 | /** |
| | 942 | * Testing the `wp_comments_personal_data_exporter()` function with no comments found. |
| | 943 | * |
| | 944 | * @ticket 43440 |
| | 945 | */ |
| | 946 | public function test_wp_comments_personal_data_exporter_with_no_comments_found() { |
| | 947 | |
| | 948 | $actual = wp_comments_personal_data_exporter( 'nocommentsfound@local.host' ); |
| | 949 | |
| | 950 | $expected = array( |
| | 951 | 'data' => array(), |
| | 952 | 'done' => true, |
| | 953 | ); |
| | 954 | |
| | 955 | $this->assertSame( $expected, $actual ); |
| | 956 | } |
| | 957 | |
| | 958 | /** |
| | 959 | * Testing the `wp_comments_personal_data_exporter()` function for an empty comment property. |
| | 960 | * |
| | 961 | * @ticket 43440 |
| | 962 | */ |
| | 963 | public function test_wp_comments_personal_data_exporter_with_empty_comment_prop() { |
| | 964 | $args = array( |
| | 965 | 'comment_post_ID' => self::$post_id, |
| | 966 | 'comment_author' => 'Comment Author', |
| | 967 | 'comment_author_email' => 'personal@local.host', |
| | 968 | 'comment_author_url' => 'https://local.host/', |
| | 969 | 'comment_author_IP' => '192.168.0.1', |
| | 970 | 'comment_date' => '2018-03-28 20:05:00', |
| | 971 | 'comment_agent' => '', |
| | 972 | 'comment_content' => 'Comment', |
| | 973 | ); |
| | 974 | |
| | 975 | $c = self::factory()->comment->create( $args ); |
| | 976 | |
| | 977 | $actual = wp_comments_personal_data_exporter( $args['comment_author_email'] ); |
| | 978 | |
| | 979 | $this->assertSame( true, $actual['done'] ); |
| | 980 | // Number of exported comments. |
| | 981 | $this->assertSame( 1, count( $actual['data'] ) ); |
| | 982 | // Number of exported comment properties. |
| | 983 | $this->assertSame( 7, count( $actual['data'][0]['data'] ) ); |
| | 984 | } |
| | 985 | |
| | 986 | /** |
| | 987 | * Testing the `wp_comments_personal_data_exporter()` function for the second page with less than 500 comments. |
| | 988 | * |
| | 989 | * @ticket 43440 |
| | 990 | */ |
| | 991 | public function test_wp_comments_personal_data_exporter_second_page() { |
| | 992 | $args = array( |
| | 993 | 'comment_post_ID' => self::$post_id, |
| | 994 | 'comment_author' => 'Comment Author', |
| | 995 | 'comment_author_email' => 'personal@local.host', |
| | 996 | 'comment_author_url' => 'https://local.host/', |
| | 997 | 'comment_author_IP' => '192.168.0.1', |
| | 998 | 'comment_date' => '2018-03-28 20:05:00', |
| | 999 | 'comment_agent' => 'SOME_AGENT', |
| | 1000 | 'comment_content' => 'Comment', |
| | 1001 | ); |
| | 1002 | |
| | 1003 | $c = self::factory()->comment->create( $args ); |
| | 1004 | |
| | 1005 | $actual = wp_comments_personal_data_exporter( $args['comment_author_email'], 2 ); |
| | 1006 | |
| | 1007 | $this->assertSame( true, $actual['done'] ); |
| | 1008 | // Number of exported comments. |
| | 1009 | $this->assertSame( 0, count( $actual['data'] ) ); |
| | 1010 | } |