Merge "Don't send page-linked notifications for pages created by bot users"

This commit is contained in:
jenkins-bot 2023-04-28 19:27:57 +00:00 committed by Gerrit Code Review
commit 84966452f8
2 changed files with 35 additions and 0 deletions

View file

@ -131,6 +131,10 @@ class EchoUserLocator {
$user = User::newFromId( $res->rev_user );
if ( $user ) {
// T318523: Don't send page-linked notifications for pages created by bot users.
if ( $event->getType() === 'page-linked' && $user->isBot() ) {
return [];
}
return [ $user->getId() => $user ];
}

View file

@ -130,6 +130,37 @@ class UserLocatorTest extends MediaWikiIntegrationTestCase {
$this->assertEquals( $expect, array_keys( $users ), $message );
}
public function testDontSendPageLinkedNotificationsForPagesCreatedByBotUsers() {
$botUser = $this->getTestUser( [ 'bot' ] )->getUser();
$botUser->addToDatabase();
$this->editPage( 'TestBotCreatedPage', 'Test', '', NS_MAIN, $botUser );
$this->editPage( 'SomeOtherPage', '[[TestBotCreatedPage]]' );
$event = $this->createMock( Event::class );
$event->method( 'getTitle' )
->willReturn( Title::newFromText( 'TestBotCreatedPage' ) );
$event->method( 'getAgent' )
->willReturn( User::newFromId( 123 ) );
$event->method( 'getType' )
->willReturn( 'page-linked' );
$this->assertEquals( [], EchoUserLocator::locateArticleCreator( $event ) );
$normalUser = $this->getTestUser()->getUser();
$normalUser->addToDatabase();
$this->editPage( 'NormalCreatedPage', 'Test', '', NS_MAIN, $normalUser );
$this->editPage( 'AnotherPage', '[[NormalCreatedPage]]' );
$event = $this->createMock( Event::class );
$event->method( 'getTitle' )
->willReturn( Title::newFromText( 'NormalCreatedPage' ) );
$event->method( 'getAgent' )
->willReturn( User::newFromId( 456 ) );
$event->method( 'getType' )
->willReturn( 'page-linked' );
$this->assertEquals(
$normalUser->getUser()->getId(),
array_key_first( EchoUserLocator::locateArticleCreator( $event ) )
);
}
public static function locateEventAgentProvider() {
return [
[