Debian Codegraph @

extensions/TitleBlacklist/tests/phpunit/ApiTitleBlacklistTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Extension\TitleBlacklist\TitleBlacklist;
4 use MediaWiki\Tests\Api\ApiTestCase;
5
6 /**
7 * @group medium
8 * @group Database
9 * @covers \MediaWiki\Extension\TitleBlacklist\Api\ApiTitleBlacklist
10 */
11 class ApiTitleBlacklistTest extends ApiTestCase {
12
13 protected function setUp(): void {
14 parent::setUp();
15
16 TitleBlacklist::destroySingleton();
17 $this->overrideConfigValue( 'TitleBlacklistSources', [
18 [
19 'type' => 'file',
20 'src' => __DIR__ . '/testSource.txt',
21 ],
22 ] );
23 }
24
25 protected function tearDown(): void {
26 TitleBlacklist::destroySingleton();
27 parent::tearDown();
28 }
29
30 /**
31 * Verify we allow a title which is not blacklisted
32 */
33 public function testCheckingUnlistedTitle() {
34 $unlisted = $this->doApiRequest( [
35 'action' => 'titleblacklist',
36 // evil_acc is blacklisted as <newaccountonly>
37 'tbtitle' => 'evil_acc',
38 'tbaction' => 'create',
39 'tbnooverride' => true,
40 ] );
41
42 $this->assertEquals(
43 'ok',
44 $unlisted[0]['titleblacklist']['result'],
45 'Not blacklisted title returns ok'
46 );
47 }
48
49 /**
50 * Verify tboverride works
51 */
52 public function testTboverride() {
53 // Allow all users to override the titleblacklist
54 $this->setGroupPermissions( '*', 'tboverride', true );
55
56 $unlisted = $this->doApiRequest( [
57 'action' => 'titleblacklist',
58 'tbtitle' => 'bar',
59 'tbaction' => 'create',
60 ] );
61
62 $this->assertEquals(
63 'ok',
64 $unlisted[0]['titleblacklist']['result'],
65 'Blacklisted title returns ok if the user is allowd to tboverride'
66 );
67 }
68
69 /**
70 * Verify a blacklisted title gives out an error.
71 */
72 public function testCheckingBlackListedTitle() {
73 $listed = $this->doApiRequest( [
74 'action' => 'titleblacklist',
75 'tbtitle' => 'bar',
76 'tbaction' => 'create',
77 'tbnooverride' => true,
78 ] );
79
80 $this->assertEquals(
81 'blacklisted',
82 $listed[0]['titleblacklist']['result'],
83 'Listed title returns error'
84 );
85 $this->assertEquals(
86 "The title \"bar\" has been banned from creation.\nIt matches the following " .
87 "disallowed titles list entry: <code>[Bb]ar #example disallowed list entry</code>",
88 $listed[0]['titleblacklist']['reason'],
89 'Listed title error text is as expected'
90 );
91
92 $this->assertEquals(
93 "titleblacklist-forbidden-edit",
94 $listed[0]['titleblacklist']['message'],
95 'Correct blacklist message name is returned'
96 );
97
98 $this->assertEquals(
99 "[Bb]ar #example disallowed list entry",
100 $listed[0]['titleblacklist']['line'],
101 'Correct blacklist line is returned'
102 );
103 }
104
105 /**
106 * Tests integration with the AntiSpoof extension
107 */
108 public function testAntiSpoofIntegration() {
109 $this->markTestSkippedIfExtensionNotLoaded( 'AntiSpoof' );
110
111 $listed = $this->doApiRequest( [
112 'action' => 'titleblacklist',
113 'tbtitle' => 'AVVVV',
114 'tbaction' => 'create',
115 'tbnooverride' => true,
116 ] );
117
118 $this->assertEquals(
119 'blacklisted',
120 $listed[0]['titleblacklist']['result'],
121 'Spoofed title is blacklisted'
122 );
123 }
124 }