2011-07-21 22:08:44 +00:00
|
|
|
<?php
|
2011-10-14 21:30:16 +00:00
|
|
|
/**
|
2012-08-29 13:35:12 +00:00
|
|
|
* Test the TitleBlacklist API.
|
2011-07-21 22:08:44 +00:00
|
|
|
*
|
|
|
|
* This wants to run with phpunit.php, like so:
|
|
|
|
* cd $IP/tests/phpunit
|
|
|
|
* php phpunit.php ../../extensions/TitleBlacklist/tests/ApiQueryTitleBlacklistTest.php
|
|
|
|
*
|
2012-08-29 13:35:12 +00:00
|
|
|
* The blacklist file is `testSource` and shared by all tests.
|
|
|
|
*
|
2011-07-21 22:08:44 +00:00
|
|
|
* Ian Baker <ian@wikimedia.org>
|
|
|
|
*/
|
|
|
|
|
2012-08-29 13:53:38 +00:00
|
|
|
ini_set( 'include_path', ini_get( 'include_path' ) . ':' . __DIR__ . '/../../../tests/phpunit/includes/api' );
|
2011-07-21 22:08:44 +00:00
|
|
|
|
2012-05-24 23:55:22 +00:00
|
|
|
/**
|
|
|
|
* @group medium
|
|
|
|
**/
|
2011-07-21 22:08:44 +00:00
|
|
|
class ApiQueryTitleBlacklistTest extends ApiTestCase {
|
|
|
|
|
|
|
|
function setUp() {
|
2012-08-29 13:35:12 +00:00
|
|
|
global $wgTitleBlacklistSources, $wgGroupPermissions;
|
2011-07-21 22:08:44 +00:00
|
|
|
parent::setUp();
|
|
|
|
$this->doLogin();
|
2011-10-14 21:30:16 +00:00
|
|
|
|
2011-07-21 22:08:44 +00:00
|
|
|
$wgTitleBlacklistSources = array(
|
|
|
|
array(
|
|
|
|
'type' => TBLSRC_FILE,
|
|
|
|
'src' => __DIR__ . '/testSource',
|
|
|
|
),
|
|
|
|
);
|
2012-08-29 13:35:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-10-17 21:52:05 +00:00
|
|
|
* Verify we allow a title which is not blacklisted
|
2012-08-29 13:35:12 +00:00
|
|
|
*/
|
|
|
|
function testCheckingUnlistedTitle() {
|
2011-07-21 22:08:44 +00:00
|
|
|
$unlisted = $this->doApiRequest( array(
|
|
|
|
'action' => 'titleblacklist',
|
2012-10-17 21:52:05 +00:00
|
|
|
// 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',
|
2011-07-21 22:08:44 +00:00
|
|
|
'tbaction' => 'create',
|
|
|
|
) );
|
|
|
|
|
2012-08-29 13:17:27 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
'ok',
|
|
|
|
$unlisted[0]['titleblacklist']['result'],
|
2012-10-17 21:52:05 +00:00
|
|
|
'Blacklisted title returns ok if the user is allowd to tboverride'
|
2012-08-29 13:17:27 +00:00
|
|
|
);
|
2012-08-29 13:35:12 +00:00
|
|
|
}
|
2011-07-21 22:08:44 +00:00
|
|
|
|
2012-08-29 13:35:12 +00:00
|
|
|
/**
|
2012-10-17 21:52:05 +00:00
|
|
|
* Verify a blacklisted title gives out an error.
|
2012-08-29 13:35:12 +00:00
|
|
|
*/
|
|
|
|
function testCheckingBlackListedTitle() {
|
2011-07-21 22:08:44 +00:00
|
|
|
$listed = $this->doApiRequest( array(
|
|
|
|
'action' => 'titleblacklist',
|
|
|
|
'tbtitle' => 'bar',
|
|
|
|
'tbaction' => 'create',
|
2012-10-17 21:52:05 +00:00
|
|
|
'tbnooverride' => true,
|
2011-07-21 22:08:44 +00:00
|
|
|
) );
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2012-08-29 13:17:27 +00:00
|
|
|
'blacklisted',
|
|
|
|
$listed[0]['titleblacklist']['result'],
|
|
|
|
'Listed title returns error'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2011-07-23 00:23:09 +00:00
|
|
|
"The title \"bar\" has been banned from creation.\nIt matches the following blacklist entry: <code>[Bb]ar #example blacklist entry</code>",
|
2012-08-29 13:17:27 +00:00
|
|
|
$listed[0]['titleblacklist']['reason'],
|
2011-07-29 17:19:51 +00:00
|
|
|
'Listed title error text is as expected'
|
2011-07-21 22:08:44 +00:00
|
|
|
);
|
2011-10-14 21:30:16 +00:00
|
|
|
|
2011-08-01 22:44:54 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
"titleblacklist-forbidden-edit",
|
2012-08-29 13:17:27 +00:00
|
|
|
$listed[0]['titleblacklist']['message'],
|
2011-08-01 22:44:54 +00:00
|
|
|
'Correct blacklist message name is returned'
|
|
|
|
);
|
2011-10-14 21:30:16 +00:00
|
|
|
|
2011-07-29 17:19:51 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
"[Bb]ar #example blacklist entry",
|
2012-08-29 13:17:27 +00:00
|
|
|
$listed[0]['titleblacklist']['line'],
|
2011-07-29 17:19:51 +00:00
|
|
|
'Correct blacklist line is returned'
|
|
|
|
);
|
|
|
|
|
2011-07-21 22:08:44 +00:00
|
|
|
}
|
2011-10-14 21:30:16 +00:00
|
|
|
}
|