2015-12-22 20:48:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
2022-12-03 09:15:04 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
2015-12-22 20:48:19 +00:00
|
|
|
/**
|
|
|
|
|
* Test class for ReverseChronologicalPagerTest methods.
|
|
|
|
|
*
|
|
|
|
|
* @group Pager
|
|
|
|
|
*
|
|
|
|
|
* @author Geoffrey Mon <geofbot@gmail.com>
|
|
|
|
|
*/
|
2022-12-03 09:15:04 +00:00
|
|
|
class ReverseChronologicalPagerTest extends MediaWikiIntegrationTestCase {
|
2015-12-22 20:48:19 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ReverseChronologicalPager::getDateCond
|
2022-12-03 09:15:04 +00:00
|
|
|
* @dataProvider provideGetDateCond
|
2015-12-22 20:48:19 +00:00
|
|
|
*/
|
2022-12-03 09:15:04 +00:00
|
|
|
public function testGetDateCond( $params, $expected ) {
|
2018-01-13 00:02:09 +00:00
|
|
|
$pager = $this->getMockForAbstractClass( ReverseChronologicalPager::class );
|
2022-12-03 09:15:04 +00:00
|
|
|
$pagerWrapper = TestingAccessWrapper::newFromObject( $pager );
|
2021-04-29 02:37:11 +00:00
|
|
|
$db = wfGetDB( DB_PRIMARY );
|
2015-12-22 20:48:19 +00:00
|
|
|
|
2022-12-03 09:15:04 +00:00
|
|
|
$pager->getDateCond( ...$params );
|
|
|
|
|
$this->assertEquals( $pagerWrapper->endOffset, $db->timestamp( $expected ) );
|
|
|
|
|
}
|
2015-12-22 20:48:19 +00:00
|
|
|
|
2022-12-03 09:15:04 +00:00
|
|
|
/**
|
|
|
|
|
* Data provider in description => [ [ param1, ... ], expected output ] format
|
|
|
|
|
*/
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideGetDateCond() {
|
2022-12-03 09:15:04 +00:00
|
|
|
yield 'Test year and month' => [
|
|
|
|
|
[ 2006, 6 ], '20060701000000'
|
|
|
|
|
];
|
|
|
|
|
yield 'Test year, month, and day' => [
|
|
|
|
|
[ 2006, 6, 5 ], '20060606000000'
|
|
|
|
|
];
|
|
|
|
|
yield 'Test month overflow into the next year' => [
|
|
|
|
|
[ 2006, 12 ], '20070101000000'
|
|
|
|
|
];
|
|
|
|
|
yield 'Test day overflow to the next month' => [
|
|
|
|
|
[ 2006, 6, 30 ], '20060701000000'
|
|
|
|
|
];
|
|
|
|
|
yield 'Test invalid month (should use end of year)' => [
|
|
|
|
|
[ 2006, -1 ], '20070101000000'
|
|
|
|
|
];
|
|
|
|
|
yield 'Test invalid day (should use end of month)' => [
|
|
|
|
|
[ 2006, 6, 1337 ], '20060701000000'
|
|
|
|
|
];
|
|
|
|
|
yield 'Test last day of year' => [
|
|
|
|
|
[ 2006, 12, 31 ], '20070101000000'
|
|
|
|
|
];
|
|
|
|
|
yield 'Test invalid day that overflows to next year' => [
|
|
|
|
|
[ 2006, 12, 32 ], '20070101000000'
|
|
|
|
|
];
|
|
|
|
|
yield '3-digit year, T287621' => [
|
|
|
|
|
[ 720, 1, 5 ], '07200106000000'
|
|
|
|
|
];
|
|
|
|
|
yield 'Y2K38 bug' => [
|
|
|
|
|
[ 2042, 1, 5 ], '20320101000000'
|
|
|
|
|
];
|
|
|
|
|
}
|
2015-12-22 20:48:19 +00:00
|
|
|
|
2022-12-03 09:15:04 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ReverseChronologicalPager::getDateCond
|
|
|
|
|
*/
|
|
|
|
|
public function testGetDateCondSpecial() {
|
|
|
|
|
$pager = $this->getMockForAbstractClass( ReverseChronologicalPager::class );
|
|
|
|
|
$pagerWrapper = TestingAccessWrapper::newFromObject( $pager );
|
|
|
|
|
$timestamp = MWTimestamp::getInstance();
|
|
|
|
|
$db = wfGetDB( DB_PRIMARY );
|
2015-12-22 20:48:19 +00:00
|
|
|
|
2022-12-03 09:15:04 +00:00
|
|
|
$currYear = $timestamp->format( 'Y' );
|
|
|
|
|
$currMonth = $timestamp->format( 'n' );
|
2015-12-22 20:48:19 +00:00
|
|
|
|
2022-12-03 09:15:04 +00:00
|
|
|
// Test that getDateCond sets and returns offset
|
|
|
|
|
$this->assertEquals( $pager->getDateCond( 2006, 6 ), $pagerWrapper->endOffset );
|
2015-12-22 20:48:19 +00:00
|
|
|
|
|
|
|
|
// Test month past current month (should use previous year)
|
|
|
|
|
if ( $currMonth < 5 ) {
|
|
|
|
|
$pager->getDateCond( -1, 5 );
|
2022-12-03 09:15:04 +00:00
|
|
|
$this->assertEquals( $pagerWrapper->endOffset, $db->timestamp( $currYear - 1 . '0601000000' ) );
|
2015-12-22 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
if ( $currMonth < 12 ) {
|
|
|
|
|
$pager->getDateCond( -1, 12 );
|
2022-12-03 09:15:04 +00:00
|
|
|
$this->assertEquals( $pagerWrapper->endOffset, $db->timestamp( $currYear . '0101000000' ) );
|
2015-12-22 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|