X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fspecials%2FContribsPagerTest.php;h=9366282fa8670a70a96527c68179cbc76342fb90;hp=d7fc13d11628c8f2449da3b808b175a0b6810604;hb=1d7a1bf8bddf0908e4f572c82268733f63126a13;hpb=b95ca29602793f39191c06cd6941e3f32ab1bbb8 diff --git a/tests/phpunit/includes/specials/ContribsPagerTest.php b/tests/phpunit/includes/specials/ContribsPagerTest.php index d7fc13d116..9366282fa8 100644 --- a/tests/phpunit/includes/specials/ContribsPagerTest.php +++ b/tests/phpunit/includes/specials/ContribsPagerTest.php @@ -3,7 +3,20 @@ /** * @group Database */ -class ContribsPagerTest extends \PHPUnit_Framework_TestCase { +class ContribsPagerTest extends MediaWikiTestCase { + /** @var ContribsPager */ + private $pager; + + function setUp() { + $context = new RequestContext(); + $this->pager = new ContribsPager( $context, [ + 'start' => '2017-01-01', + 'end' => '2017-02-02', + ] ); + + parent::setUp(); + } + /** * @dataProvider dateFilterOptionProcessingProvider * @param array $inputOpts Input options @@ -47,4 +60,58 @@ class ContribsPagerTest extends \PHPUnit_Framework_TestCase { 'end' => '2012-12-31' ] ], ]; } + + /** + * @covers ContribsPager::isQueryableRange + * @dataProvider provideQueryableRanges + */ + public function testQueryableRanges( $ipRange ) { + $this->setMwGlobals( [ + 'wgRangeContributionsCIDRLimit' => [ + 'IPv4' => 16, + 'IPv6' => 32, + ], + ] ); + + $this->assertTrue( + $this->pager->isQueryableRange( $ipRange ), + "$ipRange is a queryable IP range" + ); + } + + public function provideQueryableRanges() { + return [ + [ '116.17.184.5/32' ], + [ '0.17.184.5/16' ], + [ '2000::/32' ], + [ '2001:db8::/128' ], + ]; + } + + /** + * @covers ContribsPager::isQueryableRange + * @dataProvider provideUnqueryableRanges + */ + public function testUnqueryableRanges( $ipRange ) { + $this->setMwGlobals( [ + 'wgRangeContributionsCIDRLimit' => [ + 'IPv4' => 16, + 'IPv6' => 32, + ], + ] ); + + $this->assertFalse( + $this->pager->isQueryableRange( $ipRange ), + "$ipRange is not a queryable IP range" + ); + } + + public function provideUnqueryableRanges() { + return [ + [ '116.17.184.5/33' ], + [ '0.17.184.5/15' ], + [ '2000::/31' ], + [ '2001:db8::/9999' ], + ]; + } }