MediaWiki  REL1_19
TimeAdjustTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class TimeAdjustTest extends MediaWikiLangTestCase {
00004         static $offset;
00005 
00006         public function setUp() {
00007                 parent::setUp();
00008                 global $wgLocalTZoffset;
00009                 self::$offset = $wgLocalTZoffset;
00010 
00011                 $this->iniSet( 'precision', 15 );
00012         }
00013 
00014         public function tearDown() {
00015                 global $wgLocalTZoffset;
00016                 $wgLocalTZoffset = self::$offset;
00017                 parent::tearDown();
00018         }
00019 
00020         # Test offset usage for a given language::userAdjust
00021         function testUserAdjust() {
00022                 global $wgLocalTZoffset, $wgContLang;
00023 
00024                 $wgContLang = $en = Language::factory( 'en' );
00025 
00026                 #  Collection of parameters for Language_t_Offset.
00027                 # Format: date to be formatted, localTZoffset value, expected date
00028                 $userAdjust_tests = array(
00029                         array( 20061231235959,   0, 20061231235959 ),
00030                         array( 20061231235959,   5, 20070101000459 ),
00031                         array( 20061231235959,  15, 20070101001459 ),
00032                         array( 20061231235959,  60, 20070101005959 ),
00033                         array( 20061231235959,  90, 20070101012959 ),
00034                         array( 20061231235959, 120, 20070101015959 ),
00035                         array( 20061231235959, 540, 20070101085959 ),
00036                         array( 20061231235959,  -5, 20061231235459 ),
00037                         array( 20061231235959, -30, 20061231232959 ),
00038                         array( 20061231235959, -60, 20061231225959 ),
00039                 );
00040 
00041                 foreach ( $userAdjust_tests as $data ) {
00042                         $wgLocalTZoffset = $data[1];
00043 
00044                         $this->assertEquals(
00045                                 strval( $data[2] ),
00046                                 strval( $en->userAdjust( $data[0], '' ) ),
00047                                 "User adjust {$data[0]} by {$data[1]} minutes should give {$data[2]}"
00048                         );
00049                 }
00050         }
00051 }