| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Content\Content; |
| 22 |
use MediaWiki\EditPage\Constraint\ExistingSectionEditConstraint; |
| 23 |
use MediaWiki\EditPage\Constraint\IEditConstraint; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 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 |
} |