Merge "install.php: Allow extensions and skins to be specified"
[lhc/web/wiklou.git] / tests / phpunit / includes / logging / DatabaseLogEntryTest.php
1 <?php
2
3 use MediaWiki\MediaWikiServices;
4 use Wikimedia\Rdbms\IDatabase;
5
6 class DatabaseLogEntryTest extends MediaWikiTestCase {
7 public function setUp() {
8 parent::setUp();
9
10 // These services cache their joins
11 MediaWikiServices::getInstance()->resetServiceForTesting( 'CommentStore' );
12 MediaWikiServices::getInstance()->resetServiceForTesting( 'ActorMigration' );
13 }
14
15 public function tearDown() {
16 parent::tearDown();
17
18 MediaWikiServices::getInstance()->resetServiceForTesting( 'CommentStore' );
19 MediaWikiServices::getInstance()->resetServiceForTesting( 'ActorMigration' );
20 }
21
22 /**
23 * @covers DatabaseLogEntry::newFromId
24 * @covers DatabaseLogEntry::getSelectQueryData
25 *
26 * @dataProvider provideNewFromId
27 *
28 * @param int $id
29 * @param array $selectFields
30 * @param string[]|null $row
31 * @param string[]|null $expectedFields
32 * @param int $commentMigration
33 * @param int $actorMigration
34 */
35 public function testNewFromId( $id,
36 array $selectFields,
37 array $row = null,
38 array $expectedFields = null,
39 $commentMigration,
40 $actorMigration
41 ) {
42 $this->setMwGlobals( [
43 'wgCommentTableSchemaMigrationStage' => $commentMigration,
44 'wgActorTableSchemaMigrationStage' => $actorMigration,
45 ] );
46
47 $row = $row ? (object)$row : null;
48 $db = $this->getMock( IDatabase::class );
49 $db->expects( self::once() )
50 ->method( 'selectRow' )
51 ->with( $selectFields['tables'],
52 $selectFields['fields'],
53 $selectFields['conds'],
54 'DatabaseLogEntry::newFromId',
55 $selectFields['options'],
56 $selectFields['join_conds']
57 )
58 ->will( self::returnValue( $row ) );
59
60 /** @var IDatabase $db */
61 $logEntry = DatabaseLogEntry::newFromId( $id, $db );
62
63 if ( !$expectedFields ) {
64 self::assertNull( $logEntry, "Expected no log entry returned for id=$id" );
65 } else {
66 self::assertEquals( $id, $logEntry->getId() );
67 self::assertEquals( $expectedFields['type'], $logEntry->getType() );
68 self::assertEquals( $expectedFields['comment'], $logEntry->getComment() );
69 }
70 }
71
72 public function provideNewFromId() {
73 $oldTables = [
74 'tables' => [ 'logging', 'user' ],
75 'fields' => [
76 'log_id',
77 'log_type',
78 'log_action',
79 'log_timestamp',
80 'log_namespace',
81 'log_title',
82 'log_params',
83 'log_deleted',
84 'user_id',
85 'user_name',
86 'user_editcount',
87 'log_comment_text' => 'log_comment',
88 'log_comment_data' => 'NULL',
89 'log_comment_cid' => 'NULL',
90 'log_user' => 'log_user',
91 'log_user_text' => 'log_user_text',
92 'log_actor' => 'NULL',
93 ],
94 'options' => [],
95 'join_conds' => [ 'user' => [ 'LEFT JOIN', 'user_id=log_user' ] ],
96 ];
97 $newTables = [
98 'tables' => [
99 'logging',
100 'user',
101 'comment_log_comment' => 'comment',
102 'actor_log_user' => 'actor'
103 ],
104 'fields' => [
105 'log_id',
106 'log_type',
107 'log_action',
108 'log_timestamp',
109 'log_namespace',
110 'log_title',
111 'log_params',
112 'log_deleted',
113 'user_id',
114 'user_name',
115 'user_editcount',
116 'log_comment_text' => 'comment_log_comment.comment_text',
117 'log_comment_data' => 'comment_log_comment.comment_data',
118 'log_comment_cid' => 'comment_log_comment.comment_id',
119 'log_user' => 'actor_log_user.actor_user',
120 'log_user_text' => 'actor_log_user.actor_name',
121 'log_actor' => 'log_actor',
122 ],
123 'options' => [],
124 'join_conds' => [
125 'user' => [ 'LEFT JOIN', 'user_id=actor_log_user.actor_user' ],
126 'comment_log_comment' => [ 'JOIN', 'comment_log_comment.comment_id = log_comment_id' ],
127 'actor_log_user' => [ 'JOIN', 'actor_log_user.actor_id = log_actor' ],
128 ],
129 ];
130 return [
131 [
132 0,
133 $oldTables + [ 'conds' => [ 'log_id' => 0 ] ],
134 null,
135 null,
136 MIGRATION_OLD,
137 SCHEMA_COMPAT_OLD,
138 ],
139 [
140 123,
141 $oldTables + [ 'conds' => [ 'log_id' => 123 ] ],
142 [
143 'log_id' => 123,
144 'log_type' => 'foobarize',
145 'log_comment_text' => 'test!',
146 'log_comment_data' => null,
147 ],
148 [ 'type' => 'foobarize', 'comment' => 'test!' ],
149 MIGRATION_OLD,
150 SCHEMA_COMPAT_OLD,
151 ],
152 [
153 567,
154 $newTables + [ 'conds' => [ 'log_id' => 567 ] ],
155 [
156 'log_id' => 567,
157 'log_type' => 'foobarize',
158 'log_comment_text' => 'test!',
159 'log_comment_data' => null,
160 ],
161 [ 'type' => 'foobarize', 'comment' => 'test!' ],
162 MIGRATION_NEW,
163 SCHEMA_COMPAT_NEW,
164 ],
165 ];
166 }
167 }