MediaWiki REL1_32
ReverseChronologicalPagerTest.php
Go to the documentation of this file.
1<?php
2
11
15 public function testGetDateCond() {
16 $pager = $this->getMockForAbstractClass( ReverseChronologicalPager::class );
17 $timestamp = MWTimestamp::getInstance();
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}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Base class that store and restore the Language objects.
Database $db
Primary database.
Test class for ReverseChronologicalPagerTest methods.
testGetDateCond()
ReverseChronologicalPager::getDateCond.
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
const DB_MASTER
Definition defines.php:26