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() {
|
|
|
|
// 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() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|