MediaWiki  master
ContribsPagerTest.php
Go to the documentation of this file.
1 <?php
2 
4 
10  private $pager;
11 
12  function setUp() {
13  $context = new RequestContext();
14  $this->pager = new ContribsPager( $context, [
15  'start' => '2017-01-01',
16  'end' => '2017-02-02',
17  ] );
18 
19  parent::setUp();
20  }
21 
28  public function testDateFilterOptionProcessing( array $inputOpts, array $expectedOpts ) {
29  $this->assertArraySubset( $expectedOpts, ContribsPager::processDateFilter( $inputOpts ) );
30  }
31 
32  public static function dateFilterOptionProcessingProvider() {
33  return [
34  [ [ 'start' => '2016-05-01',
35  'end' => '2016-06-01',
36  'year' => null,
37  'month' => null ],
38  [ 'start' => '2016-05-01',
39  'end' => '2016-06-01' ] ],
40  [ [ 'start' => '2016-05-01',
41  'end' => '2016-06-01',
42  'year' => '',
43  'month' => '' ],
44  [ 'start' => '2016-05-01',
45  'end' => '2016-06-01' ] ],
46  [ [ 'start' => '2016-05-01',
47  'end' => '2016-06-01',
48  'year' => '2012',
49  'month' => '5' ],
50  [ 'start' => '',
51  'end' => '2012-05-31' ] ],
52  [ [ 'start' => '',
53  'end' => '',
54  'year' => '2012',
55  'month' => '5' ],
56  [ 'start' => '',
57  'end' => '2012-05-31' ] ],
58  [ [ 'start' => '',
59  'end' => '',
60  'year' => '2012',
61  'month' => '' ],
62  [ 'start' => '',
63  'end' => '2012-12-31' ] ],
64  ];
65  }
66 
71  public function testQueryableRanges( $ipRange ) {
72  $this->setMwGlobals( [
73  'wgRangeContributionsCIDRLimit' => [
74  'IPv4' => 16,
75  'IPv6' => 32,
76  ],
77  ] );
78 
79  $this->assertTrue(
80  $this->pager->isQueryableRange( $ipRange ),
81  "$ipRange is a queryable IP range"
82  );
83  }
84 
85  public function provideQueryableRanges() {
86  return [
87  [ '116.17.184.5/32' ],
88  [ '0.17.184.5/16' ],
89  [ '2000::/32' ],
90  [ '2001:db8::/128' ],
91  ];
92  }
93 
98  public function testUnqueryableRanges( $ipRange ) {
99  $this->setMwGlobals( [
100  'wgRangeContributionsCIDRLimit' => [
101  'IPv4' => 16,
102  'IPv6' => 32,
103  ],
104  ] );
105 
106  $this->assertFalse(
107  $this->pager->isQueryableRange( $ipRange ),
108  "$ipRange is not a queryable IP range"
109  );
110  }
111 
112  public function provideUnqueryableRanges() {
113  return [
114  [ '116.17.184.5/33' ],
115  [ '0.17.184.5/15' ],
116  [ '2000::/31' ],
117  [ '2001:db8::/9999' ],
118  ];
119  }
120 
127  $pager = new ContribsPager( new RequestContext(), [
128  'start' => '',
129  'end' => '',
130  ] );
131 
133  $pager = TestingAccessWrapper::newFromObject( $pager );
134  $queryInfo = $pager->buildQueryInfo( '', 1, false );
135 
136  $this->assertNotContains( 'ip_changes', $queryInfo[0] );
137  $this->assertArrayNotHasKey( 'ip_changes', $queryInfo[5] );
138  $this->assertContains( 'rev_timestamp', $queryInfo[1] );
139  $this->assertContains( 'rev_id', $queryInfo[1] );
140  $this->assertSame( [ 'rev_timestamp DESC', 'rev_id DESC' ], $queryInfo[4]['ORDER BY'] );
141  }
142 
148  public function testUniqueSortOrderOnIpChanges() {
149  $pager = new ContribsPager( new RequestContext(), [
150  'target' => '116.17.184.5/32',
151  'start' => '',
152  'end' => '',
153  ] );
154 
156  $pager = TestingAccessWrapper::newFromObject( $pager );
157  $queryInfo = $pager->buildQueryInfo( '', 1, false );
158 
159  $this->assertContains( 'ip_changes', $queryInfo[0] );
160  $this->assertArrayHasKey( 'ip_changes', $queryInfo[5] );
161  $this->assertSame( [ 'ipc_rev_timestamp DESC', 'ipc_rev_id DESC' ], $queryInfo[4]['ORDER BY'] );
162  }
163 
164 }
testDateFilterOptionProcessing(array $inputOpts, array $expectedOpts)
ContribsPager::processDateFilter dateFilterOptionProcessingProvider.
static processDateFilter(array $opts)
Set up date filter options, given request data.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
testUniqueSortOrderOnIpChanges()
\ContribsPager::getExtraSortFields \ContribsPager::getIndexField \ContribsPager::getQueryInfo ...
testUnqueryableRanges( $ipRange)
ContribsPager::isQueryableRange provideUnqueryableRanges.
static dateFilterOptionProcessingProvider()
ContribsPager $pager
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:773
buildQueryInfo( $offset, $limit, $order)
Build variables to use by the database wrapper.
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
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:2627
testUniqueSortOrderWithoutIpChanges()
\ContribsPager::getExtraSortFields \ContribsPager::getIndexField \ContribsPager::getQueryInfo ...
testQueryableRanges( $ipRange)
ContribsPager::isQueryableRange provideQueryableRanges.