MediaWiki  1.29.1
ApiQueryTitleBlacklistTest.php
Go to the documentation of this file.
1 <?php
14 ini_set( 'include_path', ini_get( 'include_path' ) . ':' . __DIR__ . '/../../../tests/phpunit/includes/api' );
15 
20 
21  function setUp() {
22  parent::setUp();
23  $this->doLogin();
24 
26  $this->setMwGlobals( 'wgTitleBlacklistSources', array(
27  array(
28  'type' => 'file',
29  'src' => __DIR__ . '/testSource',
30  ),
31  ) );
32  }
33 
34  function tearDown() {
36  parent::tearDown();
37  }
38 
43  $unlisted = $this->doApiRequest( array(
44  'action' => 'titleblacklist',
45  // evil_acc is blacklisted as <newaccountonly>
46  'tbtitle' => 'evil_acc',
47  'tbaction' => 'create',
48  'tbnooverride' => true,
49  ) );
50 
51  $this->assertEquals(
52  'ok',
53  $unlisted[0]['titleblacklist']['result'],
54  'Not blacklisted title returns ok'
55  );
56  }
57 
61  function testTboverride() {
62  global $wgGroupPermissions;
63 
64  // Allow all users to override the titleblacklist
65  $this->stashMwGlobals( 'wgGroupPermissions' );
66  $wgGroupPermissions['*']['tboverride'] = true;
67 
68  $unlisted = $this->doApiRequest( array(
69  'action' => 'titleblacklist',
70  'tbtitle' => 'bar',
71  'tbaction' => 'create',
72  ) );
73 
74  $this->assertEquals(
75  'ok',
76  $unlisted[0]['titleblacklist']['result'],
77  'Blacklisted title returns ok if the user is allowd to tboverride'
78  );
79  }
80 
85  $listed = $this->doApiRequest( array(
86  'action' => 'titleblacklist',
87  'tbtitle' => 'bar',
88  'tbaction' => 'create',
89  'tbnooverride' => true,
90  ) );
91 
92  $this->assertEquals(
93  'blacklisted',
94  $listed[0]['titleblacklist']['result'],
95  'Listed title returns error'
96  );
97  $this->assertEquals(
98  "The title \"bar\" has been banned from creation.\nIt matches the following blacklist entry: <code>[Bb]ar #example blacklist entry</code>",
99  $listed[0]['titleblacklist']['reason'],
100  'Listed title error text is as expected'
101  );
102 
103  $this->assertEquals(
104  "titleblacklist-forbidden-edit",
105  $listed[0]['titleblacklist']['message'],
106  'Correct blacklist message name is returned'
107  );
108 
109  $this->assertEquals(
110  "[Bb]ar #example blacklist entry",
111  $listed[0]['titleblacklist']['line'],
112  'Correct blacklist line is returned'
113  );
114  }
115 
120  if ( !class_exists( 'AntiSpoof') ) {
121  $this->markTestSkipped( "This test requires the AntiSpoof extension" );
122  }
123 
124  $listed = $this->doApiRequest( array(
125  'action' => 'titleblacklist',
126  'tbtitle' => 'AVVVV',
127  'tbaction' => 'create',
128  'tbnooverride' => true,
129  ) );
130 
131  $this->assertEquals(
132  'blacklisted',
133  $listed[0]['titleblacklist']['result'],
134  'Spoofed title is blacklisted'
135  );
136 
137  }
138 }
MediaWikiTestCase\stashMwGlobals
stashMwGlobals( $globalKeys)
Stashes the global, will be restored in tearDown()
Definition: MediaWikiTestCase.php:710
ApiQueryTitleBlacklistTest\testCheckingBlackListedTitle
testCheckingBlackListedTitle()
Verify a blacklisted title gives out an error.
Definition: ApiQueryTitleBlacklistTest.php:84
ApiQueryTitleBlacklistTest\setUp
setUp()
Definition: ApiQueryTitleBlacklistTest.php:21
ApiQueryTitleBlacklistTest\tearDown
tearDown()
Definition: ApiQueryTitleBlacklistTest.php:34
TitleBlacklist::destroySingleton
static destroySingleton()
Destroy/reset the current singleton instance.
Definition: TitleBlacklist.list.php:44
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:119
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:658
ApiQueryTitleBlacklistTest\testCheckingUnlistedTitle
testCheckingUnlistedTitle()
Verify we allow a title which is not blacklisted.
Definition: ApiQueryTitleBlacklistTest.php:42
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:19
ApiQueryTitleBlacklistTest\testTboverride
testTboverride()
Verify tboverride works.
Definition: ApiQueryTitleBlacklistTest.php:61
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
array
the array() calling protocol came about after MediaWiki 1.4rc1.