2020-04-20 19:40:07 +00:00
|
|
|
<?php
|
|
|
|
|
2021-12-01 18:29:00 +00:00
|
|
|
use MediaWiki\User\UserOptionsLookup;
|
|
|
|
|
2020-04-20 19:40:07 +00:00
|
|
|
/**
|
|
|
|
* @coversDefaultClass EchoContainmentSet
|
|
|
|
*/
|
2021-12-01 18:29:00 +00:00
|
|
|
class EchoContainmentSetTest extends MediaWikiIntegrationTestCase {
|
2020-04-20 19:40:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::addTitleIDsFromUserOption
|
|
|
|
* @dataProvider addTitlesFromUserOptionProvider
|
|
|
|
* @param string $prefData
|
|
|
|
* @param string $contains
|
|
|
|
* @param bool $expected
|
|
|
|
*/
|
|
|
|
public function testAddTitlesFromUserOption(
|
|
|
|
$prefData, string $contains, bool $expected
|
|
|
|
) {
|
|
|
|
$user = $this->getDefaultUserMock();
|
2021-12-01 18:29:00 +00:00
|
|
|
$userOptionsLookupMock = $this->createMock( UserOptionsLookup::class );
|
|
|
|
$userOptionsLookupMock->method( 'getOption' )->willReturn( $prefData );
|
|
|
|
$this->setService( 'UserOptionsLookup', $userOptionsLookupMock );
|
2020-04-20 19:40:07 +00:00
|
|
|
$containmentSet = new EchoContainmentSet( $user );
|
|
|
|
$containmentSet->addTitleIDsFromUserOption( 'preference-name' );
|
|
|
|
$this->assertSame( $expected, $containmentSet->contains( $contains ) );
|
|
|
|
}
|
|
|
|
|
2021-07-23 21:23:16 +00:00
|
|
|
public function addTitlesFromUserOptionProvider(): array {
|
2020-04-20 19:40:07 +00:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
'foo',
|
|
|
|
'bar',
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[ 'foo', 'bar' ],
|
|
|
|
'foo',
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"foo\nbar",
|
|
|
|
'bar',
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'{"foo":"bar"}',
|
|
|
|
'bar',
|
|
|
|
false
|
|
|
|
]
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getDefaultUserMock() {
|
|
|
|
return $this->getMockBuilder( User::class )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|