diff options
Diffstat (limited to 'extensions/TitleBlacklist')
-rw-r--r-- | extensions/TitleBlacklist/.gitreview | 5 | ||||
-rw-r--r-- | extensions/TitleBlacklist/tests/ApiQueryTitleBlacklistTest.php | 110 | ||||
-rw-r--r-- | extensions/TitleBlacklist/tests/testSource | 4 |
3 files changed, 119 insertions, 0 deletions
diff --git a/extensions/TitleBlacklist/.gitreview b/extensions/TitleBlacklist/.gitreview new file mode 100644 index 00000000..964229c3 --- /dev/null +++ b/extensions/TitleBlacklist/.gitreview @@ -0,0 +1,5 @@ +[gerrit] +host=gerrit.wikimedia.org +port=29418 +project=mediawiki/extensions/TitleBlacklist.git +defaultbranch=master diff --git a/extensions/TitleBlacklist/tests/ApiQueryTitleBlacklistTest.php b/extensions/TitleBlacklist/tests/ApiQueryTitleBlacklistTest.php new file mode 100644 index 00000000..1f8164e7 --- /dev/null +++ b/extensions/TitleBlacklist/tests/ApiQueryTitleBlacklistTest.php @@ -0,0 +1,110 @@ +<?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' ); + +/** + * @group medium + **/ +class ApiQueryTitleBlacklistTest extends ApiTestCase { + + function setUp() { + global $wgTitleBlacklistSources; + 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() { + global $wgGroupPermissions; + + // 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' + ); + + } +} diff --git a/extensions/TitleBlacklist/tests/testSource b/extensions/TitleBlacklist/tests/testSource new file mode 100644 index 00000000..f73d9dd7 --- /dev/null +++ b/extensions/TitleBlacklist/tests/testSource @@ -0,0 +1,4 @@ +[Bb]ar #example blacklist entry +.*[Ff]ail.* +.*[Nn]yancat.* <errmsg=blacklisted-nyancat> +.*evil_acc.* <newaccountonly> |