mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
2c74f66f18
To test the HTML email: 1. install the latest version of php-mail and php-mail-mime package, they are required by the core sendmail function to send HTML email 2. set $wgAllowHTMLEmail = true before loading Echo in LocalSetting.php Change-Id: Ia4b98b14e135742b84f1b0e04589b0efdd24e954
89 lines
2.6 KiB
PHP
89 lines
2.6 KiB
PHP
<?php
|
|
|
|
class MWEchoNotifUserTest extends MediaWikiTestCase {
|
|
|
|
protected function setUp() {
|
|
parent::setUp();
|
|
$this->setMwGlobals( 'wgMemc', new HashBagOStuff() );
|
|
}
|
|
|
|
public function testNewFromUser() {
|
|
$exception = false;
|
|
try {
|
|
MWEchoNotifUser::newFromUser( User::newFromId( 0 ) );
|
|
} catch ( Exception $e ) {
|
|
$exception = true;
|
|
$this->assertEquals( "User must be logged in to view notification!",
|
|
$e->getMessage() );
|
|
}
|
|
$this->assertTrue( $exception, "Got exception" );
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( User::newFromId( 2 ) );
|
|
$this->assertInstanceOf( 'MWEchoNotifUser', $notifUser );
|
|
}
|
|
|
|
public function testFlagCacheWithNewTalkNotification() {
|
|
global $wgMemc;
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( User::newFromId( 2 ) );
|
|
|
|
$notifUser->flagCacheWithNewTalkNotification();
|
|
$this->assertEquals( '1', $wgMemc->get( $notifUser->getTalkNotificationCacheKey() ) );
|
|
}
|
|
|
|
public function testFlagCacheWithNoTalkNotification() {
|
|
global $wgMemc;
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( User::newFromId( 2 ) );
|
|
|
|
$notifUser->flagCacheWithNoTalkNotification();
|
|
$this->assertEquals( '0', $wgMemc->get( $notifUser->getTalkNotificationCacheKey() ) );
|
|
}
|
|
|
|
public function testNotifCountHasReachedMax() {
|
|
global $wgEchoMaxNotificationCount;
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( User::newFromId( 2 ) );
|
|
|
|
if ( $notifUser->getNotificationCount() > $wgEchoMaxNotificationCount ) {
|
|
$this->assertTrue( $notifUser->notifCountHasReachedMax() );
|
|
} else {
|
|
$this->assertFalse( $notifUser->notifCountHasReachedMax() );
|
|
}
|
|
}
|
|
|
|
public function testClearTalkNotification() {
|
|
global $wgMemc;
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( User::newFromId( 2 ) );
|
|
|
|
$notifUser->flagCacheWithNewTalkNotification();
|
|
|
|
$hasMax = $notifUser->notifCountHasReachedMax();
|
|
|
|
$notifUser->clearTalkNotification();
|
|
if ( $hasMax ) {
|
|
$this->assertEquals( '1', $wgMemc->get( $notifUser->getTalkNotificationCacheKey() ) );
|
|
} else {
|
|
$this->assertEquals( '0', $wgMemc->get( $notifUser->getTalkNotificationCacheKey() ) );
|
|
}
|
|
}
|
|
|
|
public function testGetEmailFormat() {
|
|
global $wgAllowHTMLEmail;
|
|
|
|
$format = $wgAllowHTMLEmail;
|
|
|
|
$user = User::newFromId( 2 );
|
|
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
|
|
|
$this->setMwGlobals( 'wgAllowHTMLEmail', true );
|
|
$this->assertEquals( $notifUser->getEmailFormat(), $user->getOption( 'echo-email-format' ) );
|
|
$this->setMwGlobals( 'wgAllowHTMLEmail', false );
|
|
$this->assertEquals( $notifUser->getEmailFormat(), EchoHooks::EMAIL_FORMAT_PLAIN_TEXT );
|
|
|
|
$this->setMwGlobals( 'wgAllowHTMLEmail', $format );
|
|
}
|
|
|
|
}
|