From 24d3c2d7c3f51f6d9a008f45067f7807cdb13474 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 23 Jul 2021 15:13:34 +0200 Subject: [PATCH] Add integration test This test ensures that SpamBlacklist prevents edits that contain spam. Change-Id: I18e205752d9c5428bb52ebf41ad10fa29e813247 --- tests/phpunit/SpamBlacklistTest.php | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/phpunit/SpamBlacklistTest.php b/tests/phpunit/SpamBlacklistTest.php index 04f47380..0da10171 100644 --- a/tests/phpunit/SpamBlacklistTest.php +++ b/tests/phpunit/SpamBlacklistTest.php @@ -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();