mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-11 23:46:53 +00:00
c36d2bd0e8
The codebase already used the …::class feature in many places. So this is more for consistency than anything. The …::class feature makes it much easier to do refactoring in the future. Note this patch is exclusively touching tests. That should make it relatively easy to review this. As long as the CI is fine with it, it should be ok. Right? ;-) Change-Id: I4d2adee76b4adbc83b2061161fd4e863ba833fcb
78 lines
2.4 KiB
PHP
78 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @covers EchoContainmentSet
|
|
* @group Echo
|
|
* @group Database
|
|
*/
|
|
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' ) );
|
|
|
|
$list->addArray( [ 0 ] );
|
|
$this->assertFalse( $list->contains( 'baz' ) );
|
|
}
|
|
|
|
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::class )
|
|
->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() );
|
|
}
|
|
|
|
/**
|
|
* @group 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 );
|
|
}
|
|
}
|