Debian Codegraph @

tests/phpunit/unit/includes/editpage/Constraint/SimpleAntiSpamConstraintTest.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\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 * Tests the SimpleAntiSpamConstraint
30 *
31 * @author DannyS712
32 *
33 * @covers \MediaWiki\EditPage\Constraint\SimpleAntiSpamConstraint
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 }