MediaWiki  1.27.2
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 
33  private function verifyEncodingFor( $server, $input, $expectations ) {
34  $expected = $this->extractExpect( $server, $expectations );
35 
36  // save up global
37  $old = isset( $_SERVER['SERVER_SOFTWARE'] )
38  ? $_SERVER['SERVER_SOFTWARE']
39  : null;
40  $_SERVER['SERVER_SOFTWARE'] = $server;
41  wfUrlencode( null );
42 
43  // do the requested test
44  $this->assertEquals(
45  $expected,
46  wfUrlencode( $input ),
47  "Encoding '$input' for server '$server' should be '$expected'"
48  );
49 
50  // restore global
51  if ( $old === null ) {
52  unset( $_SERVER['SERVER_SOFTWARE'] );
53  } else {
54  $_SERVER['SERVER_SOFTWARE'] = $old;
55  }
56  wfUrlencode( null );
57  }
58 
63  private function extractExpect( $server, $expectations ) {
64  if ( is_string( $expectations ) ) {
65  return $expectations;
66  } elseif ( is_array( $expectations ) ) {
67  if ( !array_key_exists( $server, $expectations ) ) {
68  throw new MWException( __METHOD__ . " expectation does not have any "
69  . "value for server name $server. Check the provider array.\n" );
70  } else {
71  return $expectations[$server];
72  }
73  } else {
74  throw new MWException( __METHOD__ . " given invalid expectation for "
75  . "'$server'. Should be a string or an array( <http server name> => <string> ).\n" );
76  }
77  }
78 
79  # ### PROVIDERS ###########################################################
80 
92  public static function provideURLS() {
93  return [
94  # ## RFC 1738 chars
95  // + is not safe
96  [ '+', '%2B' ],
97  // & and = not safe in queries
98  [ '&', '%26' ],
99  [ '=', '%3D' ],
100 
101  [ ':', [
102  'Apache' => ':',
103  'Microsoft-IIS/7' => '%3A',
104  ] ],
105 
106  // remaining chars do not need encoding
107  [
108  ';@$-_.!*',
109  ';@$-_.!*',
110  ],
111 
112  # ## Other tests
113  // slash remain unchanged. %2F seems to break things
114  [ '/', '/' ],
115  // T105265
116  [ '~', '~' ],
117 
118  // Other 'funnies' chars
119  [ '[]', '%5B%5D' ],
120  [ '<>', '%3C%3E' ],
121 
122  // Apostrophe is encoded
123  [ '\'', '%27' ],
124  ];
125  }
126 }
testEncodingUrlWithMicrosoftIis7($input, $expected)
provideURLS
The function only need a string parameter and might react to IIS7.0.
static provideURLS()
Format is either: array( 'input', 'expected' ); Or: array( 'input', array( 'Apache', 'expected' ), array( 'Microsoft-IIS/7', 'expected' ), ), If you want to add other HTTP server name, you will have to add a new testing method much like the testEncodingUrlWith() method above.
wfUrlencode($s)
We want some things to be included as literal characters in our title URLs for prettiness, which urlencode encodes by default.
testEncodingUrlWith($input, $expected)
provideURLS
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:35
extractExpect($server, $expectations)
Interprets the provider array.
verifyEncodingFor($server, $input, $expectations)
Internal helper that actually run the test.