Make WordPress Core


Ignore:
Timestamp:
05/02/2018 12:11:50 AM (7 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:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • 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.