MediaWiki  1.23.13
wfUrlencodeTest.php
Go to the documentation of this file.
1 <?php
7  #### TESTS ##############################################################
8 
12  public function testEncodingUrlWith( $input, $expected ) {
13  $this->verifyEncodingFor( 'Apache', $input, $expected );
14  }
15 
19  public function testEncodingUrlWithMicrosoftIis7( $input, $expected ) {
20  $this->verifyEncodingFor( 'Microsoft-IIS/7', $input, $expected );
21  }
22 
23  #### HELPERS #############################################################
24 
30  private function verifyEncodingFor( $server, $input, $expectations ) {
31  $expected = $this->extractExpect( $server, $expectations );
32 
33  // save up global
34  $old = isset( $_SERVER['SERVER_SOFTWARE'] )
35  ? $_SERVER['SERVER_SOFTWARE']
36  : null;
37  $_SERVER['SERVER_SOFTWARE'] = $server;
38  wfUrlencode( null );
39 
40  // do the requested test
41  $this->assertEquals(
42  $expected,
43  wfUrlencode( $input ),
44  "Encoding '$input' for server '$server' should be '$expected'"
45  );
46 
47  // restore global
48  if ( $old === null ) {
49  unset( $_SERVER['SERVER_SOFTWARE'] );
50  } else {
51  $_SERVER['SERVER_SOFTWARE'] = $old;
52  }
53  wfUrlencode( null );
54  }
55 
60  private function extractExpect( $server, $expectations ) {
61  if ( is_string( $expectations ) ) {
62  return $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" );
66  } else {
67  return $expectations[$server];
68  }
69  } else {
70  throw new MWException( __METHOD__ . " given invalid expectation for '$server'. Should be a string or an array( <http server name> => <string> ).\n" );
71  }
72  }
73 
74  #### PROVIDERS ###########################################################
75 
87  public static function provideURLS() {
88  return array(
89  ### RFC 1738 chars
90  // + is not safe
91  array( '+', '%2B' ),
92  // & and = not safe in queries
93  array( '&', '%26' ),
94  array( '=', '%3D' ),
95 
96  array( ':', array(
97  'Apache' => ':',
98  'Microsoft-IIS/7' => '%3A',
99  ) ),
100 
101  // remaining chars do not need encoding
102  array(
103  ';@$-_.!*',
104  ';@$-_.!*',
105  ),
106 
107  ### Other tests
108  // slash remain unchanged. %2F seems to break things
109  array( '/', '/' ),
110 
111  // Other 'funnies' chars
112  array( '[]', '%5B%5D' ),
113  array( '<>', '%3C%3E' ),
114 
115  // Apostrophe is encoded
116  array( '\'', '%27' ),
117  );
118  }
119 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
WfUrlencodeTest
The function only need a string parameter and might react to IIS7.0 @covers wfUrlencode.
Definition: wfUrlencodeTest.php:6
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:377
MWException
MediaWiki exception.
Definition: MWException.php:26
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
WfUrlencodeTest\verifyEncodingFor
verifyEncodingFor( $server, $input, $expectations)
Internal helper that actually run the test.
Definition: wfUrlencodeTest.php:30
WfUrlencodeTest\provideURLS
static provideURLS()
Format is either: array( 'input', 'expected' ); Or: array( 'input', array( 'Apache',...
Definition: wfUrlencodeTest.php:87
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
WfUrlencodeTest\testEncodingUrlWith
testEncodingUrlWith( $input, $expected)
@dataProvider provideURLS
Definition: wfUrlencodeTest.php:12
WfUrlencodeTest\extractExpect
extractExpect( $server, $expectations)
Interprets the provider array.
Definition: wfUrlencodeTest.php:60
WfUrlencodeTest\testEncodingUrlWithMicrosoftIis7
testEncodingUrlWithMicrosoftIis7( $input, $expected)
@dataProvider provideURLS
Definition: wfUrlencodeTest.php:19