2020-04-20 19:40:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @coversDefaultClass EchoNotificationController
|
|
|
|
*/
|
|
|
|
class NotificationControllerUnitTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider PageLinkedTitleMutedByUserDataProvider
|
|
|
|
* @covers ::isPageLinkedTitleMutedByUser
|
2020-04-28 03:39:40 +00:00
|
|
|
* @param Title $title
|
2020-04-20 19:40:07 +00:00
|
|
|
* @param User $user
|
|
|
|
* @param bool $expected
|
|
|
|
*/
|
|
|
|
public function testIsPageLinkedTitleMutedByUser(
|
2020-04-28 03:39:40 +00:00
|
|
|
Title $title, User $user, bool $expected ): void {
|
2020-04-20 19:40:07 +00:00
|
|
|
$wrapper = TestingAccessWrapper::newFromClass( EchoNotificationController::class );
|
|
|
|
$wrapper->mutedPageLinkedTitlesCache = $this->getMapCacheLruMock();
|
|
|
|
$this->assertSame(
|
|
|
|
$expected,
|
2020-04-28 03:39:40 +00:00
|
|
|
$wrapper->isPageLinkedTitleMutedByUser( $title, $user )
|
2020-04-20 19:40:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function PageLinkedTitleMutedByUserDataProvider() :array {
|
|
|
|
return [
|
|
|
|
[
|
2020-04-28 03:39:40 +00:00
|
|
|
$this->getMockTitle( 123 ),
|
2020-04-20 19:40:07 +00:00
|
|
|
$this->getMockUser( [] ),
|
|
|
|
false
|
|
|
|
],
|
|
|
|
[
|
2020-04-28 03:39:40 +00:00
|
|
|
$this->getMockTitle( 123 ),
|
2020-04-20 19:40:07 +00:00
|
|
|
$this->getMockUser( [ 123, 456, 789 ] ),
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
2020-04-28 03:39:40 +00:00
|
|
|
$this->getMockTitle( 456 ),
|
2020-04-20 19:40:07 +00:00
|
|
|
$this->getMockUser( [ 489 ] ),
|
|
|
|
false
|
|
|
|
]
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-04-28 03:39:40 +00:00
|
|
|
private function getMockTitle( int $articleID ) {
|
2020-04-20 19:40:07 +00:00
|
|
|
$title = $this->getMockBuilder( Title::class )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$title->method( 'getArticleID' )
|
|
|
|
->willReturn( $articleID );
|
2020-04-28 03:39:40 +00:00
|
|
|
return $title;
|
2020-04-20 19:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|