3 use MediaWiki\MediaWikiServices
;
4 use Wikimedia\Rdbms\IDatabase
;
6 class DatabaseLogEntryTest
extends MediaWikiTestCase
{
7 public function setUp() {
10 // These services cache their joins
11 MediaWikiServices
::getInstance()->resetServiceForTesting( 'CommentStore' );
12 MediaWikiServices
::getInstance()->resetServiceForTesting( 'ActorMigration' );
15 public function tearDown() {
18 MediaWikiServices
::getInstance()->resetServiceForTesting( 'CommentStore' );
19 MediaWikiServices
::getInstance()->resetServiceForTesting( 'ActorMigration' );
23 * @covers DatabaseLogEntry::newFromId
24 * @covers DatabaseLogEntry::getSelectQueryData
26 * @dataProvider provideNewFromId
29 * @param array $selectFields
30 * @param string[]|null $row
31 * @param string[]|null $expectedFields
32 * @param string $migration
34 public function testNewFromId( $id,
37 array $expectedFields = null,
40 $this->setMwGlobals( [
41 'wgCommentTableSchemaMigrationStage' => $migration,
42 'wgActorTableSchemaMigrationStage' => $migration,
45 $row = $row ?
(object)$row : null;
46 $db = $this->getMock( IDatabase
::class );
47 $db->expects( self
::once() )
48 ->method( 'selectRow' )
49 ->with( $selectFields['tables'],
50 $selectFields['fields'],
51 $selectFields['conds'],
52 'DatabaseLogEntry::newFromId',
53 $selectFields['options'],
54 $selectFields['join_conds']
56 ->will( self
::returnValue( $row ) );
58 /** @var IDatabase $db */
59 $logEntry = DatabaseLogEntry
::newFromId( $id, $db );
61 if ( !$expectedFields ) {
62 self
::assertNull( $logEntry, "Expected no log entry returned for id=$id" );
64 self
::assertEquals( $id, $logEntry->getId() );
65 self
::assertEquals( $expectedFields['type'], $logEntry->getType() );
66 self
::assertEquals( $expectedFields['comment'], $logEntry->getComment() );
70 public function provideNewFromId() {
72 'tables' => [ 'logging', 'user' ],
85 'log_comment_text' => 'log_comment',
86 'log_comment_data' => 'NULL',
87 'log_comment_cid' => 'NULL',
88 'log_user' => 'log_user',
89 'log_user_text' => 'log_user_text',
90 'log_actor' => 'NULL',
93 'join_conds' => [ 'user' => [ 'LEFT JOIN', 'user_id=log_user' ] ],
99 'comment_log_comment' => 'comment',
100 'actor_log_user' => 'actor'
114 'log_comment_text' => 'comment_log_comment.comment_text',
115 'log_comment_data' => 'comment_log_comment.comment_data',
116 'log_comment_cid' => 'comment_log_comment.comment_id',
117 'log_user' => 'actor_log_user.actor_user',
118 'log_user_text' => 'actor_log_user.actor_name',
119 'log_actor' => 'log_actor',
123 'user' => [ 'LEFT JOIN', 'user_id=actor_log_user.actor_user' ],
124 'comment_log_comment' => [ 'JOIN', 'comment_log_comment.comment_id = log_comment_id' ],
125 'actor_log_user' => [ 'JOIN', 'actor_log_user.actor_id = log_actor' ],
131 $oldTables +
[ 'conds' => [ 'log_id' => 0 ] ],
138 $oldTables +
[ 'conds' => [ 'log_id' => 123 ] ],
141 'log_type' => 'foobarize',
142 'log_comment_text' => 'test!',
143 'log_comment_data' => null,
145 [ 'type' => 'foobarize', 'comment' => 'test!' ],
150 $newTables +
[ 'conds' => [ 'log_id' => 567 ] ],
153 'log_type' => 'foobarize',
154 'log_comment_text' => 'test!',
155 'log_comment_data' => null,
157 [ 'type' => 'foobarize', 'comment' => 'test!' ],