mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-14 19:28:31 +00:00
5d2cde1022
- Disabled by default, is a gated preference by wg variable - User specifies blocks in Echo preferences - Uses a TextArea with username separated by new lines as input - Still allows notifications to come through on a user's talk page - Cache the blacklist and whitelist Requested at <https://meta.wikimedia.org/wiki/2016_Community_Wishlist_Survey/Categories/Miscellaneous#Allow_users_to_restrict_who_can_send_them_notifications>. Bug: T150419 Change-Id: Ibf548da4aa600bdc7848cba1947436e56ac48a4a
74 lines
2.3 KiB
PHP
74 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group Echo
|
|
*/
|
|
class ContainmentSetTest extends MediaWikiTestCase {
|
|
|
|
public function testGenericContains() {
|
|
$list = new EchoContainmentSet( self::getTestUser()->getUser() );
|
|
|
|
$list->addArray( [ 'foo', 'bar' ] );
|
|
$this->assertTrue( $list->contains( 'foo' ) );
|
|
$this->assertTrue( $list->contains( 'bar' ) );
|
|
$this->assertFalse( $list->contains( 'whammo' ) );
|
|
|
|
$list->addArray( [ 'whammo' ] );
|
|
$this->assertTrue( $list->contains( 'whammo' ) );
|
|
}
|
|
|
|
public function testCachedListInnerListIsOnlyCalledOnce() {
|
|
|
|
// the global $wgMemc during tests is an EmptyBagOStuff, so it
|
|
// wont do anything. We use a HashBagOStuff to get more like a real
|
|
// client
|
|
$innerCache = new HashBagOStuff;
|
|
|
|
$inner = [ 'bing', 'bang' ];
|
|
// We use a mock instead of the real thing for the $this->once() assertion
|
|
// verifying that the cache doesn't just keep asking the inner object
|
|
$list = $this->getMockBuilder( 'EchoArrayList' )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$list->expects( $this->once() )
|
|
->method( 'getValues' )
|
|
->will( $this->returnValue( $inner ) );
|
|
|
|
$cached = new EchoCachedList( $innerCache, 'test_key', $list );
|
|
|
|
// First run through should hit the main list, and save to innerCache
|
|
$this->assertEquals( $inner, $cached->getValues() );
|
|
$this->assertEquals( $inner, $cached->getValues() );
|
|
|
|
// Reinitialize to get a fresh instance that will pull directly from
|
|
// innerCache without hitting the $list
|
|
$freshCached = new EchoCachedList( $innerCache, 'test_key', $list );
|
|
$this->assertEquals( $inner, $freshCached->getValues() );
|
|
}
|
|
|
|
/**
|
|
* @Database
|
|
*/
|
|
public function testOnWikiList() {
|
|
$this->editPage( 'User:Foo/Bar-baz', "abc\ndef\r\nghi\n\n\n" );
|
|
|
|
$list = new EchoOnWikiList( NS_USER, "Foo/Bar-baz" );
|
|
$this->assertEquals(
|
|
[ 'abc', 'def', 'ghi' ],
|
|
$list->getValues()
|
|
);
|
|
}
|
|
|
|
public function testOnWikiListNonExistant() {
|
|
$list = new EchoOnWikiList( NS_USER, "Some_Non_Existant_Page" );
|
|
$this->assertEquals( [], $list->getValues() );
|
|
}
|
|
|
|
protected function editPage( $pageName, $text, $summary = '', $defaultNs = NS_MAIN ) {
|
|
$title = Title::newFromText( $pageName, $defaultNs );
|
|
$page = WikiPage::factory( $title );
|
|
|
|
return $page->doEditContent( ContentHandler::makeContent( $text, $title ), $summary );
|
|
}
|
|
}
|