Debian Codegraph @

tests/phpunit/includes/mail/EmailNotificationTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\MainConfigNames;
4 use MediaWiki\Title\Title;
5
6 /**
7 * @group Database
8 * @group Mail
9 * @covers \EmailNotification
10 */
11 class EmailNotificationTest extends MediaWikiIntegrationTestCase {
12
13 /** @var EmailNotification */
14 protected $emailNotification;
15
16 protected function setUp(): void {
17 parent::setUp();
18
19 $this->emailNotification = new EmailNotification();
20
21 $this->overrideConfigValue( MainConfigNames::WatchlistExpiry, true );
22 }
23
24 public function testNotifyOnPageChange(): void {
25 $store = $this->getServiceContainer()->getWatchedItemStore();
26
27 // both Alice and Bob watch 'Foobar'
28 $title = Title::makeTitle( NS_MAIN, 'Foobar' );
29 $alice = $this->getTestSysop()->getUser();
30 $store->addWatch( $alice, $title );
31 $bob = $this->getTestUser()->getUser();
32 $store->addWatch( $bob, $title );
33
34 // Alice edits the page (doesn't actually have to edit in this test).
35 // Bob (as in, not Alice) should have received an email notification.
36 $notifyArgs = [ $alice, $title, '20200624000000', '', false ];
37 $sent = $this->emailNotification->notifyOnPageChange( ...$notifyArgs );
38 static::assertTrue( $sent );
39
40 // Alice edits again, but Bob shouldn't be notified again
41 // (only one email until Bob visits the page again).
42 $sent = $this->emailNotification->notifyOnPageChange( ...$notifyArgs );
43 static::assertFalse( $sent );
44
45 // Reset notification timestamp, simulating that Bob visited the page.
46 $store->resetAllNotificationTimestampsForUser( $bob );
47
48 // Bob re-watches temporarily. For testing purposes we use a past expiry,
49 // so an email shouldn't be sent after Alice edits the page.
50 $store->addWatch( $bob, $title, '20060123000000' );
51
52 // Alice edits again, email should not be sent.
53 $sent = $this->emailNotification->notifyOnPageChange( ...$notifyArgs );
54 static::assertFalse( $sent );
55 }
56 }