Merge "Revert "Log the reason why revision->getContent() returns null""
[lhc/web/wiklou.git] / tests / phpunit / includes / pager / RangeChronologicalPagerTest.php
1 <?php
2
3 /**
4 * Test class for RangeChronologicalPagerTest logic.
5 *
6 * @group Pager
7 *
8 * @author Geoffrey Mon <geofbot@gmail.com>
9 */
10 class RangeChronologicalPagerTest extends MediaWikiLangTestCase {
11
12 /**
13 * @covers RangeChronologicalPager::getDateCond
14 * @dataProvider getDateCondProvider
15 */
16 public function testGetDateCond( $inputYear, $inputMonth, $inputDay, $expected ) {
17 $pager = $this->getMockForAbstractClass( RangeChronologicalPager::class );
18 $this->assertEquals(
19 $expected,
20 wfTimestamp( TS_MW, $pager->getDateCond( $inputYear, $inputMonth, $inputDay ) )
21 );
22 }
23
24 /**
25 * Data provider in [ input year, input month, input day, expected timestamp output ] format
26 */
27 public function getDateCondProvider() {
28 return [
29 [ 2016, 12, 5, '20161205235959' ],
30 [ 2016, 12, 31, '20161231235959' ],
31 [ 2016, 12, 1337, '20161231235959' ],
32 [ 2016, 1337, 1337, '20161231235959' ],
33 [ 2016, 1337, -1, '20161231235959' ],
34 [ 2016, 12, 32, '20161231235959' ],
35 [ 2016, 12, -1, '20161231235959' ],
36 [ 2016, -1, -1, '20161231235959' ],
37 ];
38 }
39
40 /**
41 * @covers RangeChronologicalPager::getDateRangeCond
42 * @dataProvider getDateRangeCondProvider
43 */
44 public function testGetDateRangeCond( $start, $end, $expected ) {
45 $pager = $this->getMockForAbstractClass( RangeChronologicalPager::class );
46 $this->assertArrayEquals( $expected, $pager->getDateRangeCond( $start, $end ) );
47 }
48
49 /**
50 * Data provider in [ start, end, [ expected output has start condition, has end cond ] ] format
51 */
52 public function getDateRangeCondProvider() {
53 $db = wfGetDB( DB_MASTER );
54
55 return [
56 [
57 '20161201000000',
58 '20161203000000',
59 [
60 '>=' . $db->addQuotes( $db->timestamp( '20161201000000' ) ),
61 '<=' . $db->addQuotes( $db->timestamp( '20161203000000' ) ),
62 ],
63 ],
64 [
65 '',
66 '20161203000000',
67 [
68 '<=' . $db->addQuotes( $db->timestamp( '20161203000000' ) ),
69 ],
70 ],
71 [
72 '20161201000000',
73 '',
74 [
75 '>=' . $db->addQuotes( $db->timestamp( '20161201000000' ) ),
76 ],
77 ],
78 [ '', '', [] ],
79 ];
80 }
81
82 /**
83 * @covers RangeChronologicalPager::getDateRangeCond
84 * @dataProvider getDateRangeCondInvalidProvider
85 */
86 public function testGetDateRangeCondInvalid( $start, $end ) {
87 $pager = $this->getMockForAbstractClass( RangeChronologicalPager::class );
88 $this->assertEquals( null, $pager->getDateRangeCond( $start, $end ) );
89 }
90
91 public function getDateRangeCondInvalidProvider() {
92 return [
93 [ '-2016-12-01', '2017-12-01', ],
94 [ '2016-12-01', '-2017-12-01', ],
95 [ 'abcdefghij', 'klmnopqrstu', ],
96 ];
97 }
98
99 }