MediaWiki  1.28.0
ReverseChronologicalPagerTest.php
Go to the documentation of this file.
1 <?php
2 
11 
15  public function testGetDateCond() {
16  $pager = $this->getMockForAbstractClass( 'ReverseChronologicalPager' );
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 }
69 
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
timestamp($ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
Definition: Database.php:2894
const DB_MASTER
Definition: defines.php:23
Test class for ReverseChronologicalPagerTest methods.
if($limit) $timestamp
static getInstance($ts=false)
Get a timestamp instance in GMT.
Definition: MWTimestamp.php:38
Base class that store and restore the Language objects.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Database $db
Primary database.
testGetDateCond()
ReverseChronologicalPager::getDateCond.