mediawiki-extensions-Echo/tests/phpunit/unit/EchoContainmentSetTest.php
Kosta Harlan 1560528dc7 Add page linked event title muted list
* Add a section on the preference form to allow users to mute articles
  from generating "page linked" notices
* The preference will save the article title as an article ID

Depends-On: Ia0ddf78646ec4c8ae0b84b6d5b46ef5e51c8e8c1
Bug: T46787
Change-Id: I67f751eae5fdc5bccff7fe3047227d432c1cb8d5
2020-05-06 12:38:55 +02:00

60 lines
1.1 KiB
PHP

<?php
/**
* @coversDefaultClass EchoContainmentSet
*/
class EchoContainmentSetTest extends \MediaWikiUnitTestCase {
/**
* @covers ::addTitleIDsFromUserOption
* @dataProvider addTitlesFromUserOptionProvider
* @param User $user
* @param string $prefData
* @param string $contains
* @param bool $expected
*/
public function testAddTitlesFromUserOption(
$prefData, string $contains, bool $expected
) {
$user = $this->getDefaultUserMock();
$user->method( 'getOption' )
->willReturn( $prefData );
$containmentSet = new EchoContainmentSet( $user );
$containmentSet->addTitleIDsFromUserOption( 'preference-name' );
$this->assertSame( $expected, $containmentSet->contains( $contains ) );
}
public function addTitlesFromUserOptionProvider() :array {
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();
}
}