- Timestamp:
- 07/17/2018 09:03:33 AM (7 years ago)
- Location:
- branches/4.9
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.9
-
branches/4.9/tests/phpunit/tests/functions/anonymization.php
r43082 r43468 3 3 * Test anonymization functions. 4 4 * 5 * @package WordPress 6 * 7 * @since 5.0.05 * @package WordPress\UnitTests 6 * 7 * @since 4.9.6 8 8 */ 9 9 … … 14 14 * @group privacy 15 15 * 16 * @since 5.0.016 * @since 4.9.6 17 17 */ 18 18 class Tests_Functions_Anonymization extends WP_UnitTestCase { … … 43 43 * Provide test cases for `test_wp_privacy_anonymize_ip()`. 44 44 * 45 * @since 5.0.0Moved 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()`. 46 46 * 47 47 * @return array { … … 213 213 */ 214 214 public function test_anonymize_email() { 215 $this->assert Equals( 'deleted@site.invalid', wp_privacy_anonymize_data( 'email', 'bar@example.com' ) );215 $this->assertSame( '', wp_privacy_anonymize_data( 'email', 'bar@example.com' ) ); 216 216 } 217 217 … … 220 220 */ 221 221 public function test_anonymize_url() { 222 $this->assert Equals( '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' ) ); 223 223 } 224 224 … … 245 245 $this->assertEquals( 'This content was deleted by the author.', wp_privacy_anonymize_data( 'longtext', $text ) ); 246 246 } 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 247 278 }
Note: See TracChangeset
for help on using the changeset viewer.