MediaWiki  REL1_31
wfUrlencodeTest.php
Go to the documentation of this file.
1 <?php
2 
10  # ### TESTS ##############################################################
11 
15  public function testEncodingUrlWith( $input, $expected ) {
16  $this->verifyEncodingFor( 'Apache', $input, $expected );
17  }
18 
22  public function testEncodingUrlWithMicrosoftIis7( $input, $expected ) {
23  $this->verifyEncodingFor( 'Microsoft-IIS/7', $input, $expected );
24  }
25 
26  # ### HELPERS #############################################################
27 
32  private function verifyEncodingFor( $server, $input, $expectations ) {
33  $expected = $this->extractExpect( $server, $expectations );
34 
35  // save up global
36  $old = isset( $_SERVER['SERVER_SOFTWARE'] )
37  ? $_SERVER['SERVER_SOFTWARE']
38  : null;
39  $_SERVER['SERVER_SOFTWARE'] = $server;
40  wfUrlencode( null );
41 
42  // do the requested test
43  $this->assertEquals(
44  $expected,
46  "Encoding '$input' for server '$server' should be '$expected'"
47  );
48 
49  // restore global
50  if ( $old === null ) {
51  unset( $_SERVER['SERVER_SOFTWARE'] );
52  } else {
53  $_SERVER['SERVER_SOFTWARE'] = $old;
54  }
55  wfUrlencode( null );
56  }
57 
62  private function extractExpect( $server, $expectations ) {
63  if ( is_string( $expectations ) ) {
64  return $expectations;
65  } elseif ( is_array( $expectations ) ) {
66  if ( !array_key_exists( $server, $expectations ) ) {
67  throw new MWException( __METHOD__ . " expectation does not have any "
68  . "value for server name $server. Check the provider array.\n" );
69  } else {
70  return $expectations[$server];
71  }
72  } else {
73  throw new MWException( __METHOD__ . " given invalid expectation for "
74  . "'$server'. Should be a string or an array( <http server name> => <string> ).\n" );
75  }
76  }
77 
78  # ### PROVIDERS ###########################################################
79 
91  public static function provideURLS() {
92  return [
93  # ## RFC 1738 chars
94  // + is not safe
95  [ '+', '%2B' ],
96  // & and = not safe in queries
97  [ '&', '%26' ],
98  [ '=', '%3D' ],
99 
100  [ ':', [
101  'Apache' => ':',
102  'Microsoft-IIS/7' => '%3A',
103  ] ],
104 
105  // remaining chars do not need encoding
106  [
107  ';@$-_.!*',
108  ';@$-_.!*',
109  ],
110 
111  # ## Other tests
112  // slash remain unchanged. %2F seems to break things
113  [ '/', '/' ],
114  // T105265
115  [ '~', '~' ],
116 
117  // Other 'funnies' chars
118  [ '[]', '%5B%5D' ],
119  [ '<>', '%3C%3E' ],
120 
121  // Apostrophe is encoded
122  [ '\'', '%27' ],
123  ];
124  }
125 }
WfUrlencodeTest
The function only need a string parameter and might react to IIS7.0.
Definition: wfUrlencodeTest.php:9
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:340
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
MWException
MediaWiki exception.
Definition: MWException.php:26
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:145
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
WfUrlencodeTest\verifyEncodingFor
verifyEncodingFor( $server, $input, $expectations)
Internal helper that actually run the test.
Definition: wfUrlencodeTest.php:32
WfUrlencodeTest\provideURLS
static provideURLS()
Format is either: [ 'input', 'expected' ]; Or: [ 'input', [ 'Apache', 'expected' ],...
Definition: wfUrlencodeTest.php:91
WfUrlencodeTest\testEncodingUrlWith
testEncodingUrlWith( $input, $expected)
provideURLS
Definition: wfUrlencodeTest.php:15
WfUrlencodeTest\extractExpect
extractExpect( $server, $expectations)
Interprets the provider array.
Definition: wfUrlencodeTest.php:62
WfUrlencodeTest\testEncodingUrlWithMicrosoftIis7
testEncodingUrlWithMicrosoftIis7( $input, $expected)
provideURLS
Definition: wfUrlencodeTest.php:22