2020-06-17 19:08:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
2022-07-28 20:36:55 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-07-28 20:36:55 +00:00
|
|
|
|
2022-08-06 20:53:57 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class EmailNotificationTest extends MediaWikiIntegrationTestCase {
|
2020-06-17 19:08:11 +00:00
|
|
|
|
|
|
|
|
protected $emailNotification;
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->tablesUsed = [
|
|
|
|
|
'watchlist',
|
|
|
|
|
'watchlist_expiry',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->emailNotification = new EmailNotification();
|
|
|
|
|
|
2022-07-28 20:36:55 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::WatchlistExpiry, true );
|
2020-06-17 19:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers EmailNotification::notifyOnPageChange
|
|
|
|
|
*/
|
|
|
|
|
public function testNotifyOnPageChange(): void {
|
2022-01-12 20:13:39 +00:00
|
|
|
$store = $this->getServiceContainer()->getWatchedItemStore();
|
2020-06-17 19:08:11 +00:00
|
|
|
|
|
|
|
|
// both Alice and Bob watch 'Foobar'
|
2022-07-05 22:21:30 +00:00
|
|
|
$title = Title::makeTitle( NS_MAIN, 'Foobar' );
|
2020-06-17 19:08:11 +00:00
|
|
|
$alice = $this->getTestSysop()->getUser();
|
|
|
|
|
$store->addWatch( $alice, $title );
|
|
|
|
|
$bob = $this->getTestUser()->getUser();
|
|
|
|
|
$store->addWatch( $bob, $title );
|
|
|
|
|
|
|
|
|
|
// Alice edits the page (doesn't actually have to edit in this test).
|
|
|
|
|
// Bob (as in, not Alice) should have received an email notification.
|
|
|
|
|
$notifyArgs = [ $alice, $title, '20200624000000', '', false ];
|
|
|
|
|
$sent = $this->emailNotification->notifyOnPageChange( ...$notifyArgs );
|
|
|
|
|
static::assertTrue( $sent );
|
|
|
|
|
|
|
|
|
|
// Alice edits again, but Bob shouldn't be notified again
|
|
|
|
|
// (only one email until Bob visits the page again).
|
|
|
|
|
$sent = $this->emailNotification->notifyOnPageChange( ...$notifyArgs );
|
|
|
|
|
static::assertFalse( $sent );
|
|
|
|
|
|
|
|
|
|
// Reset notification timestamp, simulating that Bob visited the page.
|
|
|
|
|
$store->resetAllNotificationTimestampsForUser( $bob );
|
|
|
|
|
|
|
|
|
|
// Bob re-watches temporarily. For testing purposes we use a past expiry,
|
|
|
|
|
// so an email shouldn't be sent after Alice edits the page.
|
|
|
|
|
$store->addWatch( $bob, $title, '20060123000000' );
|
|
|
|
|
|
|
|
|
|
// Alice edits again, email should not be sent.
|
|
|
|
|
$sent = $this->emailNotification->notifyOnPageChange( ...$notifyArgs );
|
|
|
|
|
static::assertFalse( $sent );
|
|
|
|
|
}
|
|
|
|
|
}
|