3 use MediaWiki\MainConfigNames
;
4 use MediaWiki\User\Options\StaticUserOptionsLookup
;
5 use MediaWiki\User\UserIdentityValue
;
6 use MediaWiki\Utils\MWTimestamp
;
9 * @covers \MediaWiki\Utils\MWTimestamp
11 class MWTimestampTest
extends MediaWikiLangTestCase
{
13 private function setMockUserOptions( array $options ) {
14 $defaults = $this->getServiceContainer()->getMainConfig()->get( MainConfigNames
::DefaultUserOptions
);
16 // $options are set as the options for "Pamela", the name used in the tests
17 $userOptionsLookup = new StaticUserOptionsLookup(
18 [ 'Pamela' => $options ],
22 $this->setService( 'UserOptionsLookup', $userOptionsLookup );
26 * @dataProvider provideRelativeTimestampTests
28 public function testRelativeTimestamp(
29 $tsTime, // The timestamp to format
30 $currentTime, // The time to consider "now"
31 $timeCorrection, // The time offset to use
32 $dateFormat, // The date preference to use
33 $expectedOutput, // The expected output
36 $this->setMockUserOptions( [
37 'timecorrection' => $timeCorrection,
41 $user = new UserIdentityValue( 13, 'Pamela' );
43 $tsTime = new MWTimestamp( $tsTime );
44 $currentTime = new MWTimestamp( $currentTime );
48 $tsTime->getRelativeTimestamp( $currentTime, $user ),
53 public static function provideRelativeTimestampTests() {
61 '"Yesterday" across years',
76 '6 minutes and 30 seconds ago',
77 'Combination of multiple units',
92 '2 decades, 1 year, 168 days, 2 hours, 8 minutes and 48 seconds ago',
101 '"Yesterday" across years with time correction',
109 'Recent weekday with time correction',
116 '9 hours and 17 minutes ago',
117 'Today at another time with time correction',