MediaWiki REL1_34
SpamBlacklistTest.php
Go to the documentation of this file.
1<?php
2
8class SpamBlacklistTest extends MediaWikiTestCase {
12 protected $spamFilter;
13
24 protected $blacklist = [ '\b01bags\.com\b', 'sytes\.net' ];
25
35 protected $whitelist = [ 'a5b\.sytes\.net' ];
36
37 public function spamProvider() {
38 return [
39 'no spam' => [
40 [ 'https://example.com' ],
41 false,
42 ],
43 'revision with spam, with additional non-spam' => [
44 [ 'https://foo.com', 'http://01bags.com', 'http://bar.com' ],
45 [ '01bags.com' ],
46 ],
47
48 'revision with spam using full width stop normalization' => [
49 [ 'http://01bags.com' ],
50 [ '01bags.com' ],
51 ],
52
53 'revision with domain blacklisted as spam, but subdomain whitelisted' => [
54 [ 'http://a5b.sytes.net' ],
55 false,
56 ],
57 ];
58 }
59
63 public function testSpam( $links, $expected ) {
64 $returnValue = $this->spamFilter->filter( $links, Title::newMainPage() );
65 $this->assertEquals( $expected, $returnValue );
66 }
67
68 protected function setUp() {
69 parent::setUp();
70
71 // create spam filter
72 $this->spamFilter = new SpamBlacklist;
73
74 $this->setMwGlobals( 'wgBlacklistSettings', [
75 'files' => [],
76 ] );
77
78 \MessageCache::singleton()->enable();
79 $this->insertPage( 'MediaWiki:Spam-blacklist', implode( "\n", $this->blacklist ) );
80 $this->insertPage( 'MediaWiki:Spam-whitelist', implode( "\n", $this->whitelist ) );
81
82 // That only works if the spam blacklist is really reset
83 $instance = BaseBlacklist::getInstance( 'spam' );
84 $reflProp = new \ReflectionProperty( $instance, 'regexes' );
85 $reflProp->setAccessible( true );
86 $reflProp->setValue( $instance, false );
87 }
88
89 protected function tearDown() {
90 \MessageCache::singleton()->disable();
91 parent::tearDown();
92 }
93}
static getInstance( $type)
Returns an instance of the given blacklist.
@group SpamBlacklist @group Database @covers SpamBlacklist
testSpam( $links, $expected)
@dataProvider spamProvider
array $whitelist
Spam whitelist regexes.
array $blacklist
Spam blacklist regexes.
SpamBlacklist $spamFilter