mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/SpamBlacklist
synced 2024-11-23 22:54:57 +00:00
Add integration test
This test ensures that SpamBlacklist prevents edits that contain spam. Change-Id: I18e205752d9c5428bb52ebf41ad10fa29e813247
This commit is contained in:
parent
3b79f98ba8
commit
24d3c2d7c3
|
@ -71,6 +71,59 @@ class SpamBlacklistTest extends MediaWikiTestCase {
|
|||
$this->assertEquals( $expected, $returnValue );
|
||||
}
|
||||
|
||||
public function spamEditProvider() {
|
||||
return [
|
||||
'no spam' => [
|
||||
'https://example.com',
|
||||
true,
|
||||
],
|
||||
'revision with spam, with additional non-spam' => [
|
||||
"https://foo.com\nhttp://01bags.com\nhttp://bar.com'",
|
||||
false,
|
||||
],
|
||||
|
||||
'revision with domain blacklisted as spam, but subdomain whitelisted' => [
|
||||
'http://a5b.sytes.net',
|
||||
true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider spamEditProvider
|
||||
*/
|
||||
public function testSpamEdit( $text, $ok ) {
|
||||
$fields = [
|
||||
'wpTextbox1' => $text,
|
||||
'wpUnicodeCheck' => EditPage::UNICODE_CHECK,
|
||||
'wpRecreate' => true,
|
||||
];
|
||||
|
||||
$req = new FauxRequest( $fields, true );
|
||||
|
||||
$page = $this->getNonexistingTestPage( __METHOD__ );
|
||||
$title = $page->getTitle();
|
||||
|
||||
$articleContext = new RequestContext;
|
||||
$articleContext->setRequest( $req );
|
||||
$articleContext->setWikiPage( $page );
|
||||
$articleContext->setUser( $this->getTestUser()->getUser() );
|
||||
|
||||
$article = new Article( $title );
|
||||
$ep = new EditPage( $article );
|
||||
$ep->setContextTitle( $title );
|
||||
|
||||
$ep->importFormData( $req );
|
||||
|
||||
$status = $ep->attemptSave( $result );
|
||||
|
||||
$this->assertSame( $ok, $status->isOK() );
|
||||
|
||||
if ( !$ok ) {
|
||||
$this->assertTrue( $status->hasMessage( 'spam-blacklisted-link' ) );
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
|
|
Loading…
Reference in a new issue