wiki.techinc.nl/tests/phpunit/includes/logging/DatabaseLogEntryTest.php
Brad Jorsch 993baa3493 ActorMigration: Remove possibility of read-both
When this was originally written, the plan was to read both the old and
new fields during the transition period, while stopping writes to them
midway through. It turns out that the WHERE conditions to do read-both
correctly are generally not handled well by the database and working
around that would require a lot of complicated code (see what's being
removed from ApiQueryUserContribs here, for example).

We can simplify things greatly by instead having it write both fields
during the transition period, reading from the old for the first part
and the new for the second part, as is being done for MCR.

Bug: T204669
Change-Id: I4764c1c7883dc1003cb12729455c8107319f70b1
Depends-On: I845f6ae462f2539ebd35cbb5f2ca8b5714e2c1fb
Depends-On: I88b31b977543fdbdf69f8c1158e77e448df94e11
2018-10-11 12:12:00 +11:00

167 lines
4.3 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\IDatabase;
class DatabaseLogEntryTest extends MediaWikiTestCase {
public function setUp() {
parent::setUp();
// These services cache their joins
MediaWikiServices::getInstance()->resetServiceForTesting( 'CommentStore' );
MediaWikiServices::getInstance()->resetServiceForTesting( 'ActorMigration' );
}
public function tearDown() {
parent::tearDown();
MediaWikiServices::getInstance()->resetServiceForTesting( 'CommentStore' );
MediaWikiServices::getInstance()->resetServiceForTesting( 'ActorMigration' );
}
/**
* @covers DatabaseLogEntry::newFromId
* @covers DatabaseLogEntry::getSelectQueryData
*
* @dataProvider provideNewFromId
*
* @param int $id
* @param array $selectFields
* @param string[]|null $row
* @param string[]|null $expectedFields
* @param int $commentMigration
* @param int $actorMigration
*/
public function testNewFromId( $id,
array $selectFields,
array $row = null,
array $expectedFields = null,
$commentMigration,
$actorMigration
) {
$this->setMwGlobals( [
'wgCommentTableSchemaMigrationStage' => $commentMigration,
'wgActorTableSchemaMigrationStage' => $actorMigration,
] );
$row = $row ? (object)$row : null;
$db = $this->getMock( IDatabase::class );
$db->expects( self::once() )
->method( 'selectRow' )
->with( $selectFields['tables'],
$selectFields['fields'],
$selectFields['conds'],
'DatabaseLogEntry::newFromId',
$selectFields['options'],
$selectFields['join_conds']
)
->will( self::returnValue( $row ) );
/** @var IDatabase $db */
$logEntry = DatabaseLogEntry::newFromId( $id, $db );
if ( !$expectedFields ) {
self::assertNull( $logEntry, "Expected no log entry returned for id=$id" );
} else {
self::assertEquals( $id, $logEntry->getId() );
self::assertEquals( $expectedFields['type'], $logEntry->getType() );
self::assertEquals( $expectedFields['comment'], $logEntry->getComment() );
}
}
public function provideNewFromId() {
$oldTables = [
'tables' => [ 'logging', 'user' ],
'fields' => [
'log_id',
'log_type',
'log_action',
'log_timestamp',
'log_namespace',
'log_title',
'log_params',
'log_deleted',
'user_id',
'user_name',
'user_editcount',
'log_comment_text' => 'log_comment',
'log_comment_data' => 'NULL',
'log_comment_cid' => 'NULL',
'log_user' => 'log_user',
'log_user_text' => 'log_user_text',
'log_actor' => 'NULL',
],
'options' => [],
'join_conds' => [ 'user' => [ 'LEFT JOIN', 'user_id=log_user' ] ],
];
$newTables = [
'tables' => [
'logging',
'user',
'comment_log_comment' => 'comment',
'actor_log_user' => 'actor'
],
'fields' => [
'log_id',
'log_type',
'log_action',
'log_timestamp',
'log_namespace',
'log_title',
'log_params',
'log_deleted',
'user_id',
'user_name',
'user_editcount',
'log_comment_text' => 'comment_log_comment.comment_text',
'log_comment_data' => 'comment_log_comment.comment_data',
'log_comment_cid' => 'comment_log_comment.comment_id',
'log_user' => 'actor_log_user.actor_user',
'log_user_text' => 'actor_log_user.actor_name',
'log_actor' => 'log_actor',
],
'options' => [],
'join_conds' => [
'user' => [ 'LEFT JOIN', 'user_id=actor_log_user.actor_user' ],
'comment_log_comment' => [ 'JOIN', 'comment_log_comment.comment_id = log_comment_id' ],
'actor_log_user' => [ 'JOIN', 'actor_log_user.actor_id = log_actor' ],
],
];
return [
[
0,
$oldTables + [ 'conds' => [ 'log_id' => 0 ] ],
null,
null,
MIGRATION_OLD,
SCHEMA_COMPAT_OLD,
],
[
123,
$oldTables + [ 'conds' => [ 'log_id' => 123 ] ],
[
'log_id' => 123,
'log_type' => 'foobarize',
'log_comment_text' => 'test!',
'log_comment_data' => null,
],
[ 'type' => 'foobarize', 'comment' => 'test!' ],
MIGRATION_OLD,
SCHEMA_COMPAT_OLD,
],
[
567,
$newTables + [ 'conds' => [ 'log_id' => 567 ] ],
[
'log_id' => 567,
'log_type' => 'foobarize',
'log_comment_text' => 'test!',
'log_comment_data' => null,
],
[ 'type' => 'foobarize', 'comment' => 'test!' ],
MIGRATION_NEW,
SCHEMA_COMPAT_NEW,
],
];
}
}