2013-05-06 22:34:50 +00:00
|
|
|
<?php
|
|
|
|
|
2014-07-25 20:19:15 +00:00
|
|
|
/**
|
2018-01-24 00:31:53 +00:00
|
|
|
* @covers EchoContainmentSet
|
2014-07-25 20:19:15 +00:00
|
|
|
* @group Echo
|
2018-09-14 19:26:45 +00:00
|
|
|
* @group Database
|
2014-07-25 20:19:15 +00:00
|
|
|
*/
|
2013-05-06 22:34:50 +00:00
|
|
|
class ContainmentSetTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
public function testGenericContains() {
|
2016-11-10 04:37:10 +00:00
|
|
|
$list = new EchoContainmentSet( self::getTestUser()->getUser() );
|
2013-05-06 22:34:50 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$list->addArray( [ 'foo', 'bar' ] );
|
2013-05-06 22:34:50 +00:00
|
|
|
$this->assertTrue( $list->contains( 'foo' ) );
|
|
|
|
$this->assertTrue( $list->contains( 'bar' ) );
|
|
|
|
$this->assertFalse( $list->contains( 'whammo' ) );
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$list->addArray( [ 'whammo' ] );
|
2013-05-06 22:34:50 +00:00
|
|
|
$this->assertTrue( $list->contains( 'whammo' ) );
|
2017-10-14 23:24:18 +00:00
|
|
|
|
|
|
|
$list->addArray( [ 0 ] );
|
|
|
|
$this->assertFalse( $list->contains( 'baz' ) );
|
2013-05-06 22:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCachedListInnerListIsOnlyCalledOnce() {
|
2019-02-28 21:17:15 +00:00
|
|
|
$innerCache = new HashBagOStuff; // simulate caching
|
|
|
|
$wanCache = new WANObjectCache( [ 'cache' => $innerCache ] );
|
2013-05-06 22:34:50 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$inner = [ 'bing', 'bang' ];
|
2013-05-06 22:34:50 +00:00
|
|
|
// 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
|
2019-02-19 10:35:54 +00:00
|
|
|
$list = $this->getMockBuilder( EchoArrayList::class )
|
2013-05-06 22:34:50 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$list->expects( $this->once() )
|
|
|
|
->method( 'getValues' )
|
|
|
|
->will( $this->returnValue( $inner ) );
|
|
|
|
|
2019-02-28 21:17:15 +00:00
|
|
|
$cached = new EchoCachedList( $wanCache, 'test_key', $list );
|
2013-05-06 22:34:50 +00:00
|
|
|
|
|
|
|
// 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
|
2019-02-28 21:17:15 +00:00
|
|
|
$freshCached = new EchoCachedList( $wanCache, 'test_key', $list );
|
2013-05-06 22:34:50 +00:00
|
|
|
$this->assertEquals( $inner, $freshCached->getValues() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-09 18:41:51 +00:00
|
|
|
* @group Database
|
2013-05-06 22:34:50 +00:00
|
|
|
*/
|
|
|
|
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(
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'abc', 'def', 'ghi' ],
|
2013-05-06 22:34:50 +00:00
|
|
|
$list->getValues()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOnWikiListNonExistant() {
|
|
|
|
$list = new EchoOnWikiList( NS_USER, "Some_Non_Existant_Page" );
|
2016-12-05 18:51:07 +00:00
|
|
|
$this->assertEquals( [], $list->getValues() );
|
2013-05-06 22:34:50 +00:00
|
|
|
}
|
|
|
|
}
|