MediaWiki  1.31.0
ApiQueryTitleBlacklistTest.php
Go to the documentation of this file.
1 <?php
14 ini_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 }
MediaWikiTestCase\stashMwGlobals
stashMwGlobals( $globalKeys)
Stashes the global, will be restored in tearDown()
Definition: MediaWikiTestCase.php:730
ApiQueryTitleBlacklistTest\testCheckingBlackListedTitle
testCheckingBlackListedTitle()
Verify a blacklisted title gives out an error.
Definition: ApiQueryTitleBlacklistTest.php:86
ApiQueryTitleBlacklistTest\setUp
setUp()
Definition: ApiQueryTitleBlacklistTest.php:23
ApiQueryTitleBlacklistTest\tearDown
tearDown()
Definition: ApiQueryTitleBlacklistTest.php:36
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:100
ApiQueryTitleBlacklistTest\testAntiSpoofIntegration
testAntiSpoofIntegration()
Tests integration with the AntiSpoof extension.
Definition: ApiQueryTitleBlacklistTest.php:122
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:678
ApiQueryTitleBlacklistTest\testCheckingUnlistedTitle
testCheckingUnlistedTitle()
Verify we allow a title which is not blacklisted.
Definition: ApiQueryTitleBlacklistTest.php:44
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ApiTestCase
Definition: ApiTestCase.php:5
ApiQueryTitleBlacklistTest
medium ApiQueryTitleBlacklist
Definition: ApiQueryTitleBlacklistTest.php:21
ApiQueryTitleBlacklistTest\testTboverride
testTboverride()
Verify tboverride works.
Definition: ApiQueryTitleBlacklistTest.php:63
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:186
$wgGroupPermissions
$wgGroupPermissions['sysop']['replacetext']
Definition: ReplaceText.php:56