WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/17/2018 08:59:30 AM (4 years ago)
Author:
azaozz
Message:

Privacy: Don't replace comment author URL and email with anything.

Props TZ-Media, desrosj, birgire.
Fixes #44141.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions/anonymization.php

    r42971 r43467  
    33 * Test anonymization functions.
    44 *
    5  * @package WordPress
    6  *
    7  * @since 5.0.0
     5 * @package WordPress\UnitTests
     6 *
     7 * @since 4.9.6
    88 */
    99
     
    1414 * @group privacy
    1515 *
    16  * @since 5.0.0
     16 * @since 4.9.6
    1717 */
    1818class Tests_Functions_Anonymization extends WP_UnitTestCase {
     
    4343     * Provide test cases for `test_wp_privacy_anonymize_ip()`.
    4444     *
    45      * @since 5.0.0 Moved from `Test_WP_Community_Events::data_get_unsafe_client_ip_anonymization()`.
     45     * @since 4.9.6 Moved from `Test_WP_Community_Events::data_get_unsafe_client_ip_anonymization()`.
    4646     *
    4747     * @return array {
     
    213213     */
    214214    public function test_anonymize_email() {
    215         $this->assertEquals( 'deleted@site.invalid', wp_privacy_anonymize_data( 'email', 'bar@example.com' ) );
     215        $this->assertSame( '', wp_privacy_anonymize_data( 'email', 'bar@example.com' ) );
    216216    }
    217217
     
    220220     */
    221221    public function test_anonymize_url() {
    222         $this->assertEquals( 'https://site.invalid', wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' ) );
     222        $this->assertSame( '', wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' ) );
    223223    }
    224224
     
    245245        $this->assertEquals( 'This content was deleted by the author.', wp_privacy_anonymize_data( 'longtext', $text ) );
    246246    }
     247
     248    /**
     249     * Test text anonymization when a filter is added.
     250     *
     251     * @ticket 44141
     252     */
     253    public function test_anonymize_with_filter() {
     254        add_filter( 'wp_privacy_anonymize_data', array( $this, 'filter_wp_privacy_anonymize_data' ), 10, 3 );
     255        $actual_url   = wp_privacy_anonymize_data( 'url', 'https://example.com/author/username' );
     256        remove_filter( 'wp_privacy_anonymize_data', array( $this, 'filter_wp_privacy_anonymize_data' ), 10 );
     257
     258        $this->assertSame( 'http://local.host/why-this-was-removed', $actual_url );
     259    }
     260
     261    /**
     262     * Change the anonymized value for URLs.
     263     *
     264     * @since 4.9.8
     265     *
     266     * @param string  $anonymous Anonymized data.
     267     * @param string  $type      Type of the data.
     268     * @param string  $data      Original data.
     269     * @return string $anonymous Anonymized data.
     270     */
     271    public function filter_wp_privacy_anonymize_data( $anonymous, $type, $data ) {
     272        if ( 'url' === $type && 'example.com' === parse_url( $data, PHP_URL_HOST ) ) {
     273            return 'http://local.host/why-this-was-removed';
     274        }
     275        return $anonymous;
     276    }
     277
    247278}
Note: See TracChangeset for help on using the changeset viewer.