Debian Codegraph @

tests/phpunit/unit/includes/editpage/Constraint/SelfRedirectConstraintTest.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\SelfRedirectConstraint;
24 use MediaWiki\Title\Title;
25
26 /**
27 * Tests the SelfRedirectConstraint
28 *
29 * @author DannyS712
30 *
31 * @covers \MediaWiki\EditPage\Constraint\SelfRedirectConstraint
32 */
33 class SelfRedirectConstraintTest extends MediaWikiUnitTestCase {
34 use EditConstraintTestTrait;
35
36 private function getContent( $title, $isSelfRedirect ) {
37 $content = $this->createMock( Content::class );
38 $contentRedirectTarget = $this->createMock( Title::class );
39 // No $this->once() since only called for the new content
40 $content->method( 'isRedirect' )
41 ->willReturn( true );
42 $content->expects( $this->once() )
43 ->method( 'getRedirectTarget' )
44 ->willReturn( $contentRedirectTarget );
45 $contentRedirectTarget->expects( $this->once() )
46 ->method( 'equals' )
47 ->with( $title )
48 ->willReturn( $isSelfRedirect );
49 return $content;
50 }
51
52 public function testPass() {
53 // New content is a self redirect, but so is existing content, so no warning
54 $title = $this->createMock( Title::class );
55 $constraint = new SelfRedirectConstraint(
56 false, // $allowSelfRedirect
57 $this->getContent( $title, true ),
58 $this->getContent( $title, true ),
59 $title
60 );
61 $this->assertConstraintPassed( $constraint );
62 }
63
64 public function testFailure() {
65 // New content is a self redirect, but existing content is not
66 $title = $this->createMock( Title::class );
67 $constraint = new SelfRedirectConstraint(
68 false, // $allowSelfRedirect
69 $this->getContent( $title, true ),
70 $this->getContent( $title, false ),
71 $title
72 );
73 $this->assertConstraintFailed(
74 $constraint,
75 IEditConstraint::AS_SELF_REDIRECT
76 );
77 }
78
79 }