MediaWiki REL1_30
FauxRequestTest.php
Go to the documentation of this file.
1<?php
2
4
5class FauxRequestTest extends PHPUnit_Framework_TestCase {
9 public function testConstructInvalidData() {
10 $this->setExpectedException( MWException::class, 'bogus data' );
11 $req = new FauxRequest( 'x' );
12 }
13
17 public function testConstructInvalidSession() {
18 $this->setExpectedException( MWException::class, 'bogus session' );
19 $req = new FauxRequest( [], false, 'x' );
20 }
21
25 public function testConstructWithSession() {
26 $session = SessionManager::singleton()->getEmptySession( new FauxRequest( [] ) );
27 $this->assertInstanceOf(
28 FauxRequest::class,
29 new FauxRequest( [], false, $session )
30 );
31 }
32
36 public function testGetText() {
37 $req = new FauxRequest( [ 'x' => 'Value' ] );
38 $this->assertEquals( 'Value', $req->getText( 'x' ) );
39 $this->assertEquals( '', $req->getText( 'z' ) );
40 }
41
42 // Integration test for parent method.
43 public function testGetVal() {
44 $req = new FauxRequest( [ 'crlf' => "A\r\nb" ] );
45 $this->assertSame( "A\r\nb", $req->getVal( 'crlf' ), 'CRLF' );
46 }
47
48 // Integration test for parent method.
49 public function testGetRawVal() {
50 $req = new FauxRequest( [
51 'x' => 'Value',
52 'y' => [ 'a' ],
53 'crlf' => "A\r\nb"
54 ] );
55 $this->assertSame( 'Value', $req->getRawVal( 'x' ) );
56 $this->assertSame( null, $req->getRawVal( 'z' ), 'Not found' );
57 $this->assertSame( null, $req->getRawVal( 'y' ), 'Array is ignored' );
58 $this->assertSame( "A\r\nb", $req->getRawVal( 'crlf' ), 'CRLF' );
59 }
60
64 public function testGetValues() {
65 $values = [ 'x' => 'Value', 'y' => '' ];
66 $req = new FauxRequest( $values );
67 $this->assertEquals( $values, $req->getValues() );
68 }
69
73 public function testGetQueryValues() {
74 $values = [ 'x' => 'Value', 'y' => '' ];
75
76 $req = new FauxRequest( $values );
77 $this->assertEquals( $values, $req->getQueryValues() );
78 $req = new FauxRequest( $values, /*wasPosted*/ true );
79 $this->assertEquals( [], $req->getQueryValues() );
80 }
81
85 public function testGetMethod() {
86 $req = new FauxRequest( [] );
87 $this->assertEquals( 'GET', $req->getMethod() );
88 $req = new FauxRequest( [], /*wasPosted*/ true );
89 $this->assertEquals( 'POST', $req->getMethod() );
90 }
91
95 public function testWasPosted() {
96 $req = new FauxRequest( [] );
97 $this->assertFalse( $req->wasPosted() );
98 $req = new FauxRequest( [], /*wasPosted*/ true );
99 $this->assertTrue( $req->wasPosted() );
100 }
101
107 public function testCookies() {
108 $req = new FauxRequest();
109 $this->assertSame( null, $req->getCookie( 'z', '' ) );
110
111 $req->setCookie( 'x', 'Value', '' );
112 $this->assertEquals( 'Value', $req->getCookie( 'x', '' ) );
113
114 $req->setCookies( [ 'x' => 'One', 'y' => 'Two' ], '' );
115 $this->assertEquals( 'One', $req->getCookie( 'x', '' ) );
116 $this->assertEquals( 'Two', $req->getCookie( 'y', '' ) );
117 }
118
124 public function testCookiesDefaultPrefix() {
126 $oldPrefix = $wgCookiePrefix;
127 $wgCookiePrefix = '_';
128
129 $req = new FauxRequest();
130 $this->assertSame( null, $req->getCookie( 'z' ) );
131
132 $req->setCookie( 'x', 'Value' );
133 $this->assertEquals( 'Value', $req->getCookie( 'x' ) );
134
135 $wgCookiePrefix = $oldPrefix;
136 }
137
141 public function testGetRequestURL() {
142 $req = new FauxRequest();
143 $this->setExpectedException( MWException::class );
144 $req->getRequestURL();
145 }
146
151 public function testSetRequestURL() {
152 $req = new FauxRequest();
153 $req->setRequestURL( 'https://example.org' );
154 $this->assertEquals( 'https://example.org', $req->getRequestURL() );
155 }
156
161 public function testProtocol() {
162 $req = new FauxRequest();
163 $this->assertEquals( 'http', $req->getProtocol() );
164 $req = new FauxRequest( [], false, null, 'http' );
165 $this->assertEquals( 'http', $req->getProtocol() );
166 $req = new FauxRequest( [], false, null, 'https' );
167 $this->assertEquals( 'https', $req->getProtocol() );
168 }
169
175 public function testGetSetHeader() {
176 $value = 'text/plain, text/html';
177
178 $request = new FauxRequest();
179 $request->setHeader( 'Accept', $value );
180
181 $this->assertEquals( $request->getHeader( 'Nonexistent' ), false );
182 $this->assertEquals( $request->getHeader( 'Accept' ), $value );
183 $this->assertEquals( $request->getHeader( 'ACCEPT' ), $value );
184 $this->assertEquals( $request->getHeader( 'accept' ), $value );
185 $this->assertEquals(
186 $request->getHeader( 'Accept', WebRequest::GETHEADER_LIST ),
187 [ 'text/plain', 'text/html' ]
188 );
189 }
190
194 public function testGetAllHeaders() {
195 $_SERVER['HTTP_TEST'] = 'Example';
196
197 $request = new FauxRequest();
198
199 $this->assertEquals(
200 [],
201 $request->getAllHeaders()
202 );
203
204 $this->assertEquals(
205 false,
206 $request->getHeader( 'test' )
207 );
208 }
209
214 public function testSessionData() {
215 $values = [ 'x' => 'Value', 'y' => '' ];
216
217 $req = new FauxRequest( [], false, /*session*/ $values );
218 $this->assertEquals( $values, $req->getSessionArray() );
219
220 $req = new FauxRequest();
221 $this->assertSame( null, $req->getSessionArray() );
222 }
223
229 public function testDummies() {
230 $req = new FauxRequest();
231 $this->assertEquals( '', $req->getRawQueryString() );
232 $this->assertEquals( '', $req->getRawPostString() );
233 $this->assertEquals( '', $req->getRawInput() );
234 }
235}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgCookiePrefix
Cookies generated by MediaWiki have names starting with this prefix.
testGetRequestURL()
FauxRequest::getRequestURL.
testDummies()
FauxRequest::getRawQueryString FauxRequest::getRawPostString FauxRequest::getRawInput.
testConstructInvalidSession()
FauxRequest::__construct.
testSetRequestURL()
FauxRequest::setRequestURL FauxRequest::getRequestURL.
testWasPosted()
FauxRequest::wasPosted.
testProtocol()
FauxRequest::__construct FauxRequest::getProtocol.
testGetText()
FauxRequest::getText.
testConstructInvalidData()
FauxRequest::__construct.
testSessionData()
FauxRequest::__construct FauxRequest::getSessionArray.
testCookies()
FauxRequest::getCookie FauxRequest::setCookie FauxRequest::setCookies.
testCookiesDefaultPrefix()
FauxRequest::getCookie FauxRequest::setCookie FauxRequest::setCookies.
testConstructWithSession()
FauxRequest::__construct.
testGetMethod()
FauxRequest::getMethod.
testGetSetHeader()
FauxRequest::setHeader FauxRequest::setHeaders FauxRequest::getHeader.
testGetValues()
FauxRequest::getValues.
testGetQueryValues()
FauxRequest::getQueryValues.
testGetAllHeaders()
FauxRequest::initHeaders.
WebRequest clone which takes values from a provided array.
This serves as the entry point to the MediaWiki session handling system.
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
this hook is for auditing only $req
Definition hooks.txt:988
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2775
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