This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
||
|
||
class TimeAdjustTest extends MediaWikiLangTestCase {
|
||
protected function setUp() {
|
||
parent::setUp();
|
||
|
||
$this->setMwGlobals( array(
|
||
'wgLocalTZoffset' => null,
|
||
'wgContLang' => Language::factory( 'en' ),
|
||
) );
|
||
|
||
$this->iniSet( 'precision', 15 );
|
||
}
|
||
|
||
# Test offset usage for a given language::userAdjust
|
||
function testUserAdjust() {
|
||
global $wgLocalTZoffset, $wgContLang;
|
||
|
||
# Collection of parameters for Language_t_Offset.
|
||
# Format: date to be formatted, localTZoffset value, expected date
|
||
$userAdjust_tests = array(
|
||
array( 20061231235959, 0, 20061231235959 ),
|
||
array( 20061231235959, 5, 20070101000459 ),
|
||
array( 20061231235959, 15, 20070101001459 ),
|
||
array( 20061231235959, 60, 20070101005959 ),
|
||
array( 20061231235959, 90, 20070101012959 ),
|
||
array( 20061231235959, 120, 20070101015959 ),
|
||
array( 20061231235959, 540, 20070101085959 ),
|
||
array( 20061231235959, -5, 20061231235459 ),
|
||
array( 20061231235959, -30, 20061231232959 ),
|
||
array( 20061231235959, -60, 20061231225959 ),
|
||
);
|
||
|
||
foreach ( $userAdjust_tests as $data ) {
|
||
$wgLocalTZoffset = $data[1];
|
||
|
||
$this->assertEquals(
|
||
strval( $data[2] ),
|
||
strval( $wgContLang->userAdjust( $data[0], '' ) ),
|
||
"User adjust {$data[0]} by {$data[1]} minutes should give {$data[2]}"
|
||
);
|
||
}
|
||
}
|
||
}
|