Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / pager / ReverseChronologicalPagerTest.php
blob55478c8bd0cde5c5edfd8a729480778d26ea57af
1 <?php
3 use MediaWiki\Pager\ReverseChronologicalPager;
4 use MediaWiki\Utils\MWTimestamp;
5 use Wikimedia\TestingAccessWrapper;
7 /**
8 * Test class for ReverseChronologicalPagerTest methods.
10 * @group Pager
11 * @group Database
13 * @author Geoffrey Mon <geofbot@gmail.com>
15 class ReverseChronologicalPagerTest extends MediaWikiIntegrationTestCase {
17 /**
18 * @covers \MediaWiki\Pager\ReverseChronologicalPager::getDateCond
19 * @dataProvider provideGetDateCond
21 public function testGetDateCond( $params, $expected ) {
22 $pager = $this->getMockForAbstractClass( ReverseChronologicalPager::class );
23 $pagerWrapper = TestingAccessWrapper::newFromObject( $pager );
25 $pager->getDateCond( ...$params );
26 $this->assertEquals( $pagerWrapper->endOffset, $this->getDb()->timestamp( $expected ) );
29 /**
30 * Data provider in description => [ [ param1, ... ], expected output ] format
32 public static function provideGetDateCond() {
33 yield 'Test year and month' => [
34 [ 2006, 6 ], '20060701000000'
36 yield 'Test year, month, and day' => [
37 [ 2006, 6, 5 ], '20060606000000'
39 yield 'Test month overflow into the next year' => [
40 [ 2006, 12 ], '20070101000000'
42 yield 'Test day overflow to the next month' => [
43 [ 2006, 6, 30 ], '20060701000000'
45 yield 'Test invalid month (should use end of year)' => [
46 [ 2006, -1 ], '20070101000000'
48 yield 'Test invalid day (should use end of month)' => [
49 [ 2006, 6, 1337 ], '20060701000000'
51 yield 'Test last day of year' => [
52 [ 2006, 12, 31 ], '20070101000000'
54 yield 'Test invalid day that overflows to next year' => [
55 [ 2006, 12, 32 ], '20070101000000'
57 yield '3-digit year, T287621' => [
58 [ 720, 1, 5 ], '07200106000000'
60 yield 'Y2K38' => [
61 [ 2042, 1, 5 ], '20420106000000'
65 /**
66 * @covers \MediaWiki\Pager\ReverseChronologicalPager::getDateCond
68 public function testGetDateCondSpecial() {
69 $pager = $this->getMockForAbstractClass( ReverseChronologicalPager::class );
70 $pagerWrapper = TestingAccessWrapper::newFromObject( $pager );
71 $timestamp = MWTimestamp::getInstance();
72 $db = $this->getDb();
74 $currYear = $timestamp->format( 'Y' );
75 $currMonth = $timestamp->format( 'n' );
77 // Test that getDateCond sets and returns offset
78 $this->assertEquals( $pager->getDateCond( 2006, 6 ), $pagerWrapper->endOffset );
80 // Test month past current month (should use previous year)
81 if ( $currMonth < 5 ) {
82 $pager->getDateCond( -1, 5 );
83 $this->assertEquals( $pagerWrapper->endOffset, $db->timestamp( $currYear - 1 . '0601000000' ) );
85 if ( $currMonth < 12 ) {
86 $pager->getDateCond( -1, 12 );
87 $this->assertEquals( $pagerWrapper->endOffset, $db->timestamp( $currYear . '0101000000' ) );