Merge "Add a change tag for edits that change the content model of a page"
[lhc/web/wiklou.git] / tests / phpunit / includes / pager / ReverseChronologicalPagerTest.php
1 <?php
2
3 /**
4 * Test class for ReverseChronologicalPagerTest methods.
5 *
6 * @group Pager
7 *
8 * @author Geoffrey Mon <geofbot@gmail.com>
9 */
10 class ReverseChronologicalPagerTest extends MediaWikiLangTestCase {
11
12 /**
13 * @covers ReverseChronologicalPager::getDateCond
14 */
15 public function testGetDateCond() {
16 $pager = $this->getMockForAbstractClass( 'ReverseChronologicalPager' );
17 $timestamp = MWTimestamp::getInstance();
18 $db = wfGetDB( DB_MASTER );
19
20 $currYear = $timestamp->format( 'Y' );
21 $currMonth = $timestamp->format( 'n' );
22 $currYearTimestamp = $db->timestamp( $currYear + 1 . '0101000000' );
23
24 // Test that getDateCond sets and returns mOffset
25 $this->assertEquals( $pager->getDateCond( 2006 ), $pager->mOffset );
26
27 // Test year
28 $pager->getDateCond( 2006 );
29 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
30
31 // Test year and month
32 $pager->getDateCond( 2006, 6 );
33 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060701000000' ) );
34
35 // Test year, month, and day
36 $pager->getDateCond( 2006, 6, 5 );
37 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060606000000' ) );
38
39 // Test month overflow into the next year
40 $pager->getDateCond( 2006, 12 );
41 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
42
43 // Test day overflow to the next month
44 $pager->getDateCond( 2006, 6, 30 );
45 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060701000000' ) );
46
47 // Test invalid year (should use current year)
48 $pager->getDateCond( -1337 );
49 $this->assertEquals( $pager->mOffset, $currYearTimestamp );
50
51 // Test invalid month
52 $pager->getDateCond( 2006, -1 );
53 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
54
55 // Test invalid day
56 $pager->getDateCond( 2006, 6, 1337 );
57 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060701000000' ) );
58
59 // Test no year or month (should use end of current year)
60 $pager->getDateCond();
61 $this->assertEquals( $pager->mOffset, $currYearTimestamp );
62
63 // Test last day of year
64 $pager->getDateCond( 2006, 12, 31 );
65 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
66
67 // Test invalid day that overflows to next year
68 $pager->getDateCond( 2006, 12, 32 );
69 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
70
71 // Test month past current month (should use previous year)
72 if ( $currMonth < 5 ) {
73 $pager->getDateCond( -1, 5 );
74 $this->assertEquals( $pager->mOffset, $db->timestamp( $currYear - 1 . '0601000000' ) );
75 }
76 if ( $currMonth < 12 ) {
77 $pager->getDateCond( -1, 12 );
78 $this->assertEquals( $pager->mOffset, $db->timestamp( $currYear . '0101000000' ) );
79 }
80 }
81 }
82