blob: e4bf26ef8d7ccd50162626c9c86ec52f74731228 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<?php
/**
* General integration test for special pages.
*
* @file
* @author Niklas Laxström
* @license GPL-2.0-or-later
*/
/**
* Integration tests for making sure special pages do not fail in unexpected ways when viewed
* without parameters as anonymous or logged in user.
* @group Database
* @group large
*/
class SpecialPagesTest extends MediaWikiTestCase {
protected function setUp() {
parent::setUp();
global $wgHooks;
$this->setMwGlobals( [
'wgHooks' => $wgHooks,
'wgTranslateTranslationServices' => [],
'wgTranslateCacheDirectory' => $this->getNewTempDirectory(),
] );
$wgHooks['TranslatePostInitGroups'] = [];
$mg = MessageGroups::singleton();
$mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
$mg->recache();
MessageIndex::setInstance( new HashMessageIndex() );
MessageIndex::singleton()->rebuild();
}
public static function provideSpecialPages() {
require __DIR__ . '/../../Autoload.php';
global $wgSpecialPages;
$pages = [];
foreach ( $wgSpecialPages as $name => $class ) {
if ( is_string( $class ) && isset( $al[$class] ) ) {
$pages[] = [ $name ];
}
}
return $pages;
}
/**
* @dataProvider provideSpecialPages
*/
public function testSpecialPage( $name ) {
$page = TranslateUtils::getSpecialPage( $name );
$title = $page->getPageTitle();
$context = RequestContext::newExtraneousContext( $title );
$page->setContext( $context );
try {
$page->run( null );
} catch ( PermissionsError $e ) {
// This is okay
wfDebug( 'Permissions error caught; expected.' );
} catch ( ErrorPageError $e ) {
// This is okay as well
wfDebug( 'Page error caught; expected.' );
}
$this->assertTrue( true, "Special page $name was executed successfully with anon user" );
$user = $this->getTestSysop()->getUser();
$context->setUser( $user );
$page->setContext( $context );
// This should not throw permission errors
try {
$page->run( null );
} catch ( ErrorPageError $e ) {
// This is okay here
wfDebug( 'Page error caught; expected.' );
}
$this->assertTrue( true, "Special page $name was executed succesfully with super user" );
}
}
|