MediaWiki REL1_34
ApiQueryTitleBlacklistTest.php
Go to the documentation of this file.
1<?php
18class ApiQueryTitleBlacklistTest extends ApiTestCase {
19
20 public function setUp() {
21 parent::setUp();
22 $this->doLogin();
23
25 $this->setMwGlobals( 'wgTitleBlacklistSources', [
26 [
27 'type' => 'file',
28 'src' => __DIR__ . '/testSource',
29 ],
30 ] );
31 }
32
33 public function tearDown() {
35 parent::tearDown();
36 }
37
41 public function testCheckingUnlistedTitle() {
42 $unlisted = $this->doApiRequest( [
43 'action' => 'titleblacklist',
44 // evil_acc is blacklisted as <newaccountonly>
45 'tbtitle' => 'evil_acc',
46 'tbaction' => 'create',
47 'tbnooverride' => true,
48 ] );
49
50 $this->assertEquals(
51 'ok',
52 $unlisted[0]['titleblacklist']['result'],
53 'Not blacklisted title returns ok'
54 );
55 }
56
60 public function testTboverride() {
61 // Allow all users to override the titleblacklist
62 $this->setGroupPermissions( '*', 'tboverride', true );
63
64 $unlisted = $this->doApiRequest( [
65 'action' => 'titleblacklist',
66 'tbtitle' => 'bar',
67 'tbaction' => 'create',
68 ] );
69
70 $this->assertEquals(
71 'ok',
72 $unlisted[0]['titleblacklist']['result'],
73 'Blacklisted title returns ok if the user is allowd to tboverride'
74 );
75 }
76
80 public function testCheckingBlackListedTitle() {
81 $listed = $this->doApiRequest( [
82 'action' => 'titleblacklist',
83 'tbtitle' => 'bar',
84 'tbaction' => 'create',
85 'tbnooverride' => true,
86 ] );
87
88 $this->assertEquals(
89 'blacklisted',
90 $listed[0]['titleblacklist']['result'],
91 'Listed title returns error'
92 );
93 $this->assertEquals(
94 "The title \"bar\" has been banned from creation.\nIt matches the following " .
95 "blacklist entry: <code>[Bb]ar #example blacklist entry</code>",
96 $listed[0]['titleblacklist']['reason'],
97 'Listed title error text is as expected'
98 );
99
100 $this->assertEquals(
101 "titleblacklist-forbidden-edit",
102 $listed[0]['titleblacklist']['message'],
103 'Correct blacklist message name is returned'
104 );
105
106 $this->assertEquals(
107 "[Bb]ar #example blacklist entry",
108 $listed[0]['titleblacklist']['line'],
109 'Correct blacklist line is returned'
110 );
111 }
112
116 public function testAntiSpoofIntegration() {
117 if ( !ExtensionRegistry::getInstance()->isLoaded( 'AntiSpoof' ) ) {
118 $this->markTestSkipped( "This test requires the AntiSpoof extension" );
119 }
120
121 $listed = $this->doApiRequest( [
122 'action' => 'titleblacklist',
123 'tbtitle' => 'AVVVV',
124 'tbaction' => 'create',
125 'tbnooverride' => true,
126 ] );
127
128 $this->assertEquals(
129 'blacklisted',
130 $listed[0]['titleblacklist']['result'],
131 'Spoofed title is blacklisted'
132 );
133 }
134}
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.
static destroySingleton()
Destroy/reset the current singleton instance.