Make WordPress Core

Changeset 43077


Ignore:
Timestamp:
05/02/2018 12:11:50 AM (8 years ago)
Author:
SergeyBiryukov
Message:

Privacy: fix docs, formatting, white space, add tests for the personal data from comments exporter.

Props birgire.
Merges [42987] to the 4.9 branch.
See #43440.

Location:
branches/4.9
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-includes/comment.php

    r43076 r43077  
    31483148
    31493149/**
    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.
    31543156 */
    31553157function wp_register_comment_personal_data_exporter( $exporters ) {
     
    31653167 * Finds and exports personal data associated with an email address from the comments table.
    31663168 *
    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.
    31703174 */
    31713175function wp_comments_personal_data_exporter( $email_address, $page = 1 ) {
    31723176
    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.
    31783178        $number = 500;
    3179         $page = (int) $page;
     3179        $page   = (int) $page;
    31803180
    31813181        $data_to_export = array();
     
    32083208                        $value = '';
    32093209
    3210                         switch( $key ) {
     3210                        switch ( $key ) {
    32113211                                case 'comment_author':
    32123212                                case 'comment_author_email':
     
    32283228
    32293229                        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                                );
    32313234                        }
    32323235                }
  • branches/4.9/tests/phpunit/tests/comment.php

    r40981 r43077  
    778778                $this->assertSame( '1', $comment->comment_approved );
    779779        }
     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        }
    780899}
Note: See TracChangeset for help on using the changeset viewer.