Merge "Fix sessionfailure i18n message during authentication"
[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::class );
17 $timestamp = MWTimestamp::getInstance();
18 $db = wfGetDB( DB_MASTER );
19
20 $currYear = $timestamp->format( 'Y' );
21 $currMonth = $timestamp->format( 'n' );
22
23 // Test that getDateCond sets and returns mOffset
24 $this->assertEquals( $pager->getDateCond( 2006, 6 ), $pager->mOffset );
25
26 // Test year and month
27 $pager->getDateCond( 2006, 6 );
28 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060701000000' ) );
29
30 // Test year, month, and day
31 $pager->getDateCond( 2006, 6, 5 );
32 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060606000000' ) );
33
34 // Test month overflow into the next year
35 $pager->getDateCond( 2006, 12 );
36 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
37
38 // Test day overflow to the next month
39 $pager->getDateCond( 2006, 6, 30 );
40 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060701000000' ) );
41
42 // Test invalid month (should use end of year)
43 $pager->getDateCond( 2006, -1 );
44 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
45
46 // Test invalid day (should use end of month)
47 $pager->getDateCond( 2006, 6, 1337 );
48 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060701000000' ) );
49
50 // Test last day of year
51 $pager->getDateCond( 2006, 12, 31 );
52 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
53
54 // Test invalid day that overflows to next year
55 $pager->getDateCond( 2006, 12, 32 );
56 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
57
58 // Test month past current month (should use previous year)
59 if ( $currMonth < 5 ) {
60 $pager->getDateCond( -1, 5 );
61 $this->assertEquals( $pager->mOffset, $db->timestamp( $currYear - 1 . '0601000000' ) );
62 }
63 if ( $currMonth < 12 ) {
64 $pager->getDateCond( -1, 12 );
65 $this->assertEquals( $pager->mOffset, $db->timestamp( $currYear . '0101000000' ) );
66 }
67 }
68 }