Debian Codegraph @

tests/phpunit/unit/includes/editpage/Constraint/ExistingSectionEditConstraintTest.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\ExistingSectionEditConstraint;
23 use MediaWiki\EditPage\Constraint\IEditConstraint;
24
25 /**
26 * Tests the ExistingSectionEditConstraint
27 *
28 * @author DannyS712
29 *
30 * @covers \MediaWiki\EditPage\Constraint\ExistingSectionEditConstraint
31 */
32 class ExistingSectionEditConstraintTest extends MediaWikiUnitTestCase {
33 use EditConstraintTestTrait;
34
35 public function testPass() {
36 $originalContent = $this->createMock( Content::class );
37 $newContent = $this->createMock( Content::class );
38 $newContent->expects( $this->once() )
39 ->method( 'equals' )
40 ->with( $originalContent )
41 ->willReturn( false );
42 $newContent->expects( $this->once() )
43 ->method( 'isRedirect' )
44 ->willReturn( false );
45 $constraint = new ExistingSectionEditConstraint(
46 'notnew',
47 'UserSummary',
48 'AutoSummary',
49 false,
50 $newContent,
51 $originalContent
52 );
53 $this->assertConstraintPassed( $constraint );
54 }
55
56 public function testPass_newSection() {
57 $constraint = new ExistingSectionEditConstraint(
58 'new',
59 'UserSummary',
60 md5( 'UserSummary' ),
61 false,
62 $this->createNoOpMock( Content::class ),
63 null
64 );
65 $this->assertConstraintPassed( $constraint );
66 }
67
68 public function testFailure_autoSummary() {
69 $originalContent = $this->createMock( Content::class );
70 $newContent = $this->createMock( Content::class );
71 $newContent->expects( $this->once() )
72 ->method( 'equals' )
73 ->with( $originalContent )
74 ->willReturn( false );
75 $newContent->expects( $this->once() )
76 ->method( 'isRedirect' )
77 ->willReturn( false );
78 $constraint = new ExistingSectionEditConstraint(
79 'notnew',
80 'UserSummary',
81 md5( 'UserSummary' ),
82 false,
83 $newContent,
84 $originalContent
85 );
86 $this->assertConstraintFailed( $constraint, IEditConstraint::AS_SUMMARY_NEEDED );
87 }
88
89 public function testFailure_revisionDeleted() {
90 $constraint = new ExistingSectionEditConstraint(
91 'notnew',
92 'UserSummary',
93 md5( 'UserSummary' ),
94 false,
95 $this->createNoOpMock( Content::class ),
96 null
97 );
98 $this->assertConstraintFailed( $constraint, IEditConstraint::AS_REVISION_WAS_DELETED );
99 }
100
101 }