Debian Codegraph @

extensions/AbuseFilter/tests/phpunit/integration/AbuseLoggerTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\AbuseFilter\Tests\Integration;
4
5 use MediaWiki\Deferred\DeferredUpdates;
6 use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
7 use MediaWiki\Extension\AbuseFilter\Variables\VariableHolder;
8 use MediaWikiIntegrationTestCase;
9
10 /**
11 * @covers \MediaWiki\Extension\AbuseFilter\AbuseLogger
12 * @group Database
13 */
14 class AbuseLoggerTest extends MediaWikiIntegrationTestCase {
15 /**
16 * Tests that the AbuseFilter logs are sent to CheckUser, and that CheckUser actually inserts the row to the
17 * cu_private_event table.
18 */
19 public function testSendingLogsToCheckUser() {
20 $this->markTestSkippedIfExtensionNotLoaded( 'CheckUser' );
21 AbuseFilterServices::getAbuseLoggerFactory()->newLogger(
22 $this->getExistingTestPage()->getTitle(),
23 $this->getTestUser()->getUser(),
24 VariableHolder::newFromArray( [ 'action' => 'edit' ] )
25 )->addLogEntries( [ 1 => [ 'warn' ] ] );
26 // Sending the log to CheckUser happens on a DeferredUpdate, so we need to run the updates.
27 DeferredUpdates::doUpdates();
28 // Assert that an insert into the cu_private_event table occurred for the abusefilter hit.
29 // This may be a bit brittle if the cu_private_event table schema changes, but as AbuseFilter is
30 // a dependency of CheckUser in CI and the columns checked are unlikely to change, this is acceptable.
31 $this->assertSame(
32 1,
33 (int)$this->getDb()->newSelectQueryBuilder()
34 ->select( 'COUNT(*)' )
35 ->from( 'cu_private_event' )
36 ->where( [ 'cupe_log_type' => 'abusefilter', 'cupe_log_action' => 'hit' ] )
37 ->fetchField()
38 );
39 }
40 }