MediaWiki  1.30.0
RangeChronologicalPagerTest.php
Go to the documentation of this file.
1 <?php
2 
11 
16  public function testGetDateCond( $inputYear, $inputMonth, $inputDay, $expected ) {
17  $pager = $this->getMockForAbstractClass( 'RangeChronologicalPager' );
18  $this->assertEquals(
19  $expected,
20  wfTimestamp( TS_MW, $pager->getDateCond( $inputYear, $inputMonth, $inputDay ) )
21  );
22  }
23 
27  public function getDateCondProvider() {
28  return [
29  [ 2016, 12, 5, '20161205235959' ],
30  [ 2016, 12, 31, '20161231235959' ],
31  [ 2016, 12, 1337, '20161231235959' ],
32  [ 2016, 1337, 1337, '20161231235959' ],
33  [ 2016, 1337, -1, '20161231235959' ],
34  [ 2016, 12, 32, '20161231235959' ],
35  [ 2016, 12, -1, '20161231235959' ],
36  [ 2016, -1, -1, '20161231235959' ],
37  ];
38  }
39 
44  public function testGetDateRangeCond( $start, $end, $expected ) {
45  $pager = $this->getMockForAbstractClass( 'RangeChronologicalPager' );
46  $this->assertArrayEquals( $expected, $pager->getDateRangeCond( $start, $end ) );
47  }
48 
52  public function getDateRangeCondProvider() {
53  $db = wfGetDB( DB_MASTER );
54 
55  return [
56  [
57  '20161201000000',
58  '20161203000000',
59  [
60  '>=' . $db->addQuotes( $db->timestamp( '20161201000000' ) ),
61  '<=' . $db->addQuotes( $db->timestamp( '20161203000000' ) ),
62  ],
63  ],
64  [
65  '',
66  '20161203000000',
67  [
68  '<=' . $db->addQuotes( $db->timestamp( '20161203000000' ) ),
69  ],
70  ],
71  [
72  '20161201000000',
73  '',
74  [
75  '>=' . $db->addQuotes( $db->timestamp( '20161201000000' ) ),
76  ],
77  ],
78  [ '', '', [] ],
79  ];
80  }
81 
86  public function testGetDateRangeCondInvalid( $start, $end ) {
87  $pager = $this->getMockForAbstractClass( 'RangeChronologicalPager' );
88  $this->assertEquals( null, $pager->getDateRangeCond( $start, $end ) );
89  }
90 
91  public function getDateRangeCondInvalidProvider() {
92  return [
93  [ '-2016-12-01', '2017-12-01', ],
94  [ '2016-12-01', '-2017-12-01', ],
95  [ 'abcdefghij', 'klmnopqrstu', ],
96  ];
97  }
98 
99 }
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:1552
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2040
RangeChronologicalPagerTest\testGetDateRangeCond
testGetDateRangeCond( $start, $end, $expected)
Definition: RangeChronologicalPagerTest.php:44
php
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
RangeChronologicalPagerTest\getDateRangeCondProvider
getDateRangeCondProvider()
Data provider in [ start, end, [ expected output has start condition, has end cond ] ] format.
Definition: RangeChronologicalPagerTest.php:52
RangeChronologicalPagerTest\getDateCondProvider
getDateCondProvider()
Data provider in [ input year, input month, input day, expected timestamp output ] format.
Definition: RangeChronologicalPagerTest.php:27
RangeChronologicalPagerTest\testGetDateRangeCondInvalid
testGetDateRangeCondInvalid( $start, $end)
Definition: RangeChronologicalPagerTest.php:86
RangeChronologicalPagerTest
Test class for RangeChronologicalPagerTest logic.
Definition: RangeChronologicalPagerTest.php:10
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2856
DB_MASTER
const DB_MASTER
Definition: defines.php:26
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
RangeChronologicalPagerTest\testGetDateCond
testGetDateCond( $inputYear, $inputMonth, $inputDay, $expected)
Definition: RangeChronologicalPagerTest.php:16
RangeChronologicalPagerTest\getDateRangeCondInvalidProvider
getDateRangeCondInvalidProvider()
Definition: RangeChronologicalPagerTest.php:91
MediaWikiTestCase\$db
Database $db
Primary database.
Definition: MediaWikiTestCase.php:52