Merge "Drop cache interwiki"
[mediawiki.git] / tests / phpunit / includes / specials / SpecialPageTestBase.php
blob16e601619a9d8430f1736f05f5f6302d274851ef
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 tearDown(): void {
31 $obLevel = ob_get_level();
33 while ( ob_get_level() > $this->obLevel ) {
34 ob_end_clean();
37 try {
38 if ( $obLevel !== $this->obLevel ) {
39 $this->fail(
40 "Test changed output buffer level: was {$this->obLevel} before test, but $obLevel after test."
43 } finally {
44 parent::tearDown();
48 /**
49 * Returns a new instance of the special page under test.
51 * @return SpecialPage
53 abstract protected function newSpecialPage();
55 /**
56 * @param string|null $subPage The subpage parameter to call the page with
57 * @param WebRequest|null $request Web request that may contain URL parameters, etc
58 * @param Language|string|null $language The language which should be used in the context;
59 * defaults to "qqx"
60 * @param Authority|null $performer The user which should be used in the context of this special page
61 * @param bool $fullHtml if true, the entirety of the generated HTML will be returned, this
62 * includes the opening <!DOCTYPE> declaration and closing </html> tag. If false, only value
63 * of OutputPage::getHTML() will be returned except if the page is redirect or where OutputPage
64 * is completely disabled.
66 * @return array [ string, WebResponse ] A two-elements array containing the HTML output
67 * generated by the special page as well as the response object.
69 protected function executeSpecialPage(
70 $subPage = '',
71 ?WebRequest $request = null,
72 $language = null,
73 ?Authority $performer = null,
74 $fullHtml = false
75 ) {
76 return ( new SpecialPageExecutor() )->executeSpecialPage(
77 $this->newSpecialPage(),
78 $subPage,
79 $request,
80 $language ?: 'qqx',
81 $performer,
82 $fullHtml