Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / pager / ReverseChronologicalPagerTest.php
blobeb163d3834b550bad93929acb40fe1a809a1593c
1 <?php
3 /**
4 * Test class for ReverseChronologicalPagerTest methods.
6 * @group Pager
8 * @author Geoffrey Mon <geofbot@gmail.com>
9 */
10 class ReverseChronologicalPagerTest extends MediaWikiLangTestCase {
12 /**
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' );
23 // Test that getDateCond sets and returns mOffset
24 $this->assertEquals( $pager->getDateCond( 2006, 6 ), $pager->mOffset );
26 // Test year and month
27 $pager->getDateCond( 2006, 6 );
28 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060701000000' ) );
30 // Test year, month, and day
31 $pager->getDateCond( 2006, 6, 5 );
32 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060606000000' ) );
34 // Test month overflow into the next year
35 $pager->getDateCond( 2006, 12 );
36 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
38 // Test day overflow to the next month
39 $pager->getDateCond( 2006, 6, 30 );
40 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060701000000' ) );
42 // Test invalid month (should use end of year)
43 $pager->getDateCond( 2006, -1 );
44 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
46 // Test invalid day (should use end of month)
47 $pager->getDateCond( 2006, 6, 1337 );
48 $this->assertEquals( $pager->mOffset, $db->timestamp( '20060701000000' ) );
50 // Test last day of year
51 $pager->getDateCond( 2006, 12, 31 );
52 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
54 // Test invalid day that overflows to next year
55 $pager->getDateCond( 2006, 12, 32 );
56 $this->assertEquals( $pager->mOffset, $db->timestamp( '20070101000000' ) );
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' ) );
63 if ( $currMonth < 12 ) {
64 $pager->getDateCond( -1, 12 );
65 $this->assertEquals( $pager->mOffset, $db->timestamp( $currYear . '0101000000' ) );