Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / specials / SpecialPageTestBase.php
blob3ca48bacbfd566f68fda731c6eb8b77586d99570
1 <?php
3 use MediaWiki\Language\Language;
4 use MediaWiki\Permissions\Authority;
5 use MediaWiki\Request\WebRequest;
6 use MediaWiki\SpecialPage\SpecialPage;
8 /**
9 * Base class for testing special pages.
11 * @since 1.26
13 * @license GPL-2.0-or-later
14 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
15 * @author Daniel Kinzler
16 * @author Addshore
17 * @author Thiemo Kreuz
19 abstract class SpecialPageTestBase extends MediaWikiIntegrationTestCase {
21 /** @var int */
22 private $obLevel;
24 protected function setUp(): void {
25 parent::setUp();
27 $this->obLevel = ob_get_level();
30 protected function assertPostConditions(): void {
31 $obLevel = ob_get_level();
32 if ( $obLevel !== $this->obLevel ) {
33 $this->fail(
34 "Test changed output buffer level: was {$this->obLevel} before test, but $obLevel after test."
37 parent::assertPostConditions();
40 protected function tearDown(): void {
41 while ( ob_get_level() > $this->obLevel ) {
42 ob_end_clean();
44 parent::tearDown();
47 /**
48 * Returns a new instance of the special page under test.
50 * @return SpecialPage
52 abstract protected function newSpecialPage();
54 /**
55 * @param string|null $subPage The subpage parameter to call the page with
56 * @param WebRequest|null $request Web request that may contain URL parameters, etc
57 * @param Language|string|null $language The language which should be used in the context;
58 * defaults to "qqx"
59 * @param Authority|null $performer The user which should be used in the context of this special page
60 * @param bool $fullHtml if true, the entirety of the generated HTML will be returned, this
61 * includes the opening <!DOCTYPE> declaration and closing </html> tag. If false, only value
62 * of OutputPage::getHTML() will be returned except if the page is redirect or where OutputPage
63 * is completely disabled.
65 * @return array [ string, WebResponse ] A two-elements array containing the HTML output
66 * generated by the special page as well as the response object.
68 protected function executeSpecialPage(
69 $subPage = '',
70 ?WebRequest $request = null,
71 $language = null,
72 ?Authority $performer = null,
73 $fullHtml = false
74 ) {
75 return ( new SpecialPageExecutor() )->executeSpecialPage(
76 $this->newSpecialPage(),
77 $subPage,
78 $request,
79 $language ?: 'qqx',
80 $performer,
81 $fullHtml