| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Content\Content; |
| 22 |
use MediaWiki\EditPage\Constraint\IEditConstraint; |
| 23 |
use MediaWiki\EditPage\Constraint\ImageRedirectConstraint; |
| 24 |
use MediaWiki\Permissions\Authority; |
| 25 |
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait; |
| 26 |
use MediaWiki\Title\Title; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class ImageRedirectConstraintTest extends MediaWikiUnitTestCase { |
| 36 |
use EditConstraintTestTrait; |
| 37 |
use MockAuthorityTrait; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
private function getConstraint( Authority $performer ) { |
| 44 |
$content = $this->createMock( Content::class ); |
| 45 |
$content->method( 'isRedirect' )->willReturn( true ); |
| 46 |
|
| 47 |
$title = $this->createMock( Title::class ); |
| 48 |
$title->method( 'getNamespace' )->willReturn( NS_FILE ); |
| 49 |
|
| 50 |
return new ImageRedirectConstraint( |
| 51 |
$content, |
| 52 |
$title, |
| 53 |
$performer |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
public function testPass() { |
| 58 |
$constraint = $this->getConstraint( $this->mockRegisteredUltimateAuthority() ); |
| 59 |
$this->assertConstraintPassed( $constraint ); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public function testFailure( Authority $performer, int $expectedValue ) { |
| 68 |
$constraint = $this->getConstraint( $performer ); |
| 69 |
$this->assertConstraintFailed( $constraint, $expectedValue ); |
| 70 |
} |
| 71 |
|
| 72 |
public function provideTestFailure() { |
| 73 |
yield 'Anonymous user' => [ |
| 74 |
'performer' => $this->mockAnonAuthorityWithoutPermissions( [ 'upload' ] ), |
| 75 |
'expectedValue' => IEditConstraint::AS_IMAGE_REDIRECT_ANON |
| 76 |
]; |
| 77 |
yield 'Registered user' => [ |
| 78 |
'performer' => $this->mockRegisteredAuthorityWithoutPermissions( [ 'upload' ] ), |
| 79 |
'expectedValue' => IEditConstraint::AS_IMAGE_REDIRECT_LOGGED |
| 80 |
]; |
| 81 |
} |
| 82 |
|
| 83 |
} |