3
* Tests for includes/GlobalFunctions.php -> wfUrlencode()
5
* The function only need a string parameter and might react to IIS7.0
8
class wfUrlencodeTest extends MediaWikiTestCase {
10
#### TESTS ##############################################################
12
/** @dataProvider provideURLS */
13
public function testEncodingUrlWith( $input, $expected ) {
14
$this->verifyEncodingFor( 'Apache', $input, $expected );
17
/** @dataProvider provideURLS */
18
public function testEncodingUrlWithMicrosoftIis7( $input, $expected ) {
19
$this->verifyEncodingFor( 'Microsoft-IIS/7', $input, $expected );
22
#### HELPERS #############################################################
25
* Internal helper that actually run the test.
26
* Called by the public methods testEncodingUrlWith...()
29
private function verifyEncodingFor( $server, $input, $expectations ) {
30
$expected = $this->extractExpect( $server, $expectations );
33
$old = isset($_SERVER['SERVER_SOFTWARE'])
34
? $_SERVER['SERVER_SOFTWARE']
37
$_SERVER['SERVER_SOFTWARE'] = $server;
40
// do the requested test
43
wfUrlencode( $input ),
44
"Encoding '$input' for server '$server' should be '$expected'"
49
unset( $_SERVER['SERVER_SOFTWARE'] );
51
$_SERVER['SERVER_SOFTWARE'] = $old;
57
* Interprets the provider array. Return expected value depending
58
* the HTTP server name.
60
private function extractExpect( $server, $expectations ) {
61
if( is_string( $expectations ) ) {
63
} elseif( is_array( $expectations ) ) {
64
if( !array_key_exists( $server, $expectations ) ) {
65
throw new MWException( __METHOD__ . " expectation does not have any value for server name $server. Check the provider array.\n" );
67
return $expectations[$server];
70
throw new MWException( __METHOD__ . " given invalid expectation for '$server'. Should be a string or an array( <http server name> => <string> ).\n" );
75
#### PROVIDERS ###########################################################
79
* array( 'input', 'expected' );
82
* array( 'Apache', 'expected' ),
83
* array( 'Microsoft-IIS/7', 'expected' ),
85
* If you want to add other HTTP server name, you will have to add a new
86
* testing method much like the testEncodingUrlWith() method above.
88
public function provideURLS() {
93
// & and = not safe in queries
99
'Microsoft-IIS/7' => '%3A',
102
// remaining chars do not need encoding
109
// slash remain unchanged. %2F seems to break things
112
// Other 'funnies' chars
113
array( '[]', '%5B%5D' ),
114
array( '<>', '%3C%3E' ),
116
// Apostrophe is encoded
117
array( '\'', '%27' ),