MediaWiki REL1_31
ApiQueryTitleBlacklistTest.php
Go to the documentation of this file.
1<?php
14ini_set( 'include_path', ini_get( 'include_path' ) . ':' .
15 __DIR__ . '/../../../tests/phpunit/includes/api' );
16
22
23 function setUp() {
24 parent::setUp();
25 $this->doLogin();
26
28 $this->setMwGlobals( 'wgTitleBlacklistSources', [
29 [
30 'type' => 'file',
31 'src' => __DIR__ . '/testSource',
32 ],
33 ] );
34 }
35
36 function tearDown() {
38 parent::tearDown();
39 }
40
45 $unlisted = $this->doApiRequest( [
46 'action' => 'titleblacklist',
47 // evil_acc is blacklisted as <newaccountonly>
48 'tbtitle' => 'evil_acc',
49 'tbaction' => 'create',
50 'tbnooverride' => true,
51 ] );
52
53 $this->assertEquals(
54 'ok',
55 $unlisted[0]['titleblacklist']['result'],
56 'Not blacklisted title returns ok'
57 );
58 }
59
63 function testTboverride() {
65
66 // Allow all users to override the titleblacklist
67 $this->stashMwGlobals( 'wgGroupPermissions' );
68 $wgGroupPermissions['*']['tboverride'] = true;
69
70 $unlisted = $this->doApiRequest( [
71 'action' => 'titleblacklist',
72 'tbtitle' => 'bar',
73 'tbaction' => 'create',
74 ] );
75
76 $this->assertEquals(
77 'ok',
78 $unlisted[0]['titleblacklist']['result'],
79 'Blacklisted title returns ok if the user is allowd to tboverride'
80 );
81 }
82
87 $listed = $this->doApiRequest( [
88 'action' => 'titleblacklist',
89 'tbtitle' => 'bar',
90 'tbaction' => 'create',
91 'tbnooverride' => true,
92 ] );
93
94 $this->assertEquals(
95 'blacklisted',
96 $listed[0]['titleblacklist']['result'],
97 'Listed title returns error'
98 );
99 $this->assertEquals(
100 "The title \"bar\" has been banned from creation.\nIt matches the following " .
101 "blacklist entry: <code>[Bb]ar #example blacklist entry</code>",
102 $listed[0]['titleblacklist']['reason'],
103 'Listed title error text is as expected'
104 );
105
106 $this->assertEquals(
107 "titleblacklist-forbidden-edit",
108 $listed[0]['titleblacklist']['message'],
109 'Correct blacklist message name is returned'
110 );
111
112 $this->assertEquals(
113 "[Bb]ar #example blacklist entry",
114 $listed[0]['titleblacklist']['line'],
115 'Correct blacklist line is returned'
116 );
117 }
118
123 if ( !class_exists( 'AntiSpoof' ) ) {
124 $this->markTestSkipped( "This test requires the AntiSpoof extension" );
125 }
126
127 $listed = $this->doApiRequest( [
128 'action' => 'titleblacklist',
129 'tbtitle' => 'AVVVV',
130 'tbaction' => 'create',
131 'tbnooverride' => true,
132 ] );
133
134 $this->assertEquals(
135 'blacklisted',
136 $listed[0]['titleblacklist']['result'],
137 'Spoofed title is blacklisted'
138 );
139 }
140}
$wgGroupPermissions['sysop']['replacetext']
medium ApiQueryTitleBlacklist
testAntiSpoofIntegration()
Tests integration with the AntiSpoof extension.
testCheckingUnlistedTitle()
Verify we allow a title which is not blacklisted.
testCheckingBlackListedTitle()
Verify a blacklisted title gives out an error.
testTboverride()
Verify tboverride works.
doLogin( $testUser=null)
Previously this would do API requests to log in, as well as setting $wgUser and the request context's...
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
stashMwGlobals( $globalKeys)
Stashes the global, will be restored in tearDown()
static destroySingleton()
Destroy/reset the current singleton instance.