MediaWiki  1.33.0
SpecialPageDataTest.php
Go to the documentation of this file.
1 <?php
2 
11 
12  protected function newSpecialPage() {
13  $page = new SpecialPageData();
14 
15  // why is this needed?
16  $page->getContext()->setOutput( new OutputPage( $page->getContext() ) );
17 
18  $page->setRequestHandler( new PageDataRequestHandler() );
19 
20  return $page;
21  }
22 
23  public function provideExecute() {
24  $cases = [];
25 
26  $cases['Empty request'] = [ '', [], [], '!!', 200 ];
27 
28  $cases['Only title specified'] = [
29  '',
30  [ 'target' => 'Helsinki' ],
31  [],
32  '!!',
33  303,
34  [ 'Location' => '!.+!' ]
35  ];
36 
37  $cases['Accept only HTML'] = [
38  '',
39  [ 'target' => 'Helsinki' ],
40  [ 'Accept' => 'text/HTML' ],
41  '!!',
42  303,
43  [ 'Location' => '!Helsinki$!' ]
44  ];
45 
46  $cases['Accept only HTML with revid'] = [
47  '',
48  [
49  'target' => 'Helsinki',
50  'revision' => '4242',
51  ],
52  [ 'Accept' => 'text/HTML' ],
53  '!!',
54  303,
55  [ 'Location' => '!Helsinki(\?|&)oldid=4242!' ]
56  ];
57 
58  $cases['Nothing specified'] = [
59  'main/Helsinki',
60  [],
61  [],
62  '!!',
63  303,
64  [ 'Location' => '!Helsinki&action=raw!' ]
65  ];
66 
67  $cases['Nothing specified'] = [
68  '/Helsinki',
69  [],
70  [],
71  '!!',
72  303,
73  [ 'Location' => '!Helsinki&action=raw!' ]
74  ];
75 
76  $cases['Invalid Accept header'] = [
77  'main/Helsinki',
78  [],
79  [ 'Accept' => 'text/foobar' ],
80  '!!',
81  406,
82  [],
83  ];
84 
85  return $cases;
86  }
87 
98  public function testExecute(
99  $subpage,
100  array $params,
101  array $headers,
102  $expRegExp,
103  $expCode = 200,
104  array $expHeaders = []
105  ) {
106  $request = new FauxRequest( $params );
107  $request->response()->header( 'Status: 200 OK', true, 200 ); // init/reset
108 
109  foreach ( $headers as $name => $value ) {
110  $request->setHeader( strtoupper( $name ), $value );
111  }
112 
113  try {
114  /* @var FauxResponse $response */
115  list( $output, $response ) = $this->executeSpecialPage( $subpage, $request );
116 
117  $this->assertEquals( $expCode, $response->getStatusCode(), "status code" );
118  $this->assertRegExp( $expRegExp, $output, "output" );
119 
120  foreach ( $expHeaders as $name => $exp ) {
121  $value = $response->getHeader( $name );
122  $this->assertNotNull( $value, "header: $name" );
123  $this->assertInternalType( 'string', $value, "header: $name" );
124  $this->assertRegExp( $exp, $value, "header: $name" );
125  }
126  } catch ( HttpError $e ) {
127  $this->assertEquals( $expCode, $e->getStatusCode(), "status code" );
128  $this->assertRegExp( $expRegExp, $e->getHTML(), "error output" );
129  }
130  }
131 
133  $this->setContentLang( Language::factory( 'en' ) );
134  $request = new FauxRequest();
135  $request->response()->header( 'Status: 200 OK', true, 200 ); // init/reset
136 
137  list( $output, ) = $this->executeSpecialPage( '', $request );
138 
139  $this->assertContains(
140  "Content negotiation applies based on your client's Accept header.",
141  $output,
142  "output"
143  );
144  }
145 
146 }
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
SpecialPageDataTest\provideExecute
provideExecute()
Definition: SpecialPageDataTest.php:23
PageDataRequestHandler
Request handler implementing a data interface for mediawiki pages.
Definition: PageDataRequestHandler.php:30
$params
$params
Definition: styleTest.css.php:44
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:132
SpecialPageTestBase
Base class for testing special pages.
Definition: SpecialPageTestBase.php:14
SpecialPageDataTest
SpecialPageData Database SpecialPage.
Definition: SpecialPageDataTest.php:10
$output
$output
Definition: SyntaxHighlight.php:334
SpecialPageData
Definition: SpecialPageData.php:31
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
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:2636
MediaWikiTestCase\setContentLang
setContentLang( $lang)
Definition: MediaWikiTestCase.php:1066
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2162
$value
$value
Definition: styleTest.css.php:49
SpecialPageTestBase\executeSpecialPage
executeSpecialPage( $subPage='', WebRequest $request=null, $language=null, User $user=null)
Definition: SpecialPageTestBase.php:59
$response
this hook is for auditing only $response
Definition: hooks.txt:780
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:215
SpecialPageDataTest\newSpecialPage
newSpecialPage()
Returns a new instance of the special page under test.
Definition: SpecialPageDataTest.php:12
SpecialPageDataTest\testExecute
testExecute( $subpage, array $params, array $headers, $expRegExp, $expCode=200, array $expHeaders=[])
provideExecute
Definition: SpecialPageDataTest.php:98