Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / FixAutoblockLogTitlesTest.php
bloba48a621156c74b0b214f7c202e1a99fb39c541c2
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use ManualLogEntry;
6 use MediaWiki\Linker\LinkTarget;
7 use MediaWiki\Maintenance\FixAutoblockLogTitles;
8 use MediaWiki\Title\TitleValue;
10 /**
11 * @covers \MediaWiki\Maintenance\FixAutoblockLogTitles
12 * @group Database
13 * @author Dreamy Jazz
15 class FixAutoblockLogTitlesTest extends MaintenanceBaseTestCase {
17 protected function getMaintenanceClass() {
18 return FixAutoblockLogTitles::class;
21 public function testExecuteWhenNoMatchingLogs() {
22 $this->maintenance->execute();
23 $this->expectOutputRegex( "/Fixing log entries with log_title starting with[\s\S]*done.\n$/" );
26 private function getBlockTypeEntry( string $subtype, LinkTarget $target, int $blockId ): int {
27 $logEntry = new ManualLogEntry( 'block', $subtype );
28 $logEntry->setTarget( $target );
29 $logEntry->setPerformer( $this->getTestSysop()->getUser() );
30 $logEntry->setRelations( [ 'ipb_id' => $blockId ] );
31 return $logEntry->insert();
34 public function testExecuteWhenMatchingLogs() {
35 // Get three "block" type log entries, where two have the unblock subtype and one of those two has a invalid
36 // title.
37 $brokenId = $this->getBlockTypeEntry( 'unblock', TitleValue::tryNew( NS_USER, 'User:#1234' ), 1234 );
38 $notBrokenId = $this->getBlockTypeEntry( 'unblock', TitleValue::tryNew( NS_USER, '#1236' ), 1236 );
39 $notRelevantId = $this->getBlockTypeEntry( 'block', TitleValue::tryNew( NS_USER, 'Abc' ), 1238 );
40 // Run the maintenance script and then check that only the $brokenId log entry was updated.
41 $this->maintenance->execute();
42 $this->expectOutputString(
43 "Fixing log entries with log_title starting with 'User:#'\n" .
44 "...Processing unblock rows with IDs $brokenId to $notBrokenId\n" .
45 "done. Fixed 1 rows.\n"
47 $this->newSelectQueryBuilder()
48 ->select( [ 'log_id', 'log_title' ] )
49 ->from( 'logging' )
50 ->orderBy( 'log_id' )
51 ->assertResultSet( [
52 [ $brokenId, '#1234' ],
53 [ $notBrokenId, '#1236' ],
54 [ $notRelevantId, 'Abc' ],
55 ] );