Debian Codegraph @

tests/phpunit/unit/includes/editpage/Constraint/ImageRedirectConstraintTest.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
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 * Tests the ImageRedirectConstraint
30 *
31 * @author DannyS712
32 *
33 * @covers \MediaWiki\EditPage\Constraint\ImageRedirectConstraint
34 */
35 class ImageRedirectConstraintTest extends MediaWikiUnitTestCase {
36 use EditConstraintTestTrait;
37 use MockAuthorityTrait;
38
39 /**
40 * @param Authority $performer
41 * @return ImageRedirectConstraint
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 * @dataProvider provideTestFailure
64 * @param Authority $performer
65 * @param int $expectedValue
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 }