mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TitleBlacklist
synced 2024-12-18 08:31:01 +00:00
fc27474834
I've fixed four issue with the API of this extension: 1. The extension always assumed the user wants to override the blacklist, if he's allowed to do so, but that's not the case. Introduced 'tbnooverride' to prevent that. 2. The API used actions not internally supported by TitleBlacklistEntry::matches() which made it impossible to check whether an account name is ok, if the regexp which would prevent this was set to new account only. Therefore I've introduced the new action 'new-account'. 3. Same as 2 for the 'upload' 4. The API always returned the 'titleblacklist-forbidden-edit' message, even if there was a more suitable one. Fixed that. Example: https://meta.wikimedia.org/w/api.php?action=titleblacklist&tbtitle=User:Steward&tbaction=create (this should match the expression .*steward.* <newaccountonly> on https://meta.wikimedia.org/wiki/Title_blacklist but it doesn't) Furthermore I've adjusted the unit tests slightly to test whether tboverride works and whether <newaccountonly> works. Change-Id: I2d948c84de39c6ee1c1eea7e6cd7b31506d6cb92
106 lines
2.5 KiB
PHP
106 lines
2.5 KiB
PHP
<?php
|
|
/**
|
|
* Test the TitleBlacklist API.
|
|
*
|
|
* This wants to run with phpunit.php, like so:
|
|
* cd $IP/tests/phpunit
|
|
* php phpunit.php ../../extensions/TitleBlacklist/tests/ApiQueryTitleBlacklistTest.php
|
|
*
|
|
* The blacklist file is `testSource` and shared by all tests.
|
|
*
|
|
* Ian Baker <ian@wikimedia.org>
|
|
*/
|
|
|
|
ini_set( 'include_path', ini_get( 'include_path' ) . ':' . __DIR__ . '/../../../tests/phpunit/includes/api' );
|
|
|
|
class ApiQueryTitleBlacklistTest extends ApiTestCase {
|
|
|
|
function setUp() {
|
|
global $wgTitleBlacklistSources, $wgGroupPermissions;
|
|
parent::setUp();
|
|
$this->doLogin();
|
|
|
|
$wgTitleBlacklistSources = array(
|
|
array(
|
|
'type' => TBLSRC_FILE,
|
|
'src' => __DIR__ . '/testSource',
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Verify we allow a title which is not blacklisted
|
|
*/
|
|
function testCheckingUnlistedTitle() {
|
|
$unlisted = $this->doApiRequest( array(
|
|
'action' => 'titleblacklist',
|
|
// evil_acc is blacklisted as <newaccountonly>
|
|
'tbtitle' => 'evil_acc',
|
|
'tbaction' => 'create',
|
|
'tbnooverride' => true,
|
|
) );
|
|
|
|
$this->assertEquals(
|
|
'ok',
|
|
$unlisted[0]['titleblacklist']['result'],
|
|
'Not blacklisted title returns ok'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Verify tboverride works
|
|
*/
|
|
function testTboverride() {
|
|
// Allow all users to override the titleblacklist
|
|
$wgGroupPermissions['*']['tboverride'] = true;
|
|
|
|
$unlisted = $this->doApiRequest( array(
|
|
'action' => 'titleblacklist',
|
|
'tbtitle' => 'bar',
|
|
'tbaction' => 'create',
|
|
) );
|
|
|
|
$this->assertEquals(
|
|
'ok',
|
|
$unlisted[0]['titleblacklist']['result'],
|
|
'Blacklisted title returns ok if the user is allowd to tboverride'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Verify a blacklisted title gives out an error.
|
|
*/
|
|
function testCheckingBlackListedTitle() {
|
|
$listed = $this->doApiRequest( array(
|
|
'action' => 'titleblacklist',
|
|
'tbtitle' => 'bar',
|
|
'tbaction' => 'create',
|
|
'tbnooverride' => true,
|
|
) );
|
|
|
|
$this->assertEquals(
|
|
'blacklisted',
|
|
$listed[0]['titleblacklist']['result'],
|
|
'Listed title returns error'
|
|
);
|
|
$this->assertEquals(
|
|
"The title \"bar\" has been banned from creation.\nIt matches the following blacklist entry: <code>[Bb]ar #example blacklist entry</code>",
|
|
$listed[0]['titleblacklist']['reason'],
|
|
'Listed title error text is as expected'
|
|
);
|
|
|
|
$this->assertEquals(
|
|
"titleblacklist-forbidden-edit",
|
|
$listed[0]['titleblacklist']['message'],
|
|
'Correct blacklist message name is returned'
|
|
);
|
|
|
|
$this->assertEquals(
|
|
"[Bb]ar #example blacklist entry",
|
|
$listed[0]['titleblacklist']['line'],
|
|
'Correct blacklist line is returned'
|
|
);
|
|
|
|
}
|
|
}
|