Merge "MimeAnalyzer: Detect magic bytes for mp3"
[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' );
18 $this->assertEquals( $expected, $pager->getDateCond( $inputYear, $inputMonth, $inputDay ) );
19 }
20
21 /**
22 * Data provider in [ input year, input month, input day, expected timestamp output ] format
23 */
24 public function getDateCondProvider() {
25 return [
26 [ 2016, 12, 5, '20161205235959' ],
27 [ 2016, 12, 31, '20161231235959' ],
28 [ 2016, 12, 1337, '20161231235959' ],
29 [ 2016, 1337, 1337, '20161231235959' ],
30 [ 2016, 1337, -1, '20161231235959' ],
31 [ 2016, 12, 32, '20161231235959' ],
32 [ 2016, 12, -1, '20161231235959' ],
33 [ 2016, -1, -1, '20161231235959' ],
34 ];
35 }
36
37 /**
38 * @covers RangeChronologicalPager::getDateRangeCond
39 * @dataProvider getDateRangeCondProvider
40 */
41 public function testGetDateRangeCond( $start, $end, $expected ) {
42 $pager = $this->getMockForAbstractClass( 'RangeChronologicalPager' );
43 $this->assertArrayEquals( $expected, $pager->getDateRangeCond( $start, $end ) );
44 }
45
46 /**
47 * Data provider in [ start, end, [ expected output has start condition, has end cond ] ] format
48 */
49 public function getDateRangeCondProvider() {
50 $db = wfGetDB( DB_MASTER );
51
52 return [
53 [
54 '20161201000000',
55 '20161203000000',
56 [
57 '>=' . $db->addQuotes( $db->timestamp( '20161201000000' ) ),
58 '<=' . $db->addQuotes( $db->timestamp( '20161203000000' ) ),
59 ],
60 ],
61 [
62 '',
63 '20161203000000',
64 [
65 '<=' . $db->addQuotes( $db->timestamp( '20161203000000' ) ),
66 ],
67 ],
68 [
69 '20161201000000',
70 '',
71 [
72 '>=' . $db->addQuotes( $db->timestamp( '20161201000000' ) ),
73 ],
74 ],
75 [ '', '', [] ],
76 ];
77 }
78
79 /**
80 * @covers RangeChronologicalPager::getDateRangeCond
81 * @dataProvider getDateRangeCondInvalidProvider
82 */
83 public function testGetDateRangeCondInvalid( $start, $end ) {
84 $pager = $this->getMockForAbstractClass( 'RangeChronologicalPager' );
85 $this->assertEquals( null, $pager->getDateRangeCond( $start, $end ) );
86 }
87
88 public function getDateRangeCondInvalidProvider() {
89 return [
90 [ '-2016-12-01', '2017-12-01', ],
91 [ '2016-12-01', '-2017-12-01', ],
92 [ 'abcdefghij', 'klmnopqrstu', ],
93 ];
94 }
95
96 }