More documentation!
[lhc/web/wiklou.git] / tests / phpunit / includes / TimeAdjustTest.php
1 <?php
2
3 class TimeAdjustTest extends MediaWikiLangTestCase {
4 static $offset;
5
6 public function setUp() {
7 parent::setUp();
8 global $wgLocalTZoffset;
9 self::$offset = $wgLocalTZoffset;
10
11 $this->iniSet( 'precision', 15 );
12 }
13
14 public function tearDown() {
15 global $wgLocalTZoffset;
16 $wgLocalTZoffset = self::$offset;
17 parent::tearDown();
18 }
19
20 # Test offset usage for a given language::userAdjust
21 function testUserAdjust() {
22 global $wgLocalTZoffset, $wgContLang;
23
24 $wgContLang = $en = Language::factory( 'en' );
25
26 #  Collection of parameters for Language_t_Offset.
27 # Format: date to be formatted, localTZoffset value, expected date
28 $userAdjust_tests = array(
29 array( 20061231235959, 0, 20061231235959 ),
30 array( 20061231235959, 5, 20070101000459 ),
31 array( 20061231235959, 15, 20070101001459 ),
32 array( 20061231235959, 60, 20070101005959 ),
33 array( 20061231235959, 90, 20070101012959 ),
34 array( 20061231235959, 120, 20070101015959 ),
35 array( 20061231235959, 540, 20070101085959 ),
36 array( 20061231235959, -5, 20061231235459 ),
37 array( 20061231235959, -30, 20061231232959 ),
38 array( 20061231235959, -60, 20061231225959 ),
39 );
40
41 foreach ( $userAdjust_tests as $data ) {
42 $wgLocalTZoffset = $data[1];
43
44 $this->assertEquals(
45 strval( $data[2] ),
46 strval( $en->userAdjust( $data[0], '' ) ),
47 "User adjust {$data[0]} by {$data[1]} minutes should give {$data[2]}"
48 );
49 }
50 }
51 }