mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-04 04:09:00 +00:00
17a644263a
composer: * mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0 The following sniffs are failing and were disabled: * PSR12.Functions.ReturnTypeDeclaration.SpaceBeforeReturnType npm: * svgo: 2.3.0 → 2.3.1 * https://npmjs.com/advisories/1754 (CVE-2021-33587) * postcss: 7.0.35 → 7.0.36 * https://npmjs.com/advisories/1693 (CVE-2021-23368) * trim-newlines: 3.0.0 → 3.0.1 * https://npmjs.com/advisories/1753 (CVE-2021-33623) Change-Id: Id866782d39ac02a329bd79539f2d52392fffd296
75 lines
1.7 KiB
PHP
75 lines
1.7 KiB
PHP
<?php
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
/**
|
|
* @coversDefaultClass EchoNotificationController
|
|
*/
|
|
class NotificationControllerUnitTest extends MediaWikiUnitTestCase {
|
|
|
|
/**
|
|
* @dataProvider PageLinkedTitleMutedByUserDataProvider
|
|
* @covers ::isPageLinkedTitleMutedByUser
|
|
* @param Title $title
|
|
* @param User $user
|
|
* @param bool $expected
|
|
*/
|
|
public function testIsPageLinkedTitleMutedByUser(
|
|
Title $title, User $user, bool $expected ): void {
|
|
$wrapper = TestingAccessWrapper::newFromClass( EchoNotificationController::class );
|
|
$wrapper->mutedPageLinkedTitlesCache = $this->getMapCacheLruMock();
|
|
$this->assertSame(
|
|
$expected,
|
|
$wrapper->isPageLinkedTitleMutedByUser( $title, $user )
|
|
);
|
|
}
|
|
|
|
public function PageLinkedTitleMutedByUserDataProvider(): array {
|
|
return [
|
|
[
|
|
$this->getMockTitle( 123 ),
|
|
$this->getMockUser( [] ),
|
|
false
|
|
],
|
|
[
|
|
$this->getMockTitle( 123 ),
|
|
$this->getMockUser( [ 123, 456, 789 ] ),
|
|
true
|
|
],
|
|
[
|
|
$this->getMockTitle( 456 ),
|
|
$this->getMockUser( [ 489 ] ),
|
|
false
|
|
]
|
|
|
|
];
|
|
}
|
|
|
|
private function getMockTitle( int $articleID ) {
|
|
$title = $this->getMockBuilder( Title::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$title->method( 'getArticleID' )
|
|
->willReturn( $articleID );
|
|
return $title;
|
|
}
|
|
|
|
private function getMockUser( $mutedTitlePreferences = [] ) {
|
|
$user = $this->getMockBuilder( User::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$user->method( 'getId' )
|
|
->willReturn( 456 );
|
|
$user->method( 'getOption' )
|
|
->willReturn( implode( "\n", $mutedTitlePreferences ) );
|
|
return $user;
|
|
}
|
|
|
|
private function getMapCacheLruMock() {
|
|
return $this->getMockBuilder( MapCacheLRU::class )
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
}
|
|
|
|
}
|