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 int $actorMigration
34 public function testNewFromId( $id,
37 array $expectedFields = null,
40 $this->setMwGlobals( [
41 'wgActorTableSchemaMigrationStage' => $actorMigration,
44 $row = $row ?
(object)$row : null;
45 $db = $this->getMock( IDatabase
::class );
46 $db->expects( self
::once() )
47 ->method( 'selectRow' )
48 ->with( $selectFields['tables'],
49 $selectFields['fields'],
50 $selectFields['conds'],
51 'DatabaseLogEntry::newFromId',
52 $selectFields['options'],
53 $selectFields['join_conds']
55 ->will( self
::returnValue( $row ) );
57 /** @var IDatabase $db */
58 $logEntry = DatabaseLogEntry
::newFromId( $id, $db );
60 if ( !$expectedFields ) {
61 self
::assertNull( $logEntry, "Expected no log entry returned for id=$id" );
63 self
::assertEquals( $id, $logEntry->getId() );
64 self
::assertEquals( $expectedFields['type'], $logEntry->getType() );
65 self
::assertEquals( $expectedFields['comment'], $logEntry->getComment() );
69 public function provideNewFromId() {
73 'comment_log_comment' => 'comment',
87 'log_comment_text' => 'comment_log_comment.comment_text',
88 'log_comment_data' => 'comment_log_comment.comment_data',
89 'log_comment_cid' => 'comment_log_comment.comment_id',
90 'log_user' => 'log_user',
91 'log_user_text' => 'log_user_text',
92 'log_actor' => 'NULL',
96 'user' => [ 'LEFT JOIN', 'user_id=log_user' ],
97 'comment_log_comment' => [ 'JOIN', 'comment_log_comment.comment_id = log_comment_id' ],
104 'comment_log_comment' => 'comment',
105 'actor_log_user' => 'actor'
119 'log_comment_text' => 'comment_log_comment.comment_text',
120 'log_comment_data' => 'comment_log_comment.comment_data',
121 'log_comment_cid' => 'comment_log_comment.comment_id',
122 'log_user' => 'actor_log_user.actor_user',
123 'log_user_text' => 'actor_log_user.actor_name',
124 'log_actor' => 'log_actor',
128 'user' => [ 'LEFT JOIN', 'user_id=actor_log_user.actor_user' ],
129 'comment_log_comment' => [ 'JOIN', 'comment_log_comment.comment_id = log_comment_id' ],
130 'actor_log_user' => [ 'JOIN', 'actor_log_user.actor_id = log_actor' ],
136 $oldTables +
[ 'conds' => [ 'log_id' => 0 ] ],
143 $oldTables +
[ 'conds' => [ 'log_id' => 123 ] ],
146 'log_type' => 'foobarize',
147 'log_comment_text' => 'test!',
148 'log_comment_data' => null,
150 [ 'type' => 'foobarize', 'comment' => 'test!' ],
155 $newTables +
[ 'conds' => [ 'log_id' => 567 ] ],
158 'log_type' => 'foobarize',
159 'log_comment_text' => 'test!',
160 'log_comment_data' => null,
162 [ 'type' => 'foobarize', 'comment' => 'test!' ],