| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MainConfigNames; |
| 4 |
use MediaWiki\Title\Title; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class EmailNotificationTest extends MediaWikiIntegrationTestCase { |
| 12 |
|
| 13 |
|
| 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 |
|
| 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 |
|
| 35 |
|
| 36 |
$notifyArgs = [ $alice, $title, '20200624000000', '', false ]; |
| 37 |
$sent = $this->emailNotification->notifyOnPageChange( ...$notifyArgs ); |
| 38 |
static::assertTrue( $sent ); |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
$sent = $this->emailNotification->notifyOnPageChange( ...$notifyArgs ); |
| 43 |
static::assertFalse( $sent ); |
| 44 |
|
| 45 |
|
| 46 |
$store->resetAllNotificationTimestampsForUser( $bob ); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
$store->addWatch( $bob, $title, '20060123000000' ); |
| 51 |
|
| 52 |
|
| 53 |
$sent = $this->emailNotification->notifyOnPageChange( ...$notifyArgs ); |
| 54 |
static::assertFalse( $sent ); |
| 55 |
} |
| 56 |
} |