31304f35c52b1ffdcf44da4077cbd33e10ebc236
[lhc/web/wiklou.git] / tests / phpunit / includes / TimeAdjustTest.php
1 <?php
2
3 class TimeAdjustTest extends MediaWikiLangTestCase {
4 static $offset, $timezone;
5
6 public function setUp() {
7 parent::setUp();
8 global $wgLocalTZoffset, $wgLocaltimezone;
9 self::$offset = $wgLocalTZoffset;
10 self::$timezone = $wgLocaltimezone;
11
12 $this->iniSet( 'precision', 15 );
13 }
14
15 public function tearDown() {
16 global $wgLocalTZoffset, $wgLocaltimezone;
17 $wgLocalTZoffset = self::$offset;
18 $wgLocaltimezone = self::$timezone;
19 parent::tearDown();
20 }
21
22 /**
23 * Test offset usage for a given language::userAdjust
24 * @dataProvider dataUserAdjustWithOffset
25 */
26 function testUserAdjustWithOffset( $inputDate, $offset, $expectedDate ) {
27 global $wgLocalTZoffset, $wgLocaltimezone, $wgContLang;
28
29 $wgContLang = $en = Language::factory( 'en' );
30
31 $wgLocaltimezone = 'DummyTimezoneSoUserAdjustWillUseTzOffset';
32 $wgLocalTZoffset = $offset;
33
34 $this->assertEquals(
35 strval( $expectedDate ),
36 strval( $en->userAdjust( $inputDate, '' ) ),
37 "User adjust {$inputDate} by {$offset} minutes should give {$expectedDate}"
38 );
39 }
40
41 function dataUserAdjustWithOffset() {
42 #  Collection of parameters for Language_t_Offset.
43 # Format: date to be formatted, localTZoffset value, expected date
44 return array(
45 array( 20061231235959, 0, 20061231235959 ),
46 array( 20061231235959, 5, 20070101000459 ),
47 array( 20061231235959, 15, 20070101001459 ),
48 array( 20061231235959, 60, 20070101005959 ),
49 array( 20061231235959, 90, 20070101012959 ),
50 array( 20061231235959, 120, 20070101015959 ),
51 array( 20061231235959, 540, 20070101085959 ),
52 array( 20061231235959, -5, 20061231235459 ),
53 array( 20061231235959, -30, 20061231232959 ),
54 array( 20061231235959, -60, 20061231225959 ),
55 );
56 }
57
58 /**
59 * Test timezone usage for a given language::userAdjust
60 * @dataProvider dataUserAdjustWithTimezone
61 */
62 function testUserAdjustWithTimezone( $inputDate, $timezone, $expectedDate ) {
63 global $wgLocalTZoffset, $wgLocaltimezone;
64
65 $wgContLang = $en = Language::factory( 'en' );
66
67 $wgLocaltimezone = $timezone;
68 $wgLocalTZoffset = 0;
69
70 $this->assertEquals(
71 strval( $expectedDate ),
72 strval( $en->userAdjust( $inputDate, '' ) ),
73 "User adjust {$inputDate} with timezone {$timezone} should give {$expectedDate}"
74 );
75 }
76
77 function dataUserAdjustWithTimezone() {
78 return array(
79 array( 20111028233711, 'Europe/Warsaw', 20111029013711 ),
80 array( 20111108205929, 'Europe/Warsaw', 20111108215929 ),
81 );
82 }
83
84 }