MediaWiki  1.30.0
SpamBlacklistTest.php
Go to the documentation of this file.
1 <?php
2 
10  protected $spamFilter;
11 
22  protected $blacklist = [ '\b01bags\.com\b', 'sytes\.net' ];
23 
33  protected $whitelist = [ 'a5b\.sytes\.net' ];
34 
35  public function spamProvider() {
36  return [
37  'no spam' => [
38  [ 'https://example.com' ],
39  false,
40  ],
41  'revision with spam, with additional non-spam' => [
42  [ 'https://foo.com', 'http://01bags.com', 'http://bar.com' ],
43  [ '01bags.com' ],
44  ],
45 
46  'revision with spam using full width stop normalization' => [
47  [ 'http://01bags.com' ],
48  [ '01bags.com' ],
49  ],
50 
51  'revision with domain blacklisted as spam, but subdomain whitelisted' => [
52  [ 'http://a5b.sytes.net' ],
53  false,
54  ],
55  ];
56  }
57 
61  public function testSpam( $links, $expected ) {
62  $returnValue = $this->spamFilter->filter( $links, Title::newMainPage() );
63  $this->assertEquals( $expected, $returnValue );
64  }
65 
66  protected function setUp() {
67  parent::setUp();
68 
69  // create spam filter
70  $this->spamFilter = new SpamBlacklist;
71 
72  $this->setMwGlobals( 'wgBlacklistSettings', [
73  'files' => [],
74  ] );
75 
76  \MessageCache::singleton()->enable();
77  $this->insertPage( 'MediaWiki:Spam-blacklist', implode( "\n", $this->blacklist ) );
78  $this->insertPage( 'MediaWiki:Spam-whitelist', implode( "\n", $this->whitelist ) );
79 
80  // That only works if the spam blacklist is really reset
81  $instance = BaseBlacklist::getInstance( 'spam' );
82  $reflProp = new \ReflectionProperty( $instance, 'regexes' );
83  $reflProp->setAccessible( true );
84  $reflProp->setValue( $instance, false );
85  }
86 
87  protected function tearDown() {
88  \MessageCache::singleton()->disable();
89  parent::tearDown();
90  }
91 }
BaseBlacklist\getInstance
static getInstance( $type)
Returns an instance of the given blacklist.
Definition: BaseBlacklist.php:100
SpamBlacklist
Definition: SpamBlacklist_body.php:9
Title\newMainPage
static newMainPage()
Create a new Title for the Main Page.
Definition: Title.php:581
SpamBlacklistTest\setUp
setUp()
Definition: SpamBlacklistTest.php:66
SpamBlacklistTest\testSpam
testSpam( $links, $expected)
spamProvider
Definition: SpamBlacklistTest.php:61
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
SpamBlacklistTest\$spamFilter
SpamBlacklist $spamFilter
Definition: SpamBlacklistTest.php:10
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:672
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
MessageCache\singleton
static singleton()
Get the signleton instance of this class.
Definition: MessageCache.php:113
SpamBlacklistTest
SpamBlacklist.
Definition: SpamBlacklistTest.php:6
MediaWikiTestCase\insertPage
insertPage( $pageName, $text='Sample page for unit test.', $namespace=null)
Insert a new page.
Definition: MediaWikiTestCase.php:996
SpamBlacklistTest\$blacklist
array $blacklist
Spam blacklist regexes.
Definition: SpamBlacklistTest.php:22
captcha-old.blacklist
def blacklist
Definition: captcha-old.py:248
SpamBlacklistTest\$whitelist
array $whitelist
Spam whitelist regexes.
Definition: SpamBlacklistTest.php:33
SpamBlacklistTest\spamProvider
spamProvider()
Definition: SpamBlacklistTest.php:35
SpamBlacklistTest\tearDown
tearDown()
Definition: SpamBlacklistTest.php:87
array
the array() calling protocol came about after MediaWiki 1.4rc1.