Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / pager / RangeChronologicalPagerTest.php
blob3cab35a624e3f97e09c8d7827decbe08a4781165
1 <?php
3 use MediaWiki\MediaWikiServices;
4 use MediaWiki\Pager\RangeChronologicalPager;
6 /**
7 * Test class for RangeChronologicalPagerTest logic.
9 * @group Pager
10 * @group Database
12 * @author Geoffrey Mon <geofbot@gmail.com>
14 class RangeChronologicalPagerTest extends MediaWikiIntegrationTestCase {
16 /**
17 * @covers \MediaWiki\Pager\RangeChronologicalPager::getDateCond
18 * @dataProvider getDateCondProvider
20 public function testGetDateCond( $inputYear, $inputMonth, $inputDay, $expected ) {
21 $pager = $this->getMockForAbstractClass( RangeChronologicalPager::class );
22 $this->assertEquals(
23 $expected,
24 wfTimestamp( TS_MW, $pager->getDateCond( $inputYear, $inputMonth, $inputDay ) )
28 /**
29 * Data provider in [ input year, input month, input day, expected timestamp output ] format
31 public static function getDateCondProvider() {
32 return [
33 [ 2016, 12, 5, '20161206000000' ],
34 [ 2016, 12, 31, '20170101000000' ],
35 [ 2016, 12, 1337, '20170101000000' ],
36 [ 2016, 1337, 1337, '20170101000000' ],
37 [ 2016, 1337, -1, '20170101000000' ],
38 [ 2016, 12, 32, '20170101000000' ],
39 [ 2016, 12, -1, '20170101000000' ],
40 [ 2016, -1, -1, '20170101000000' ],
44 /**
45 * @covers \MediaWiki\Pager\RangeChronologicalPager::getDateRangeCond
46 * @dataProvider getDateRangeCondProvider
48 public function testGetDateRangeCond( $start, $end, $expected ) {
49 $pager = $this->getMockForAbstractClass( RangeChronologicalPager::class );
50 $this->assertArrayEquals( $expected, $pager->getDateRangeCond( $start, $end ) );
53 /**
54 * Data provider in [ start, end, [ expected output has start condition, has end cond ] ] format
56 public static function getDateRangeCondProvider() {
57 $dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase();
59 return [
61 '20161201000000',
62 '20161202235959',
64 $dbw->buildComparison( '>=', [ '' => $dbw->timestamp( '20161201000000' ) ] ),
65 $dbw->buildComparison( '<', [ '' => $dbw->timestamp( '20161203000000' ) ] ),
69 '',
70 '20161202235959',
72 $dbw->buildComparison( '<', [ '' => $dbw->timestamp( '20161203000000' ) ] ),
76 '20161201000000',
77 '',
79 $dbw->buildComparison( '>=', [ '' => $dbw->timestamp( '20161201000000' ) ] ),
82 [ '', '', [] ],
86 /**
87 * @covers \MediaWiki\Pager\RangeChronologicalPager::getDateRangeCond
88 * @dataProvider getDateRangeCondInvalidProvider
90 public function testGetDateRangeCondInvalid( $start, $end ) {
91 $pager = $this->getMockForAbstractClass( RangeChronologicalPager::class );
92 $this->assertNull( $pager->getDateRangeCond( $start, $end ) );
95 public static function getDateRangeCondInvalidProvider() {
96 return [
97 [ '-2016-12-01', '2017-12-01', ],
98 [ '2016-12-01', '-2017-12-01', ],
99 [ 'abcdefghij', 'klmnopqrstu', ],