4 * @covers SpecialPageData
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() );
26 public function provideExecute() {
29 $cases['Empty request'] = [ '', [], [], '!!', 200 ];
31 $cases['Only title specified'] = [
33 [ 'target' => 'Helsinki' ],
37 [ 'Location' => '!.+!' ]
40 $cases['Accept only HTML'] = [
42 [ 'target' => 'Helsinki' ],
43 [ 'Accept' => 'text/HTML' ],
46 [ 'Location' => '!Helsinki$!' ]
49 $cases['Accept only HTML with revid'] = [
52 'target' => 'Helsinki',
55 [ 'Accept' => 'text/HTML' ],
58 [ 'Location' => '!Helsinki(\?|&)oldid=4242!' ]
61 $cases['Nothing specified'] = [
67 [ 'Location' => '!Helsinki&action=raw!' ]
70 $cases['Nothing specified'] = [
76 [ 'Location' => '!Helsinki&action=raw!' ]
79 $cases['Invalid Accept header'] = [
82 [ 'Accept' => 'text/foobar' ],
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(
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 );
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.",