| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace MediaWiki\Tests\Unit\Permissions; |
| 23 |
|
| 24 |
use MediaWiki\Permissions\RateLimitSubject; |
| 25 |
use MediaWiki\User\UserIdentityValue; |
| 26 |
use MediaWikiUnitTestCase; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class RateLimitSubjectTest extends MediaWikiUnitTestCase { |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public static function provideIp(): array { |
| 38 |
return [ |
| 39 |
'null' => [ null, true ], |
| 40 |
'empty' => [ '', true ], |
| 41 |
'ipv4' => [ '10.0.0.1', true ], |
| 42 |
'ipv6' => [ '2001:db8:1::', true ], |
| 43 |
]; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function testConstructorAndGetters( $ip, $expected ) { |
| 52 |
$actor = new UserIdentityValue( 12, 'Test' ); |
| 53 |
$flags = [ 'foo' => true, 'bar' => false ]; |
| 54 |
|
| 55 |
$subject = new RateLimitSubject( $actor, $ip, $flags ); |
| 56 |
$this->assertInstanceOf( RateLimitSubject::class, $subject ); |
| 57 |
|
| 58 |
$this->assertSame( $actor, $subject->getUser(), 'The getUser method did not return the expected actor.' ); |
| 59 |
$this->assertSame( $expected ? $ip : null, $subject->getIp(), |
| 60 |
'The getIp method did not return the expected IP.' ); |
| 61 |
$this->assertTrue( $subject->is( 'foo' ), 'The is method did not return true for flag "foo".' ); |
| 62 |
$this->assertFalse( $subject->is( 'bar' ), 'The is method did not return false for flag "bar".' ); |
| 63 |
$this->assertFalse( $subject->is( 'baz' ), |
| 64 |
'The is method returned true for an undefined flag "baz", expected false.' ); |
| 65 |
} |
| 66 |
|
| 67 |
} |