MediaWiki  1.30.0
SpecialPageDataTest.php
Go to the documentation of this file.
1 <?php
2 
14 
15  protected function newSpecialPage() {
16  $page = new SpecialPageData();
17 
18  // why is this needed?
19  $page->getContext()->setOutput( new OutputPage( $page->getContext() ) );
20 
21  $page->setRequestHandler( new PageDataRequestHandler() );
22 
23  return $page;
24  }
25 
26  public function provideExecute() {
27  $cases = [];
28 
29  $cases['Empty request'] = [ '', [], [], '!!', 200 ];
30 
31  $cases['Only title specified'] = [
32  '',
33  [ 'target' => 'Helsinki' ],
34  [],
35  '!!',
36  303,
37  [ 'Location' => '!.+!' ]
38  ];
39 
40  $cases['Accept only HTML'] = [
41  '',
42  [ 'target' => 'Helsinki' ],
43  [ 'Accept' => 'text/HTML' ],
44  '!!',
45  303,
46  [ 'Location' => '!Helsinki$!' ]
47  ];
48 
49  $cases['Accept only HTML with revid'] = [
50  '',
51  [
52  'target' => 'Helsinki',
53  'revision' => '4242',
54  ],
55  [ 'Accept' => 'text/HTML' ],
56  '!!',
57  303,
58  [ 'Location' => '!Helsinki(\?|&)oldid=4242!' ]
59  ];
60 
61  $cases['Nothing specified'] = [
62  'main/Helsinki',
63  [],
64  [],
65  '!!',
66  303,
67  [ 'Location' => '!Helsinki&action=raw!' ]
68  ];
69 
70  $cases['Nothing specified'] = [
71  '/Helsinki',
72  [],
73  [],
74  '!!',
75  303,
76  [ 'Location' => '!Helsinki&action=raw!' ]
77  ];
78 
79  $cases['Invalid Accept header'] = [
80  'main/Helsinki',
81  [],
82  [ 'Accept' => 'text/foobar' ],
83  '!!',
84  406,
85  [],
86  ];
87 
88  return $cases;
89  }
90 
101  public function testExecute(
102  $subpage,
103  array $params,
104  array $headers,
105  $expRegExp,
106  $expCode = 200,
107  array $expHeaders = []
108  ) {
109  $request = new FauxRequest( $params );
110  $request->response()->header( 'Status: 200 OK', true, 200 ); // init/reset
111 
112  foreach ( $headers as $name => $value ) {
113  $request->setHeader( strtoupper( $name ), $value );
114  }
115 
116  try {
117  /* @var FauxResponse $response */
118  list( $output, $response ) = $this->executeSpecialPage( $subpage, $request );
119 
120  $this->assertEquals( $expCode, $response->getStatusCode(), "status code" );
121  $this->assertRegExp( $expRegExp, $output, "output" );
122 
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" );
128  }
129  } catch ( HttpError $e ) {
130  $this->assertEquals( $expCode, $e->getStatusCode(), "status code" );
131  $this->assertRegExp( $expRegExp, $e->getHTML(), "error output" );
132  }
133  }
134 
136  $this->setContentLang( Language::factory( 'en' ) );
137  $request = new FauxRequest();
138  $request->response()->header( 'Status: 200 OK', true, 200 ); // init/reset
139 
140  list( $output, ) = $this->executeSpecialPage( '', $request );
141 
142  $this->assertContains(
143  "Content negotiation applies based on your client's Accept header.",
144  $output,
145  "output"
146  );
147  }
148 
149 }
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
SpecialPageDataTest\provideExecute
provideExecute()
Definition: SpecialPageDataTest.php:26
PageDataRequestHandler
Request handler implementing a data interface for mediawiki pages.
Definition: PageDataRequestHandler.php:14
$params
$params
Definition: styleTest.css.php:40
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
$output
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition: hooks.txt:2198
HttpError
Show an error that looks like an HTTP server error.
Definition: HttpError.php:30
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
SpecialPageDataTest\testSpecialPageWithoutParameters
testSpecialPageWithoutParameters()
Definition: SpecialPageDataTest.php:135
SpecialPageTestBase
Base class for testing special pages.
Definition: SpecialPageTestBase.php:14
SpecialPageDataTest
SpecialPageData.
Definition: SpecialPageDataTest.php:13
SpecialPageData
Special page to act as an endpoint for accessing raw page data.
Definition: SpecialPageData.php:10
OutputPage
This class should be covered by a general architecture document which does not exist as of January 20...
Definition: OutputPage.php:44
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
$request
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:2581
MediaWikiTestCase\setContentLang
setContentLang( $lang)
Definition: MediaWikiTestCase.php:886
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2141
$value
$value
Definition: styleTest.css.php:45
SpecialPageTestBase\executeSpecialPage
executeSpecialPage( $subPage='', WebRequest $request=null, $language=null, User $user=null)
Definition: SpecialPageTestBase.php:57
$response
this hook is for auditing only $response
Definition: hooks.txt:781
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:183
SpecialPageDataTest\newSpecialPage
newSpecialPage()
Returns a new instance of the special page under test.
Definition: SpecialPageDataTest.php:15
array
the array() calling protocol came about after MediaWiki 1.4rc1.
SpecialPageDataTest\testExecute
testExecute( $subpage, array $params, array $headers, $expRegExp, $expCode=200, array $expHeaders=[])
provideExecute
Definition: SpecialPageDataTest.php:101