| 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\IEditConstraint; |
| 22 |
use MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint; |
| 23 |
use MediaWiki\Title\Title; |
| 24 |
use MediaWiki\User\UserIdentityValue; |
| 25 |
use Psr\Log\LogLevel; |
| 26 |
use Psr\Log\NullLogger; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class SimpleAntiSpamConstraintTest extends MediaWikiUnitTestCase { |
| 36 |
use EditConstraintTestTrait; |
| 37 |
|
| 38 |
public function testPass() { |
| 39 |
$logger = new NullLogger(); |
| 40 |
$user = new UserIdentityValue( 5, 'UserNameGoesHere' ); |
| 41 |
$title = $this->createMock( Title::class ); |
| 42 |
|
| 43 |
$constraint = new SimpleAntiSpamConstraint( |
| 44 |
$logger, |
| 45 |
'', |
| 46 |
$user, |
| 47 |
$title |
| 48 |
); |
| 49 |
$this->assertConstraintPassed( $constraint ); |
| 50 |
} |
| 51 |
|
| 52 |
public function testFailure() { |
| 53 |
$logger = new TestLogger( true ); |
| 54 |
$user = new UserIdentityValue( 5, 'UserNameGoesHere' ); |
| 55 |
$title = $this->createMock( Title::class ); |
| 56 |
$title->expects( $this->once() ) |
| 57 |
->method( 'getPrefixedText' ) |
| 58 |
->willReturn( 'TitlePrefixedTextGoesHere' ); |
| 59 |
|
| 60 |
$constraint = new SimpleAntiSpamConstraint( |
| 61 |
$logger, |
| 62 |
'SpamContent', |
| 63 |
$user, |
| 64 |
$title |
| 65 |
); |
| 66 |
$this->assertConstraintFailed( $constraint, IEditConstraint::AS_SPAM_ERROR ); |
| 67 |
|
| 68 |
$this->assertSame( [ |
| 69 |
[ |
| 70 |
LogLevel::DEBUG, |
| 71 |
'{name} editing "{title}" submitted bogus field "{input}"' |
| 72 |
], |
| 73 |
], $logger->getBuffer() ); |
| 74 |
$logger->clearBuffer(); |
| 75 |
} |
| 76 |
|
| 77 |
} |