MediaWiki  REL1_20
TimestampTest.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class TimestampTest extends MediaWikiTestCase {
00011         function testValidParse( $format, $original, $expected ) {
00012                 $timestamp = new MWTimestamp( $original );
00013                 $this->assertEquals( $expected, $timestamp->getTimestamp( TS_MW ) );
00014         }
00015 
00020         function testValidOutput( $format, $expected, $original ) {
00021                 $timestamp = new MWTimestamp( $original );
00022                 $this->assertEquals( $expected, (string) $timestamp->getTimestamp( $format ) );
00023         }
00024 
00029         function testInvalidParse() {
00030                 $timestamp = new MWTimestamp( "This is not a timestamp." );
00031         }
00032 
00037         function testInvalidOutput() {
00038                 $timestamp = new MWTimestamp( '1343761268' );
00039                 $timestamp->getTimestamp( 98 );
00040         }
00041 
00045         function testHumanOutput() {
00046                 $timestamp = new MWTimestamp( time() - 3600 );
00047                 $this->assertEquals( "1 hour ago", $timestamp->getHumanTimestamp()->toString() );
00048         }
00049 
00054         function provideValidTimestamps() {
00055                 return array(
00056                         // Various formats
00057                         array( TS_UNIX, '1343761268', '20120731190108' ),
00058                         array( TS_MW, '20120731190108', '20120731190108' ),
00059                         array( TS_DB, '2012-07-31 19:01:08', '20120731190108' ),
00060                         array( TS_ISO_8601, '2012-07-31T19:01:08Z', '20120731190108' ),
00061                         array( TS_ISO_8601_BASIC, '20120731T190108Z', '20120731190108' ),
00062                         array( TS_EXIF, '2012:07:31 19:01:08', '20120731190108' ),
00063                         array( TS_RFC2822, 'Tue, 31 Jul 2012 19:01:08 GMT', '20120731190108' ),
00064                         array( TS_ORACLE, '31-07-2012 19:01:08.000000', '20120731190108' ),
00065                         array( TS_POSTGRES, '2012-07-31 19:01:08 GMT', '20120731190108' ),
00066                         array( TS_DB2, '2012-07-31 19:01:08', '20120731190108' ),
00067                         // Some extremes and weird values
00068                         array( TS_ISO_8601, '9999-12-31T23:59:59Z', '99991231235959' ),
00069                         array( TS_UNIX, '-62135596801', '00001231235959' )
00070                 );
00071         }
00072 }