jenkins-bot has submitted this change and it was merged.
Change subject: Unbreak the unit tests
......................................................................
Unbreak the unit tests
Not all installations will have a user with the id of 2,
like jenkins. At some point User::getOption is called, which
requires loading the user from the database, except it
doesn't exist. At which point the user id is reset to 0,
so it becomes an anonymous user, breaking the test.
Since the MediaWiki test runner automatically
creates a test user, we can safely assume that there is
a user with the id 1.
The other failure was due to that $wgUser may not
always be 127.0.0.1. The test now directly just
calls $wgUser to avoid issues if another test has
altered the global state.
Change-Id: Iacf904d04f1ff5aaf584cb98c3083ef6d7d89cea
---
M tests/EmailFormatterTest.php
M tests/NotificationFormatterTest.php
2 files changed, 20 insertions(+), 8 deletions(-)
Approvals:
Hashar: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/EmailFormatterTest.php b/tests/EmailFormatterTest.php
index a8609d5..ef69e5b 100644
--- a/tests/EmailFormatterTest.php
+++ b/tests/EmailFormatterTest.php
@@ -19,10 +19,10 @@
$formatter = EchoNotificationFormatter::factory(
$wgEchoNotifications[$event->getType()] );
$formatter->setOutputFormat( 'email' );
- $user = User::newFromId( 2 );
+ $user = User::newFromId( 1 );
$user->setName( 'Test' );
$user->setOption( 'echo-email-format',
EchoHooks::EMAIL_FORMAT_HTML );
-
+
$this->emailSingle = new EchoEmailSingle( $formatter, $event,
$user );
$content[$event->getCategory()][] =
EchoNotificationController::formatNotification( $event, $user, 'email',
'emaildigest' );
diff --git a/tests/NotificationFormatterTest.php
b/tests/NotificationFormatterTest.php
index 43eb84b..7c8b457 100644
--- a/tests/NotificationFormatterTest.php
+++ b/tests/NotificationFormatterTest.php
@@ -2,6 +2,14 @@
class EchoNotificationFormatterTest extends MediaWikiTestCase {
+ public function setUp() {
+ parent::setUp();
+ $user = new User();
+ $user->setName( 'Notification-formatter-test' );
+ $user->addToDatabase();
+ $this->setMwGlobals( 'wgUser', $user );
+ }
+
public static function provider_editUserTalkEmail() {
return array(
array( '/Main_Page[^#]/', null ),
@@ -31,7 +39,7 @@
public static function provider_editUserTalk() {
return array(
// if there is a section-title, the message should be
'[[User:user_name|user_name]] left a message on
- // your talk page in '[[User
talk:user_name#section_title|section_title]]'
+ // your talk page in '[[User
talk:user_name#section_title|section_title]]'
array( '/[[User
talk:[^#]+#moar_cowbell|moar_cowbell]]/', 'moar_cowbell', 'text' ),
array( '/#moar_cowbell/', 'moar_cowbell', 'html' ),
array( '/#moar_cowbell/', 'moar_cowbell', 'flyout' ),
@@ -43,12 +51,12 @@
*/
public function testEditUserTalkFlyoutSectionLinkFragment( $pattern,
$sectionTitle, $format ) {
// Required hack so parser doesnt turn the links into redlinks
which contain no fragment
- LinkCache::singleton()->addGoodLinkObj( 42, Title::newFromText(
'127.0.0.1', NS_USER_TALK ) );
+ global $wgUser;
+ LinkCache::singleton()->addGoodLinkObj( 42,
$wgUser->getTalkPage() );
$event = $this->mockEvent( 'edit-user-talk', array(
'section-title' => $sectionTitle,
) );
-
$this->assertRegExp( $pattern, $this->format( $event, $format )
);
}
@@ -121,7 +129,7 @@
$this->assertContains( $text, $this->format( $event,
'html' ) );
}
}
-
+
public static function provider_revisionAgent() {
$userText = '10.2.3.4';
$suppressed = wfMessage( 'rev-deleted-user' )->text();
@@ -198,15 +206,19 @@
$this->assertContains( $expect, $this->format( $event, 'html' )
);
}
- protected function format( EchoEvent $event, $format, $type = 'web',
array $params = array() ) {
+ protected function format( EchoEvent $event, $format, $user = false,
$type = 'web', array $params = array() ) {
global $wgEchoNotifications;
$params += $wgEchoNotifications[ $event->getType() ];
$formatter = EchoNotificationFormatter::factory( $params );
$formatter->setOutputFormat( $format );
+ if ( $user === false ) {
+ $user =
User::newFromName('Notification-formatter-test');
+ }
+
// Notification users can not be anonymous, use a fake user id
- return $formatter->format( $event, User::newFromId( 2 ), $type
);
+ return $formatter->format( $event, $user, $type );
}
protected function mockEvent( $type, array $extra = array(), Revision
$rev = null ) {
--
To view, visit https://gerrit.wikimedia.org/r/92270
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iacf904d04f1ff5aaf584cb98c3083ef6d7d89cea
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Bartosz DziewoĆski <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits