MediaWiki  1.30.0
FauxResponseTest.php
Go to the documentation of this file.
1 <?php
27  protected $response;
28 
29  protected function setUp() {
30  parent::setUp();
31  $this->response = new FauxResponse;
32  }
33 
40  public function testCookie() {
41  $expire = time() + 100;
42  $cookie = [
43  'value' => 'val',
44  'path' => '/path',
45  'domain' => 'domain',
46  'secure' => true,
47  'httpOnly' => false,
48  'raw' => false,
49  'expire' => $expire,
50  ];
51 
52  $this->assertEquals( null, $this->response->getCookie( 'xkey' ), 'Non-existing cookie' );
53  $this->response->setCookie( 'key', 'val', $expire, [
54  'prefix' => 'x',
55  'path' => '/path',
56  'domain' => 'domain',
57  'secure' => 1,
58  'httpOnly' => 0,
59  ] );
60  $this->assertEquals( 'val', $this->response->getCookie( 'xkey' ), 'Existing cookie' );
61  $this->assertEquals( $cookie, $this->response->getCookieData( 'xkey' ),
62  'Existing cookie (data)' );
63  $this->assertEquals( [ 'xkey' => $cookie ], $this->response->getCookies(),
64  'Existing cookies' );
65  }
66 
71  public function testHeader() {
72  $this->assertEquals( null, $this->response->getHeader( 'Location' ), 'Non-existing header' );
73 
74  $this->response->header( 'Location: http://localhost/' );
75  $this->assertEquals(
76  'http://localhost/',
77  $this->response->getHeader( 'Location' ),
78  'Set header'
79  );
80 
81  $this->response->header( 'Location: http://127.0.0.1/' );
82  $this->assertEquals(
83  'http://127.0.0.1/',
84  $this->response->getHeader( 'Location' ),
85  'Same header'
86  );
87 
88  $this->response->header( 'Location: http://127.0.0.2/', false );
89  $this->assertEquals(
90  'http://127.0.0.1/',
91  $this->response->getHeader( 'Location' ),
92  'Same header with override disabled'
93  );
94 
95  $this->response->header( 'Location: http://localhost/' );
96  $this->assertEquals(
97  'http://localhost/',
98  $this->response->getHeader( 'LOCATION' ),
99  'Get header case insensitive'
100  );
101  }
102 
106  public function testResponseCode() {
107  $this->response->header( 'HTTP/1.1 200' );
108  $this->assertEquals( 200, $this->response->getStatusCode(), 'Header with no message' );
109 
110  $this->response->header( 'HTTP/1.x 201' );
111  $this->assertEquals(
112  201,
113  $this->response->getStatusCode(),
114  'Header with no message and protocol 1.x'
115  );
116 
117  $this->response->header( 'HTTP/1.1 202 OK' );
118  $this->assertEquals( 202, $this->response->getStatusCode(), 'Normal header' );
119 
120  $this->response->header( 'HTTP/1.x 203 OK' );
121  $this->assertEquals(
122  203,
123  $this->response->getStatusCode(),
124  'Normal header with no message and protocol 1.x'
125  );
126 
127  $this->response->header( 'HTTP/1.x 204 OK', false, 205 );
128  $this->assertEquals(
129  205,
130  $this->response->getStatusCode(),
131  'Third parameter overrides the HTTP/... header'
132  );
133 
134  $this->response->statusHeader( 210 );
135  $this->assertEquals(
136  210,
137  $this->response->getStatusCode(),
138  'Handle statusHeader method'
139  );
140 
141  $this->response->header( 'Location: http://localhost/', false, 206 );
142  $this->assertEquals(
143  206,
144  $this->response->getStatusCode(),
145  'Third parameter with another header'
146  );
147  }
148 }
FauxResponseTest
Definition: FauxResponseTest.php:25
FauxResponseTest\testCookie
testCookie()
FauxResponse::setCookie FauxResponse::getCookie FauxResponse::getCookieData FauxResponse::getCookies.
Definition: FauxResponseTest.php:40
FauxResponseTest\testHeader
testHeader()
FauxResponse::getheader FauxResponse::header.
Definition: FauxResponseTest.php:71
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:35
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
FauxResponseTest\$response
FauxResponse $response
Definition: FauxResponseTest.php:27
FauxResponseTest\testResponseCode
testResponseCode()
FauxResponse::getStatusCode.
Definition: FauxResponseTest.php:106
FauxResponse
Definition: WebResponse.php:188
FauxResponseTest\setUp
setUp()
Definition: FauxResponseTest.php:29