From c1f348da1e6b1d60ef9d567af1cb52db2a10211f Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 16 May 2017 18:36:58 -0700 Subject: [PATCH] Various test fixes for postgres * Add another TS_MW timestamp coercion to WatchedItemStore. * Do not expect timestamp conversion for pager mOffset. They have been used in Pager URLs for ages. * Do not assume the user_id for UTSysop is 1; use the row value. Bug: T75174 Change-Id: I590a4b7363ccff26d9ac9f51b95fc1aa072503b2 --- includes/WatchedItemStore.php | 3 +- .../logging/NewUsersLogFormatterTest.php | 28 ++++++++----------- .../pager/RangeChronologicalPagerTest.php | 5 +++- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php index 228f93b9b4..06f93c6b99 100644 --- a/includes/WatchedItemStore.php +++ b/includes/WatchedItemStore.php @@ -581,7 +581,8 @@ class WatchedItemStore implements StatsdAwareInterface { ); foreach ( $res as $row ) { - $timestamps[$row->wl_namespace][$row->wl_title] = $row->wl_notificationtimestamp; + $timestamps[$row->wl_namespace][$row->wl_title] = + wfTimestampOrNull( TS_MW, $row->wl_notificationtimestamp ); } return $timestamps; diff --git a/tests/phpunit/includes/logging/NewUsersLogFormatterTest.php b/tests/phpunit/includes/logging/NewUsersLogFormatterTest.php index c4b52f0d98..333fd88da6 100644 --- a/tests/phpunit/includes/logging/NewUsersLogFormatterTest.php +++ b/tests/phpunit/includes/logging/NewUsersLogFormatterTest.php @@ -107,16 +107,10 @@ class NewUsersLogFormatterTest extends LogFormatterTestCase { 'user' => 0, 'user_text' => 'User', 'namespace' => NS_USER, - 'title' => 'UTSysop', - 'params' => [ - '4::userid' => 1, - ], + 'title' => 'UTSysop' ], [ - 'text' => 'User account UTSysop was created by User', - 'api' => [ - 'userid' => 1, - ], + 'text' => 'User account UTSysop was created by User' ], ], ]; @@ -126,6 +120,10 @@ class NewUsersLogFormatterTest extends LogFormatterTestCase { * @dataProvider provideCreate2LogDatabaseRows */ public function testCreate2LogDatabaseRows( $row, $extra ) { + // Make UTSysop user and use its user_id (sequence does not reset to 1 for postgres) + $user = static::getTestSysop()->getUser(); + $row['params']['4::userid'] = $user->getId(); + $extra['api']['userid'] = $user->getId(); $this->doTestLogFormatter( $row, $extra ); } @@ -145,16 +143,10 @@ class NewUsersLogFormatterTest extends LogFormatterTestCase { 'user' => 0, 'user_text' => 'Sysop', 'namespace' => NS_USER, - 'title' => 'UTSysop', - 'params' => [ - '4::userid' => 1, - ], + 'title' => 'UTSysop' ], [ - 'text' => 'User account UTSysop was created by Sysop and password was sent by email', - 'api' => [ - 'userid' => 1, - ], + 'text' => 'User account UTSysop was created by Sysop and password was sent by email' ], ], ]; @@ -164,6 +156,10 @@ class NewUsersLogFormatterTest extends LogFormatterTestCase { * @dataProvider provideByemailLogDatabaseRows */ public function testByemailLogDatabaseRows( $row, $extra ) { + // Make UTSysop user and use its user_id (sequence does not reset to 1 for postgres) + $user = static::getTestSysop()->getUser(); + $row['params']['4::userid'] = $user->getId(); + $extra['api']['userid'] = $user->getId(); $this->doTestLogFormatter( $row, $extra ); } diff --git a/tests/phpunit/includes/pager/RangeChronologicalPagerTest.php b/tests/phpunit/includes/pager/RangeChronologicalPagerTest.php index 3374f4ab93..4721ce6fd8 100644 --- a/tests/phpunit/includes/pager/RangeChronologicalPagerTest.php +++ b/tests/phpunit/includes/pager/RangeChronologicalPagerTest.php @@ -15,7 +15,10 @@ class RangeChronologicalPagerTest extends MediaWikiLangTestCase { */ public function testGetDateCond( $inputYear, $inputMonth, $inputDay, $expected ) { $pager = $this->getMockForAbstractClass( 'RangeChronologicalPager' ); - $this->assertEquals( $expected, $pager->getDateCond( $inputYear, $inputMonth, $inputDay ) ); + $this->assertEquals( + $expected, + wfTimestamp( TS_MW, $pager->getDateCond( $inputYear, $inputMonth, $inputDay ) ) + ); } /** -- 2.20.1