MediaWiki  1.32.5
ApiQueryTitleBlacklistTest.php
Go to the documentation of this file.
1 <?php
19 
20  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  function tearDown() {
35  parent::tearDown();
36  }
37 
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  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 
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 
117  if ( !class_exists( '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 }
ApiQueryTitleBlacklistTest\testCheckingBlackListedTitle
testCheckingBlackListedTitle()
Verify a blacklisted title gives out an error.
Definition: ApiQueryTitleBlacklistTest.php:80
ApiQueryTitleBlacklistTest\setUp
setUp()
Definition: ApiQueryTitleBlacklistTest.php:20
ApiQueryTitleBlacklistTest\tearDown
tearDown()
Definition: ApiQueryTitleBlacklistTest.php:33
TitleBlacklist\destroySingleton
static destroySingleton()
Destroy/reset the current singleton instance.
Definition: TitleBlacklist.php:47
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ApiTestCase\doApiRequest
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
Definition: ApiTestCase.php:63
ApiQueryTitleBlacklistTest\testAntiSpoofIntegration
testAntiSpoofIntegration()
Tests integration with the AntiSpoof extension.
Definition: ApiQueryTitleBlacklistTest.php:116
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:706
ApiQueryTitleBlacklistTest\testCheckingUnlistedTitle
testCheckingUnlistedTitle()
Verify we allow a title which is not blacklisted.
Definition: ApiQueryTitleBlacklistTest.php:41
ApiTestCase
Definition: ApiTestCase.php:5
ApiQueryTitleBlacklistTest
Test the TitleBlacklist API.
Definition: ApiQueryTitleBlacklistTest.php:18
ApiQueryTitleBlacklistTest\testTboverride
testTboverride()
Verify tboverride works.
Definition: ApiQueryTitleBlacklistTest.php:60
MediaWikiTestCase\setGroupPermissions
setGroupPermissions( $newPerms, $newKey=null, $newValue=null)
Alters $wgGroupPermissions for the duration of the test.
Definition: MediaWikiTestCase.php:1092
ApiTestCase\doLogin
doLogin( $testUser=null)
Previously this would do API requests to log in, as well as setting $wgUser and the request context's...
Definition: ApiTestCase.php:149