wordpress-develop/tests/phpunit/tests/formatting/UrlencodeDeep.php
John Blackbourn d5b31e6ba2 Introduce map_deep(), a utility function that recursively maps a callable function to every item in an array or object. Works like array_walk_recursive() but works with objects too.
Updates `rawurlencode_deep()`, `urlencode_deep()`, and `stripslashes_deep()` to use `map_deep()`. Introduces `urldecode_deep()` for completeness.

Props wpmuguru, nbachiyski, boonebgorges, MikeHansenMe, chriscct7, realloc, johnbillion
Fixes #22300


git-svn-id: https://develop.svn.wordpress.org/trunk@35252 602fd350-edb4-49c9-b593-d223f7449a82
2015-10-17 23:25:21 +00:00

47 lines
1.2 KiB
PHP

<?php
/**
* @group formatting
* @ticket 22300
*/
class Tests_Formatting_UrlencodeDeep extends WP_UnitTestCase {
/**
* Data Provider
*/
public function data_test_values() {
return array(
array( 'qwerty123456', 'qwerty123456' ),
array( '|!"£$%&/()=?', '%7C%21%22%C2%A3%24%25%26%2F%28%29%3D%3F' ),
array( '^é*ç°§;:_-.,', '%5E%C3%A9%2A%C3%A7%C2%B0%C2%A7%3B%3A_-.%2C' ),
array( 'abc123 @#[]€', 'abc123+%40%23%5B%5D%E2%82%AC' ),
array( 'abc123 @#[]€', urlencode( 'abc123 @#[]€' ) ),
);
}
/**
* Validate the urlencode_deep function pair by pair
*
* @dataProvider data_test_values
*
* @param string $actual
* @param string $expected
*/
public function test_urlencode_deep_should_encode_individual_value( $actual, $expected ) {
$this->assertEquals( $expected, urlencode_deep( $actual ) );
}
/**
* Test the whole array as input
*/
public function test_urlencode_deep_should_encode_all_values_in_array() {
$data = $this->data_test_values();
$actual = wp_list_pluck( $data, 0 );
$expected = wp_list_pluck( $data, 1 );
$this->assertEquals( $expected, urlencode_deep( $actual ) );
}
}