| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Test\Integration; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Notifications\ContainmentSet; |
| 6 |
use MediaWiki\User\Options\UserOptionsLookup; |
| 7 |
use MediaWiki\User\User; |
| 8 |
use MediaWikiIntegrationTestCase; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class ContainmentSetTest extends MediaWikiIntegrationTestCase { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public function testAddTitlesFromUserOption( |
| 23 |
$prefData, string $contains, bool $expected |
| 24 |
) { |
| 25 |
$userOptionsLookupMock = $this->createMock( UserOptionsLookup::class ); |
| 26 |
$userOptionsLookupMock->method( 'getOption' )->willReturn( $prefData ); |
| 27 |
$this->setService( 'UserOptionsLookup', $userOptionsLookupMock ); |
| 28 |
$containmentSet = new ContainmentSet( $this->createMock( User::class ) ); |
| 29 |
$containmentSet->addTitleIDsFromUserOption( 'preference-name' ); |
| 30 |
$this->assertSame( $expected, $containmentSet->contains( $contains ) ); |
| 31 |
} |
| 32 |
|
| 33 |
public static function addTitlesFromUserOptionProvider(): array { |
| 34 |
return [ |
| 35 |
[ |
| 36 |
'foo', |
| 37 |
'bar', |
| 38 |
false |
| 39 |
], |
| 40 |
[ |
| 41 |
[ 'foo', 'bar' ], |
| 42 |
'foo', |
| 43 |
false |
| 44 |
], |
| 45 |
[ |
| 46 |
"foo\nbar", |
| 47 |
'bar', |
| 48 |
true |
| 49 |
], |
| 50 |
[ |
| 51 |
'{"foo":"bar"}', |
| 52 |
'bar', |
| 53 |
false |
| 54 |
] |
| 55 |
|
| 56 |
]; |
| 57 |
} |
| 58 |
|
| 59 |
} |