Mattflaschen has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/351216 )

Change subject: Import PHPUnit tests from Flow, plus one more
......................................................................

Import PHPUnit tests from Flow, plus one more

Based on Flow repo as of 6099ce48818c8188709352b592f9da118a361fa5 .
Used under GPLv2+

Change-Id: Ibac17d99e86688ced2989ce9ae45581f09c85bd4
---
A tests/phpunit/SpamBlacklistTest.php
1 file changed, 83 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SpamBlacklist 
refs/changes/16/351216/1

diff --git a/tests/phpunit/SpamBlacklistTest.php 
b/tests/phpunit/SpamBlacklistTest.php
new file mode 100644
index 0000000..caad07e
--- /dev/null
+++ b/tests/phpunit/SpamBlacklistTest.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ * @group Flow
+ */
+class SpamBlacklistTest extends MediaWikiTestCase {
+       /**
+        * @var SpamBlacklist
+        */
+       protected $spamFilter;
+
+       /**
+        * Spam blacklist & whitelist regexes. Examples taken from:
+        *
+        * @see http://meta.wikimedia.org/wiki/Spam_blacklist
+        * @see http://en.wikipedia.org/wiki/MediaWiki:Spam-blacklist
+        * @see http://en.wikipedia.org/wiki/MediaWiki:Spam-whitelist
+        *
+        * via Flow extension
+        *
+        * @var array
+        */
+       protected
+               $blacklist = array( '\b01bags\.com\b', 'sytes\.net' ),
+               $whitelist = array( 'a5b\.sytes\.net' );
+
+       public function spamProvider() {
+               return array(
+                       'no spam' => array(
+                               [ 'https://example.com' ],
+                               false,
+                       ),
+                       'revision with spam, with additional non-spam' => array(
+                               [ 'https://foo.com', 'http://01bags.com', 
'http://bar.com' ],
+                               [ '01bags.com' ],
+                       ),
+
+                       'revision with spam using full width stop 
normalization' => array(
+                               [ 'http://01bags.com' ],
+                               [ '01bags.com' ],
+                       ),
+
+                       'revision with domain blacklisted as spam, but 
subdomain whitelisted' => array(
+                               [ 'http://a5b.sytes.net' ],
+                               false,
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider spamProvider
+        */
+       public function testSpam( $links, $expected ) {
+               $returnValue = $this->spamFilter->filter( $links, 
Title::newMainPage() );
+               $this->assertEquals( $expected, $returnValue );
+       }
+
+       protected function setUp() {
+               parent::setUp();
+
+               // create spam filter
+               $this->spamFilter = new SpamBlacklist;
+
+               $this->setMwGlobals( 'wgBlacklistSettings', array(
+                       'files' => array(),
+               ) );
+
+               \MessageCache::singleton()->enable();
+               $this->insertPage( 'MediaWiki:Spam-blacklist', implode( "\n", 
$this->blacklist ) );
+               $this->insertPage( 'MediaWiki:Spam-whitelist', implode( "\n", 
$this->whitelist ) );
+
+               // That only works if the spam blacklist is really reset
+               $instance = BaseBlacklist::getInstance( 'spam' );
+               $reflProp = new \ReflectionProperty( $instance, 'regexes' );
+               $reflProp->setAccessible( true );
+               $reflProp->setValue( $instance, false );
+       }
+
+       protected function tearDown() {
+               \MessageCache::singleton()->disable();
+               parent::tearDown();
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/351216
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibac17d99e86688ced2989ce9ae45581f09c85bd4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SpamBlacklist
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to