3 use MediaWiki\MediaWikiServices
;
4 use MediaWiki\Pager\RangeChronologicalPager
;
7 * Test class for RangeChronologicalPagerTest logic.
12 * @author Geoffrey Mon <geofbot@gmail.com>
14 class RangeChronologicalPagerTest
extends MediaWikiIntegrationTestCase
{
17 * @covers \MediaWiki\Pager\RangeChronologicalPager::getDateCond
18 * @dataProvider getDateCondProvider
20 public function testGetDateCond( $inputYear, $inputMonth, $inputDay, $expected ) {
21 $pager = $this->getMockForAbstractClass( RangeChronologicalPager
::class );
24 wfTimestamp( TS_MW
, $pager->getDateCond( $inputYear, $inputMonth, $inputDay ) )
29 * Data provider in [ input year, input month, input day, expected timestamp output ] format
31 public static function getDateCondProvider() {
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' ],
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 ) );
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();
64 $dbw->buildComparison( '>=', [ '' => $dbw->timestamp( '20161201000000' ) ] ),
65 $dbw->buildComparison( '<', [ '' => $dbw->timestamp( '20161203000000' ) ] ),
72 $dbw->buildComparison( '<', [ '' => $dbw->timestamp( '20161203000000' ) ] ),
79 $dbw->buildComparison( '>=', [ '' => $dbw->timestamp( '20161201000000' ) ] ),
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() {
97 [ '-2016-12-01', '2017-12-01', ],
98 [ '2016-12-01', '-2017-12-01', ],
99 [ 'abcdefghij', 'klmnopqrstu', ],