3 use MediaWiki\User\ActorStore
;
4 use MediaWiki\User\UserIdentity
;
5 use MediaWiki\User\UserIdentityValue
;
6 use Wikimedia\Rdbms\IReadableDatabase
;
11 class DatabaseLogEntryTest
extends MediaWikiIntegrationTestCase
{
14 * @covers \DatabaseLogEntry::newFromId
15 * @covers \DatabaseLogEntry::getSelectQueryData
17 * @dataProvider provideNewFromId
20 * @param array $selectFields
21 * @param string[]|null $row
22 * @param string[]|null $expectedFields
24 public function testNewFromId( $id,
27 ?
array $expectedFields = null
29 $row = $row ?
(object)$row : null;
30 $db = $this->createMock( IReadableDatabase
::class );
31 $db->expects( self
::once() )
32 ->method( 'selectRow' )
33 ->with( $selectFields['tables'],
34 $selectFields['fields'],
35 $selectFields['conds'],
36 'DatabaseLogEntry::newFromId',
37 $selectFields['options'],
38 $selectFields['join_conds']
40 ->will( self
::returnValue( $row ) );
42 /** @var IReadableDatabase $db */
43 $logEntry = DatabaseLogEntry
::newFromId( $id, $db );
45 if ( !$expectedFields ) {
46 self
::assertNull( $logEntry, "Expected no log entry returned for id=$id" );
48 self
::assertEquals( $id, $logEntry->getId() );
49 self
::assertEquals( $expectedFields['type'], $logEntry->getType() );
50 self
::assertEquals( $expectedFields['comment'], $logEntry->getComment() );
54 public static function provideNewFromId() {
58 'comment_log_comment' => 'comment',
59 'logging_actor' => 'actor',
73 'log_comment_text' => 'comment_log_comment.comment_text',
74 'log_comment_data' => 'comment_log_comment.comment_data',
75 'log_comment_cid' => 'comment_log_comment.comment_id',
76 'log_user' => 'logging_actor.actor_user',
77 'log_user_text' => 'logging_actor.actor_name',
82 'user' => [ 'LEFT JOIN', 'user_id=logging_actor.actor_user' ],
83 'comment_log_comment' => [ 'JOIN', 'comment_log_comment.comment_id = log_comment_id' ],
84 'logging_actor' => [ 'JOIN', 'actor_id=log_actor' ],
90 $newTables +
[ 'conds' => [ 'log_id' => 0 ] ],
96 $newTables +
[ 'conds' => [ 'log_id' => 123 ] ],
99 'log_type' => 'foobarize',
100 'log_comment_text' => 'test!',
101 'log_comment_data' => null,
103 [ 'type' => 'foobarize', 'comment' => 'test!' ]
107 $newTables +
[ 'conds' => [ 'log_id' => 567 ] ],
110 'log_type' => 'foobarize',
111 'log_comment_text' => 'test!',
112 'log_comment_data' => null,
114 [ 'type' => 'foobarize', 'comment' => 'test!' ]
119 public static function provideGetPerformerIdentity() {
120 yield
'registered actor' => [
121 'actor_row_fields' => [
123 'log_user_text' => 'Testing',
126 UserIdentityValue
::newRegistered( 42, 'Testing' ),
128 yield
'anon actor' => [
129 'actor_row_fields' => [
130 'log_user_text' => '127.0.0.1',
133 UserIdentityValue
::newAnonymous( '127.0.0.1' ),
135 yield
'unknown actor' => [
136 'actor_row_fields' => [],
137 new UserIdentityValue( 0, ActorStore
::UNKNOWN_USER_NAME
),
142 * @dataProvider provideGetPerformerIdentity
143 * @covers \DatabaseLogEntry::getPerformerIdentity
145 public function testGetPerformer( array $actorRowFields, UserIdentity
$expected ) {
146 $logEntry = DatabaseLogEntry
::newFromRow( [
148 ] +
$actorRowFields );
149 $performer = $logEntry->getPerformerIdentity();
150 $this->assertTrue( $expected->equals( $performer ) );