rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / specials / SpecialPageDataTest.php
blobc93fe479c9dc890910e6d600924ef6d5e24855ac
1 <?php
3 /**
4 * @covers SpecialPageData
6 * @group Database
8 * @group SpecialPage
10 * @license GPL-2.0+
11 * @author Daniel Kinzler
13 class SpecialPageDataTest extends SpecialPageTestBase {
15 protected function newSpecialPage() {
16 $page = new SpecialPageData();
18 // why is this needed?
19 $page->getContext()->setOutput( new OutputPage( $page->getContext() ) );
21 $page->setRequestHandler( new PageDataRequestHandler() );
23 return $page;
26 public function provideExecute() {
27 $cases = [];
29 $cases['Empty request'] = [ '', [], [], '!!', 200 ];
31 $cases['Only title specified'] = [
32 '',
33 [ 'target' => 'Helsinki' ],
34 [],
35 '!!',
36 303,
37 [ 'Location' => '!.+!' ]
40 $cases['Accept only HTML'] = [
41 '',
42 [ 'target' => 'Helsinki' ],
43 [ 'Accept' => 'text/HTML' ],
44 '!!',
45 303,
46 [ 'Location' => '!Helsinki$!' ]
49 $cases['Accept only HTML with revid'] = [
50 '',
52 'target' => 'Helsinki',
53 'revision' => '4242',
55 [ 'Accept' => 'text/HTML' ],
56 '!!',
57 303,
58 [ 'Location' => '!Helsinki(\?|&)oldid=4242!' ]
61 $cases['Nothing specified'] = [
62 'main/Helsinki',
63 [],
64 [],
65 '!!',
66 303,
67 [ 'Location' => '!Helsinki&action=raw!' ]
70 $cases['Nothing specified'] = [
71 '/Helsinki',
72 [],
73 [],
74 '!!',
75 303,
76 [ 'Location' => '!Helsinki&action=raw!' ]
79 $cases['Invalid Accept header'] = [
80 'main/Helsinki',
81 [],
82 [ 'Accept' => 'text/foobar' ],
83 '!!',
84 406,
85 [],
88 return $cases;
91 /**
92 * @dataProvider provideExecute
94 * @param string $subpage The subpage to request (or '')
95 * @param array $params Request parameters
96 * @param array $headers Request headers
97 * @param string $expRegExp Regex to match the output against.
98 * @param int $expCode Expected HTTP status code
99 * @param array $expHeaders Expected HTTP response headers
101 public function testExecute(
102 $subpage,
103 array $params,
104 array $headers,
105 $expRegExp,
106 $expCode = 200,
107 array $expHeaders = []
109 $request = new FauxRequest( $params );
110 $request->response()->header( 'Status: 200 OK', true, 200 ); // init/reset
112 foreach ( $headers as $name => $value ) {
113 $request->setHeader( strtoupper( $name ), $value );
116 try {
117 /* @var FauxResponse $response */
118 list( $output, $response ) = $this->executeSpecialPage( $subpage, $request );
120 $this->assertEquals( $expCode, $response->getStatusCode(), "status code" );
121 $this->assertRegExp( $expRegExp, $output, "output" );
123 foreach ( $expHeaders as $name => $exp ) {
124 $value = $response->getHeader( $name );
125 $this->assertNotNull( $value, "header: $name" );
126 $this->assertInternalType( 'string', $value, "header: $name" );
127 $this->assertRegExp( $exp, $value, "header: $name" );
129 } catch ( HttpError $e ) {
130 $this->assertEquals( $expCode, $e->getStatusCode(), "status code" );
131 $this->assertRegExp( $expRegExp, $e->getHTML(), "error output" );
135 public function testSpecialPageWithoutParameters() {
136 $this->setContentLang( Language::factory( 'en' ) );
137 $request = new FauxRequest();
138 $request->response()->header( 'Status: 200 OK', true, 200 ); // init/reset
140 list( $output, ) = $this->executeSpecialPage( '', $request );
142 $this->assertContains(
143 "Content negotiation applies based on you client's Accept header.",
144 $output,
145 "output"