MediaWiki  REL1_31
ContribsPagerTest.php
Go to the documentation of this file.
1 <?php
2 
8  private $pager;
9 
10  function setUp() {
11  $context = new RequestContext();
12  $this->pager = new ContribsPager( $context, [
13  'start' => '2017-01-01',
14  'end' => '2017-02-02',
15  ] );
16 
17  parent::setUp();
18  }
19 
26  public function testDateFilterOptionProcessing( $inputOpts, $expectedOpts ) {
27  $this->assertArraySubset( $expectedOpts, ContribsPager::processDateFilter( $inputOpts ) );
28  }
29 
30  public static function dateFilterOptionProcessingProvider() {
31  return [
32  [ [ 'start' => '2016-05-01',
33  'end' => '2016-06-01',
34  'year' => null,
35  'month' => null ],
36  [ 'start' => '2016-05-01',
37  'end' => '2016-06-01' ] ],
38  [ [ 'start' => '2016-05-01',
39  'end' => '2016-06-01',
40  'year' => '',
41  'month' => '' ],
42  [ 'start' => '2016-05-01',
43  'end' => '2016-06-01' ] ],
44  [ [ 'start' => '2016-05-01',
45  'end' => '2016-06-01',
46  'year' => '2012',
47  'month' => '5' ],
48  [ 'start' => '',
49  'end' => '2012-05-31' ] ],
50  [ [ 'start' => '',
51  'end' => '',
52  'year' => '2012',
53  'month' => '5' ],
54  [ 'start' => '',
55  'end' => '2012-05-31' ] ],
56  [ [ 'start' => '',
57  'end' => '',
58  'year' => '2012',
59  'month' => '' ],
60  [ 'start' => '',
61  'end' => '2012-12-31' ] ],
62  ];
63  }
64 
69  public function testQueryableRanges( $ipRange ) {
70  $this->setMwGlobals( [
71  'wgRangeContributionsCIDRLimit' => [
72  'IPv4' => 16,
73  'IPv6' => 32,
74  ],
75  ] );
76 
77  $this->assertTrue(
78  $this->pager->isQueryableRange( $ipRange ),
79  "$ipRange is a queryable IP range"
80  );
81  }
82 
83  public function provideQueryableRanges() {
84  return [
85  [ '116.17.184.5/32' ],
86  [ '0.17.184.5/16' ],
87  [ '2000::/32' ],
88  [ '2001:db8::/128' ],
89  ];
90  }
91 
96  public function testUnqueryableRanges( $ipRange ) {
97  $this->setMwGlobals( [
98  'wgRangeContributionsCIDRLimit' => [
99  'IPv4' => 16,
100  'IPv6' => 32,
101  ],
102  ] );
103 
104  $this->assertFalse(
105  $this->pager->isQueryableRange( $ipRange ),
106  "$ipRange is not a queryable IP range"
107  );
108  }
109 
110  public function provideUnqueryableRanges() {
111  return [
112  [ '116.17.184.5/33' ],
113  [ '0.17.184.5/15' ],
114  [ '2000::/31' ],
115  [ '2001:db8::/9999' ],
116  ];
117  }
118 }
ContribsPagerTest
Database.
Definition: ContribsPagerTest.php:6
ContribsPagerTest\testDateFilterOptionProcessing
testDateFilterOptionProcessing( $inputOpts, $expectedOpts)
ContribsPager::processDateFilter dateFilterOptionProcessingProvider.
Definition: ContribsPagerTest.php:26
ContribsPagerTest\testQueryableRanges
testQueryableRanges( $ipRange)
ContribsPager::isQueryableRange provideQueryableRanges.
Definition: ContribsPagerTest.php:69
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:37
ContribsPager\processDateFilter
static processDateFilter(array $opts)
Set up date filter options, given request data.
Definition: ContribsPager.php:642
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:678
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
ContribsPagerTest\testUnqueryableRanges
testUnqueryableRanges( $ipRange)
ContribsPager::isQueryableRange provideUnqueryableRanges.
Definition: ContribsPagerTest.php:96
ContribsPagerTest\$pager
ContribsPager $pager
Definition: ContribsPagerTest.php:8
ContribsPagerTest\provideQueryableRanges
provideQueryableRanges()
Definition: ContribsPagerTest.php:83
ContribsPagerTest\dateFilterOptionProcessingProvider
static dateFilterOptionProcessingProvider()
Definition: ContribsPagerTest.php:30
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:32
ContribsPagerTest\provideUnqueryableRanges
provideUnqueryableRanges()
Definition: ContribsPagerTest.php:110
ContribsPager
Definition: ContribsPager.php:31
ContribsPagerTest\setUp
setUp()
Definition: ContribsPagerTest.php:10
$context
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2811