Do not insert page titles into querycache.qc_value
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialPageTestBase.php
1 <?php
2
3 /**
4 * Base class for testing special pages.
5 *
6 * @since 1.26
7 *
8 * @license GPL-2.0-or-later
9 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
10 * @author Daniel Kinzler
11 * @author Addshore
12 * @author Thiemo Kreuz
13 */
14 abstract class SpecialPageTestBase extends MediaWikiTestCase {
15
16 private $obLevel;
17
18 protected function setUp() {
19 parent::setUp();
20
21 $this->obLevel = ob_get_level();
22 }
23
24 protected function tearDown() {
25 $obLevel = ob_get_level();
26
27 while ( ob_get_level() > $this->obLevel ) {
28 ob_end_clean();
29 }
30
31 try {
32 if ( $obLevel !== $this->obLevel ) {
33 $this->fail(
34 "Test changed output buffer level: was {$this->obLevel} before test, but $obLevel after test."
35 );
36 }
37 } finally {
38 parent::tearDown();
39 }
40 }
41
42 /**
43 * Returns a new instance of the special page under test.
44 *
45 * @return SpecialPage
46 */
47 abstract protected function newSpecialPage();
48
49 /**
50 * @param string $subPage The subpage parameter to call the page with
51 * @param WebRequest|null $request Web request that may contain URL parameters, etc
52 * @param Language|string|null $language The language which should be used in the context
53 * @param User|null $user The user which should be used in the context of this special page
54 *
55 * @throws Exception
56 * @return array [ string, WebResponse ] A two-elements array containing the HTML output
57 * generated by the special page as well as the response object.
58 */
59 protected function executeSpecialPage(
60 $subPage = '',
61 WebRequest $request = null,
62 $language = null,
63 User $user = null
64 ) {
65 return ( new SpecialPageExecutor() )->executeSpecialPage(
66 $this->newSpecialPage(),
67 $subPage,
68 $request,
69 $language,
70 $user
71 );
72 }
73
74 }