| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use ManualLogEntry; |
| 6 |
use MediaWiki\Linker\LinkTarget; |
| 7 |
use MediaWiki\Maintenance\FixAutoblockLogTitles; |
| 8 |
use MediaWiki\Title\TitleValue; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class FixAutoblockLogTitlesTest extends MaintenanceBaseTestCase { |
| 16 |
|
| 17 |
protected function getMaintenanceClass() { |
| 18 |
return FixAutoblockLogTitles::class; |
| 19 |
} |
| 20 |
|
| 21 |
public function testExecuteWhenNoMatchingLogs() { |
| 22 |
$this->maintenance->execute(); |
| 23 |
$this->expectOutputRegex( "/Fixing log entries with log_title starting with[\s\S]*done.\n$/" ); |
| 24 |
} |
| 25 |
|
| 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(); |
| 32 |
} |
| 33 |
|
| 34 |
public function testExecuteWhenMatchingLogs() { |
| 35 |
|
| 36 |
|
| 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 |
|
| 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" |
| 46 |
); |
| 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 |
] ); |
| 56 |
} |
| 57 |
} |