| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Test; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Notifications\ArrayList; |
| 6 |
use MediaWiki\Extension\Notifications\CachedList; |
| 7 |
use MediaWiki\Extension\Notifications\ContainmentSet; |
| 8 |
use MediaWiki\Extension\Notifications\OnWikiList; |
| 9 |
use MediaWikiIntegrationTestCase; |
| 10 |
use Wikimedia\ObjectCache\HashBagOStuff; |
| 11 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
class ContainmentSetTest extends MediaWikiIntegrationTestCase { |
| 19 |
|
| 20 |
public function testGenericContains() { |
| 21 |
$list = new ContainmentSet( self::getTestUser()->getUser() ); |
| 22 |
|
| 23 |
$list->addArray( [ 'foo', 'bar' ] ); |
| 24 |
$this->assertTrue( $list->contains( 'foo' ) ); |
| 25 |
$this->assertTrue( $list->contains( 'bar' ) ); |
| 26 |
$this->assertFalse( $list->contains( 'whammo' ) ); |
| 27 |
|
| 28 |
$list->addArray( [ 'whammo' ] ); |
| 29 |
$this->assertTrue( $list->contains( 'whammo' ) ); |
| 30 |
|
| 31 |
$list->addArray( [ 0 ] ); |
| 32 |
$this->assertFalse( $list->contains( 'baz' ) ); |
| 33 |
} |
| 34 |
|
| 35 |
public function testCachedListInnerListIsOnlyCalledOnce() { |
| 36 |
|
| 37 |
$innerCache = new HashBagOStuff; |
| 38 |
$wanCache = new WANObjectCache( [ 'cache' => $innerCache ] ); |
| 39 |
|
| 40 |
$inner = [ 'bing', 'bang' ]; |
| 41 |
|
| 42 |
|
| 43 |
$list = $this->createMock( ArrayList::class ); |
| 44 |
$list->expects( $this->once() ) |
| 45 |
->method( 'getValues' ) |
| 46 |
->willReturn( $inner ); |
| 47 |
$list->method( 'getCacheKey' )->willReturn( '' ); |
| 48 |
|
| 49 |
$cached = new CachedList( $wanCache, 'test_key', $list ); |
| 50 |
|
| 51 |
|
| 52 |
$this->assertEquals( $inner, $cached->getValues() ); |
| 53 |
$this->assertEquals( $inner, $cached->getValues() ); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
$freshCached = new CachedList( $wanCache, 'test_key', $list ); |
| 58 |
$this->assertEquals( $inner, $freshCached->getValues() ); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public function testOnWikiList() { |
| 65 |
$this->editPage( 'User:Foo/Bar-baz', "abc\ndef\r\nghi\n\n\n" ); |
| 66 |
|
| 67 |
$list = new OnWikiList( NS_USER, "Foo/Bar-baz" ); |
| 68 |
$this->assertEquals( |
| 69 |
[ 'abc', 'def', 'ghi' ], |
| 70 |
$list->getValues() |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
public function testOnWikiListNonExistant() { |
| 75 |
$list = new OnWikiList( NS_USER, "Some_Non_Existant_Page" ); |
| 76 |
$this->assertEquals( [], $list->getValues() ); |
| 77 |
} |
| 78 |
} |