| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\EditPage\Constraint\DefaultTextConstraint; |
| 22 |
use MediaWiki\EditPage\Constraint\IEditConstraint; |
| 23 |
use MediaWiki\Title\Title; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 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, |
| 46 |
'User provided text goes here' |
| 47 |
); |
| 48 |
$this->assertConstraintPassed( $constraint ); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public function testFailure( $defaultText, $userInput ) { |
| 57 |
$constraint = new DefaultTextConstraint( |
| 58 |
$this->getTitle( $defaultText ), |
| 59 |
false, |
| 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 |
} |