4 * Test class for ReverseChronologicalPagerTest methods.
8 * @author Geoffrey Mon <geofbot@gmail.com>
10 class ReverseChronologicalPagerTest
extends MediaWikiLangTestCase
{
13 * @covers ReverseChronologicalPager::getDateCond
15 public function testGetDateCond() {
16 $pager = $this->getMockForAbstractClass( 'ReverseChronologicalPager' );
17 $timestamp = MWTimestamp
::getInstance();
18 $db = wfGetDB( DB_MASTER
);
20 $currYear = $timestamp->format( 'Y' );
21 $currMonth = $timestamp->format( 'n' );
22 $currYearTimestamp = $db->timestamp( $currYear +
1 . '0101000000' );
24 // Test that getDateCond sets and returns mOffset
25 $this->assertEquals( $pager->getDateCond( 2006 ), $pager->mOffset
);
28 $pager->getDateCond( 2006 );
29 $this->assertEquals( $pager->mOffset
, $db->timestamp( '20070101000000' ) );
31 // Test year and month
32 $pager->getDateCond( 2006, 6 );
33 $this->assertEquals( $pager->mOffset
, $db->timestamp( '20060701000000' ) );
35 // Test year, month, and day
36 $pager->getDateCond( 2006, 6, 5 );
37 $this->assertEquals( $pager->mOffset
, $db->timestamp( '20060606000000' ) );
39 // Test month overflow into the next year
40 $pager->getDateCond( 2006, 12 );
41 $this->assertEquals( $pager->mOffset
, $db->timestamp( '20070101000000' ) );
43 // Test day overflow to the next month
44 $pager->getDateCond( 2006, 6, 30 );
45 $this->assertEquals( $pager->mOffset
, $db->timestamp( '20060701000000' ) );
47 // Test invalid year (should use current year)
48 $pager->getDateCond( -1337 );
49 $this->assertEquals( $pager->mOffset
, $currYearTimestamp );
52 $pager->getDateCond( 2006, -1 );
53 $this->assertEquals( $pager->mOffset
, $db->timestamp( '20070101000000' ) );
56 $pager->getDateCond( 2006, 6, 1337 );
57 $this->assertEquals( $pager->mOffset
, $db->timestamp( '20060701000000' ) );
59 // Test no year or month (should use end of current year)
60 $pager->getDateCond();
61 $this->assertEquals( $pager->mOffset
, $currYearTimestamp );
63 // Test last day of year
64 $pager->getDateCond( 2006, 12, 31 );
65 $this->assertEquals( $pager->mOffset
, $db->timestamp( '20070101000000' ) );
67 // Test invalid day that overflows to next year
68 $pager->getDateCond( 2006, 12, 32 );
69 $this->assertEquals( $pager->mOffset
, $db->timestamp( '20070101000000' ) );
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' ) );
76 if ( $currMonth < 12 ) {
77 $pager->getDateCond( -1, 12 );
78 $this->assertEquals( $pager->mOffset
, $db->timestamp( $currYear . '0101000000' ) );