Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / specialpage / ContributionsRangeTraitTest.php
bloba8deeb4720db7f4da1b9d2f86a1de8864a46aa61
1 <?php
3 namespace MediaWiki\Tests\SpecialPage;
5 use MediaWiki\Config\HashConfig;
6 use MediaWiki\MainConfigNames;
7 use MediaWiki\SpecialPage\ContributionsRangeTrait;
8 use MediaWikiIntegrationTestCase;
9 use Wikimedia\TestingAccessWrapper;
11 /**
12 * @covers \MediaWiki\SpecialPage\ContributionsRangeTrait
14 class ContributionsRangeTraitTest extends MediaWikiIntegrationTestCase {
16 private function getConfig() {
17 return new HashConfig( [
18 MainConfigNames::RangeContributionsCIDRLimit => [
19 'IPv4' => 16,
20 'IPv6' => 32,
22 ] );
25 private function getWrappedTrait() {
26 return TestingAccessWrapper::newFromObject(
27 $this->getMockForTrait( ContributionsRangeTrait::class )
31 /**
32 * @dataProvider provideQueryableRanges
34 public function testIsQueryableRange( $ipRange ) {
35 $this->assertTrue(
36 $this->getWrappedTrait()->isQueryableRange( $ipRange, $this->getConfig() ),
40 public static function provideQueryableRanges() {
41 return [
42 [ '116.17.184.5/32' ],
43 [ '0.17.184.5/16' ],
44 [ '2000::/32' ],
45 [ '2001:db8::/128' ],
49 /**
50 * @dataProvider provideUnqueryableRanges
52 public function testUnqueryableRanges( $ipRange ) {
53 $this->assertFalse(
54 $this->getWrappedTrait()->isQueryableRange( $ipRange, $this->getConfig() ),
58 public static function provideUnqueryableRanges() {
59 return [
60 [ '116.17.184.5/33' ],
61 [ '0.17.184.5/15' ],
62 [ '2000::/31' ],
63 [ '2001:db8::/9999' ],
64 [ '2001:db8::' ],
65 [ '0.17.184.5' ],
66 [ 'test' ],
70 /**
71 * @dataProvider provideValidIPOrQueryableRanges
73 public function testIsValidIPOrQueryableRange( $ip ) {
74 $this->assertTrue(
75 $this->getWrappedTrait()->isValidIPOrQueryableRange( $ip, $this->getConfig() ),
79 public static function provideValidIPOrQueryableRanges() {
80 return [
81 [ '0.17.184.5/16' ],
82 [ '0.17.184.5' ],
83 [ '2000::/32' ],
84 [ '2000::' ],
88 /**
89 * @dataProvider provideInvalidIPOrUnqueryableRanges
91 public function testInvalidIPOrUnqueryableRanges( $ip ) {
92 $this->assertFalse(
93 $this->getWrappedTrait()->isValidIPOrQueryableRange( $ip, $this->getConfig() ),
97 public static function provideInvalidIPOrUnqueryableRanges() {
98 return [
99 [ '0.17.184.5/15' ],
100 [ '2000::/31' ],
101 [ 'test' ],
105 public function testGetQueryableRangeLimit() {
106 $limit = [
107 'IPv4' => 16,
108 'IPv6' => 32,
111 $config = new HashConfig( [
112 MainConfigNames::RangeContributionsCIDRLimit => $limit
113 ] );
115 $this->assertSame( $limit, $this->getWrappedTrait()->getQueryableRangeLimit( $config ) );