2020-04-20 19:40:07 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-13 06:43:40 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Test\Integration;
|
|
|
|
|
|
|
|
use MediaWiki\Extension\Notifications\ContainmentSet;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\User\Options\UserOptionsLookup;
|
|
|
|
use MediaWiki\User\User;
|
2022-11-13 06:43:40 +00:00
|
|
|
use MediaWikiIntegrationTestCase;
|
2021-12-01 18:29:00 +00:00
|
|
|
|
2020-04-20 19:40:07 +00:00
|
|
|
/**
|
2022-11-13 06:43:40 +00:00
|
|
|
* @coversDefaultClass \MediaWiki\Extension\Notifications\ContainmentSet
|
2020-04-20 19:40:07 +00:00
|
|
|
*/
|
2022-11-13 06:43:40 +00:00
|
|
|
class ContainmentSetTest 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
|
|
|
|
) {
|
2021-12-01 18:29:00 +00:00
|
|
|
$userOptionsLookupMock = $this->createMock( UserOptionsLookup::class );
|
|
|
|
$userOptionsLookupMock->method( 'getOption' )->willReturn( $prefData );
|
|
|
|
$this->setService( 'UserOptionsLookup', $userOptionsLookupMock );
|
2022-11-13 06:43:40 +00:00
|
|
|
$containmentSet = new ContainmentSet( $this->createMock( User::class ) );
|
2020-04-20 19:40:07 +00:00
|
|
|
$containmentSet->addTitleIDsFromUserOption( 'preference-name' );
|
|
|
|
$this->assertSame( $expected, $containmentSet->contains( $contains ) );
|
|
|
|
}
|
|
|
|
|
2023-05-20 18:35:53 +00:00
|
|
|
public static 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
|
|
|
|
]
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|