2013-05-06 22:34:50 +00:00
|
|
|
<?php
|
|
|
|
|
2014-07-25 20:19:15 +00:00
|
|
|
/**
|
|
|
|
* @group Echo
|
|
|
|
*/
|
2013-05-06 22:34:50 +00:00
|
|
|
class ContainmentSetTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
public function testGenericContains() {
|
2014-05-27 18:28:37 +00:00
|
|
|
$list = new EchoContainmentSet();
|
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' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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
|
2015-10-01 13:48:52 +00:00
|
|
|
$list = $this->getMockBuilder( 'EchoArrayList' )
|
2013-05-06 22:34:50 +00:00
|
|
|
->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(
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|