| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Pager\ReverseChronologicalPager; |
| 4 |
use MediaWiki\Utils\MWTimestamp; |
| 5 |
use Wikimedia\TestingAccessWrapper; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class ReverseChronologicalPagerTest extends MediaWikiIntegrationTestCase { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function testGetDateCond( $params, $expected ) { |
| 22 |
$pager = $this->getMockForAbstractClass( ReverseChronologicalPager::class ); |
| 23 |
$pagerWrapper = TestingAccessWrapper::newFromObject( $pager ); |
| 24 |
|
| 25 |
$pager->getDateCond( ...$params ); |
| 26 |
$this->assertEquals( $pagerWrapper->endOffset, $this->getDb()->timestamp( $expected ) ); |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public static function provideGetDateCond() { |
| 33 |
yield 'Test year and month' => [ |
| 34 |
[ 2006, 6 ], '20060701000000' |
| 35 |
]; |
| 36 |
yield 'Test year, month, and day' => [ |
| 37 |
[ 2006, 6, 5 ], '20060606000000' |
| 38 |
]; |
| 39 |
yield 'Test month overflow into the next year' => [ |
| 40 |
[ 2006, 12 ], '20070101000000' |
| 41 |
]; |
| 42 |
yield 'Test day overflow to the next month' => [ |
| 43 |
[ 2006, 6, 30 ], '20060701000000' |
| 44 |
]; |
| 45 |
yield 'Test invalid month (should use end of year)' => [ |
| 46 |
[ 2006, -1 ], '20070101000000' |
| 47 |
]; |
| 48 |
yield 'Test invalid day (should use end of month)' => [ |
| 49 |
[ 2006, 6, 1337 ], '20060701000000' |
| 50 |
]; |
| 51 |
yield 'Test last day of year' => [ |
| 52 |
[ 2006, 12, 31 ], '20070101000000' |
| 53 |
]; |
| 54 |
yield 'Test invalid day that overflows to next year' => [ |
| 55 |
[ 2006, 12, 32 ], '20070101000000' |
| 56 |
]; |
| 57 |
yield '3-digit year, T287621' => [ |
| 58 |
[ 720, 1, 5 ], '07200106000000' |
| 59 |
]; |
| 60 |
yield 'Y2K38' => [ |
| 61 |
[ 2042, 1, 5 ], '20420106000000' |
| 62 |
]; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public function testGetDateCondSpecial() { |
| 69 |
$pager = $this->getMockForAbstractClass( ReverseChronologicalPager::class ); |
| 70 |
$pagerWrapper = TestingAccessWrapper::newFromObject( $pager ); |
| 71 |
$timestamp = MWTimestamp::getInstance(); |
| 72 |
$db = $this->getDb(); |
| 73 |
|
| 74 |
$currYear = $timestamp->format( 'Y' ); |
| 75 |
$currMonth = $timestamp->format( 'n' ); |
| 76 |
|
| 77 |
|
| 78 |
$this->assertEquals( $pager->getDateCond( 2006, 6 ), $pagerWrapper->endOffset ); |
| 79 |
|
| 80 |
|
| 81 |
if ( $currMonth < 5 ) { |
| 82 |
$pager->getDateCond( -1, 5 ); |
| 83 |
$this->assertEquals( $pagerWrapper->endOffset, $db->timestamp( $currYear - 1 . '0601000000' ) ); |
| 84 |
} |
| 85 |
if ( $currMonth < 12 ) { |
| 86 |
$pager->getDateCond( -1, 12 ); |
| 87 |
$this->assertEquals( $pagerWrapper->endOffset, $db->timestamp( $currYear . '0101000000' ) ); |
| 88 |
} |
| 89 |
} |
| 90 |
} |