summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CheckUser/tests/phpunit/SpecialCheckUserTest.php')
-rw-r--r--CheckUser/tests/phpunit/SpecialCheckUserTest.php88
1 files changed, 83 insertions, 5 deletions
diff --git a/CheckUser/tests/phpunit/SpecialCheckUserTest.php b/CheckUser/tests/phpunit/SpecialCheckUserTest.php
index 8f456014..2f012efa 100644
--- a/CheckUser/tests/phpunit/SpecialCheckUserTest.php
+++ b/CheckUser/tests/phpunit/SpecialCheckUserTest.php
@@ -1,5 +1,11 @@
<?php
+namespace MediaWiki\CheckUser\Tests;
+
+use MediaWikiIntegrationTestCase;
+use ReflectionClass;
+use SpecialCheckUser;
+
/**
* Test class for SpecialCheckUser class
*
@@ -8,9 +14,19 @@
*
* @covers SpecialCheckUser
*/
-class SpecialCheckUserTest extends MediaWikiTestCase {
+class SpecialCheckUserTest extends MediaWikiIntegrationTestCase {
+
+ /**
+ * @var int
+ */
+ private $lowerThanLimitIPv4;
- function __construct( $name = null, array $data = [], $dataName = '' ) {
+ /**
+ * @var int
+ */
+ private $lowerThanLimitIPv6;
+
+ public function __construct( $name = null, array $data = [], $dataName = '' ) {
parent::__construct( $name, $data, $dataName );
$this->tablesUsed = array_merge(
@@ -29,7 +45,7 @@ class SpecialCheckUserTest extends MediaWikiTestCase {
);
}
- protected function setUp() {
+ protected function setUp() : void {
parent::setUp();
$this->setMwGlobals( [
@@ -38,6 +54,10 @@ class SpecialCheckUserTest extends MediaWikiTestCase {
'IPv6' => 19,
]
] );
+
+ $CIDRLimit = \RequestContext::getMain()->getConfig()->get( 'CheckUserCIDRLimit' );
+ $this->lowerThanLimitIPv4 = $CIDRLimit['IPv4'] - 1;
+ $this->lowerThanLimitIPv6 = $CIDRLimit['IPv6'] - 1;
}
/**
@@ -76,8 +96,66 @@ class SpecialCheckUserTest extends MediaWikiTestCase {
[ 0 => 'cuc_ip_hex BETWEEN \'v6-00000000000000000000000E00000000\'' .
' AND \'v6-00000000000000000000000EFFFFFFFF\'' ],
],
- [ '0.17.184.5/15', false ],
- [ '2000::/16', false ],
+ [ "0.17.184.5/{$this->lowerThanLimitIPv4}", false ],
+ [ "2000::/{$this->lowerThanLimitIPv6}", false ],
+ ];
+ }
+
+ /**
+ * @covers SpecialCheckUser::isValidRange
+ * @dataProvider provideIsValidRange
+ */
+ public function testIsValidRange( $target, $expected ) {
+ $this->assertEquals(
+ $expected,
+ SpecialCheckUser::isValidRange( $target )
+ );
+ }
+
+ /**
+ * Test cases for SpecialCheckUser::isValid
+ * @return array
+ */
+ public function provideIsValidRange() {
+ return [
+ [ '212.35.31.121', true ],
+ [ '212.35.31.121/32', true ],
+ [ '::e:f:2001', true ],
+ [ '::e:f:2001/96', true ],
+ [ "0.17.184.5/{$this->lowerThanLimitIPv4}", false ],
+ [ "2000::/{$this->lowerThanLimitIPv6}", false ]
+ ];
+ }
+
+ /**
+ * @covers SpecialCheckUser::checkReason
+ * @dataProvider provideCheckReason
+ */
+ public function testCheckReason( $config, $reason, $expected ) {
+ $this->setMwGlobals( 'wgCheckUserForceSummary', $config );
+ $class = new ReflectionClass( SpecialCheckUser::class );
+ $method = $class->getMethod( 'checkReason' );
+ $method->setAccessible( true );
+ $instance = $class->newInstanceWithoutConstructor();
+ $property = $class->getProperty( 'reason' );
+ $property->setAccessible( true );
+ $property->setValue( $instance, $reason );
+ $this->assertEquals(
+ $expected,
+ $method->invoke( $instance )
+ );
+ }
+
+ /**
+ * Test cases for SpecialCheckUser::checkReason
+ * @return array
+ */
+ public function provideCheckReason() {
+ return [
+ [ false, '', true ],
+ [ false, 'Test Reason', true ],
+ [ true, '', false ],
+ [ true, 'Test Reason', true ]
];
}
}