MediaWiki  1.30.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 
21 
22  function setUp() {
23  parent::setUp();
24  $this->doLogin();
25 
27  $this->setMwGlobals( 'wgTitleBlacklistSources', [
28  [
29  'type' => 'file',
30  'src' => __DIR__ . '/testSource',
31  ],
32  ] );
33  }
34 
35  function tearDown() {
37  parent::tearDown();
38  }
39 
44  $unlisted = $this->doApiRequest( [
45  'action' => 'titleblacklist',
46  // evil_acc is blacklisted as <newaccountonly>
47  'tbtitle' => 'evil_acc',
48  'tbaction' => 'create',
49  'tbnooverride' => true,
50  ] );
51 
52  $this->assertEquals(
53  'ok',
54  $unlisted[0]['titleblacklist']['result'],
55  'Not blacklisted title returns ok'
56  );
57  }
58 
62  function testTboverride() {
64 
65  // Allow all users to override the titleblacklist
66  $this->stashMwGlobals( 'wgGroupPermissions' );
67  $wgGroupPermissions['*']['tboverride'] = true;
68 
69  $unlisted = $this->doApiRequest( [
70  'action' => 'titleblacklist',
71  'tbtitle' => 'bar',
72  'tbaction' => 'create',
73  ] );
74 
75  $this->assertEquals(
76  'ok',
77  $unlisted[0]['titleblacklist']['result'],
78  'Blacklisted title returns ok if the user is allowd to tboverride'
79  );
80  }
81 
86  $listed = $this->doApiRequest( [
87  'action' => 'titleblacklist',
88  'tbtitle' => 'bar',
89  'tbaction' => 'create',
90  'tbnooverride' => true,
91  ] );
92 
93  $this->assertEquals(
94  'blacklisted',
95  $listed[0]['titleblacklist']['result'],
96  'Listed title returns error'
97  );
98  $this->assertEquals(
99  "The title \"bar\" has been banned from creation.\nIt matches the following " .
100  "blacklist entry: <code>[Bb]ar #example blacklist entry</code>",
101  $listed[0]['titleblacklist']['reason'],
102  'Listed title error text is as expected'
103  );
104 
105  $this->assertEquals(
106  "titleblacklist-forbidden-edit",
107  $listed[0]['titleblacklist']['message'],
108  'Correct blacklist message name is returned'
109  );
110 
111  $this->assertEquals(
112  "[Bb]ar #example blacklist entry",
113  $listed[0]['titleblacklist']['line'],
114  'Correct blacklist line is returned'
115  );
116  }
117 
122  if ( !class_exists( 'AntiSpoof' ) ) {
123  $this->markTestSkipped( "This test requires the AntiSpoof extension" );
124  }
125 
126  $listed = $this->doApiRequest( [
127  'action' => 'titleblacklist',
128  'tbtitle' => 'AVVVV',
129  'tbaction' => 'create',
130  'tbnooverride' => true,
131  ] );
132 
133  $this->assertEquals(
134  'blacklisted',
135  $listed[0]['titleblacklist']['result'],
136  'Spoofed title is blacklisted'
137  );
138  }
139 }
MediaWikiTestCase\stashMwGlobals
stashMwGlobals( $globalKeys)
Stashes the global, will be restored in tearDown()
Definition: MediaWikiTestCase.php:724
ApiQueryTitleBlacklistTest\testCheckingBlackListedTitle
testCheckingBlackListedTitle()
Verify a blacklisted title gives out an error.
Definition: ApiQueryTitleBlacklistTest.php:85
ApiQueryTitleBlacklistTest\setUp
setUp()
Definition: ApiQueryTitleBlacklistTest.php:22
ApiQueryTitleBlacklistTest\tearDown
tearDown()
Definition: ApiQueryTitleBlacklistTest.php:35
TitleBlacklist::destroySingleton
static destroySingleton()
Destroy/reset the current singleton instance.
Definition: TitleBlacklist.list.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
ApiQueryTitleBlacklistTest\testAntiSpoofIntegration
testAntiSpoofIntegration()
Tests integration with the AntiSpoof extension.
Definition: ApiQueryTitleBlacklistTest.php:121
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:672
ApiQueryTitleBlacklistTest\testCheckingUnlistedTitle
testCheckingUnlistedTitle()
Verify we allow a title which is not blacklisted.
Definition: ApiQueryTitleBlacklistTest.php:43
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ApiTestCase\doLogin
doLogin( $testUser='sysop')
Definition: ApiTestCase.php:152
ApiTestCase
Definition: ApiTestCase.php:3
ApiQueryTitleBlacklistTest
medium
Definition: ApiQueryTitleBlacklistTest.php:20
ApiQueryTitleBlacklistTest\testTboverride
testTboverride()
Verify tboverride works.
Definition: ApiQueryTitleBlacklistTest.php:62
ApiTestCase\doApiRequest
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null)
Does the API request and returns the result.
Definition: ApiTestCase.php:73
$wgGroupPermissions
$wgGroupPermissions
Permission keys given to users in each group.
Definition: DefaultSettings.php:5129