Debian Codegraph @

tests/phpunit/unit/includes/editpage/Constraint/DefaultTextConstraintTest.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\EditPage\Constraint\DefaultTextConstraint;
22 use MediaWiki\EditPage\Constraint\IEditConstraint;
23 use MediaWiki\Title\Title;
24
25 /**
26 * Tests the DefaultTextConstraint
27 *
28 * @author DannyS712
29 *
30 * @covers \MediaWiki\EditPage\Constraint\DefaultTextConstraint
31 */
32 class DefaultTextConstraintTest extends MediaWikiUnitTestCase {
33 use EditConstraintTestTrait;
34
35 private function getTitle( $defaultText ) {
36 $title = $this->createMock( Title::class );
37 $title->method( 'getNamespace' )->willReturn( NS_MEDIAWIKI );
38 $title->method( 'getDefaultMessageText' )->willReturn( $defaultText );
39 return $title;
40 }
41
42 public function testPass() {
43 $constraint = new DefaultTextConstraint(
44 $this->getTitle( 'DefaultMessageTextGoesHere' ),
45 false, // Allow blank
46 'User provided text goes here'
47 );
48 $this->assertConstraintPassed( $constraint );
49 }
50
51 /**
52 * @dataProvider provideTestFailure
53 * @param string|bool $defaultText
54 * @param string $userInput
55 */
56 public function testFailure( $defaultText, $userInput ) {
57 $constraint = new DefaultTextConstraint(
58 $this->getTitle( $defaultText ),
59 false, // Allow blank
60 $userInput
61 );
62 $this->assertConstraintFailed( $constraint, IEditConstraint::AS_BLANK_ARTICLE );
63 }
64
65 public static function provideTestFailure() {
66 yield 'Matching message text' => [ 'MessageText', 'MessageText' ];
67 yield 'Blank page and no default' => [ false, '' ];
68 }
69
70 }