MediaWiki REL1_31
ActorMigrationTest.php
Go to the documentation of this file.
1<?php
2
4use Wikimedia\TestingAccessWrapper;
5
11
12 protected $tablesUsed = [
13 'revision',
14 'revision_actor_temp',
15 'ipblocks',
16 'recentchanges',
17 'actor',
18 ];
19
25 protected function makeMigration( $stage ) {
26 return new ActorMigration( $stage );
27 }
28
35 public function testGetJoin( $stage, $key, $expect ) {
36 $m = $this->makeMigration( $stage );
37 $result = $m->getJoin( $key );
38 $this->assertEquals( $expect, $result );
39 }
40
41 public static function provideGetJoin() {
42 return [
43 'Simple table, old' => [
44 MIGRATION_OLD, 'rc_user', [
45 'tables' => [],
46 'fields' => [
47 'rc_user' => 'rc_user',
48 'rc_user_text' => 'rc_user_text',
49 'rc_actor' => 'NULL',
50 ],
51 'joins' => [],
52 ],
53 ],
54 'Simple table, write-both' => [
55 MIGRATION_WRITE_BOTH, 'rc_user', [
56 'tables' => [ 'actor_rc_user' => 'actor' ],
57 'fields' => [
58 'rc_user' => 'COALESCE( actor_rc_user.actor_user, rc_user )',
59 'rc_user_text' => 'COALESCE( actor_rc_user.actor_name, rc_user_text )',
60 'rc_actor' => 'rc_actor',
61 ],
62 'joins' => [
63 'actor_rc_user' => [ 'LEFT JOIN', 'actor_rc_user.actor_id = rc_actor' ],
64 ],
65 ],
66 ],
67 'Simple table, write-new' => [
68 MIGRATION_WRITE_NEW, 'rc_user', [
69 'tables' => [ 'actor_rc_user' => 'actor' ],
70 'fields' => [
71 'rc_user' => 'COALESCE( actor_rc_user.actor_user, rc_user )',
72 'rc_user_text' => 'COALESCE( actor_rc_user.actor_name, rc_user_text )',
73 'rc_actor' => 'rc_actor',
74 ],
75 'joins' => [
76 'actor_rc_user' => [ 'LEFT JOIN', 'actor_rc_user.actor_id = rc_actor' ],
77 ],
78 ],
79 ],
80 'Simple table, new' => [
81 MIGRATION_NEW, 'rc_user', [
82 'tables' => [ 'actor_rc_user' => 'actor' ],
83 'fields' => [
84 'rc_user' => 'actor_rc_user.actor_user',
85 'rc_user_text' => 'actor_rc_user.actor_name',
86 'rc_actor' => 'rc_actor',
87 ],
88 'joins' => [
89 'actor_rc_user' => [ 'JOIN', 'actor_rc_user.actor_id = rc_actor' ],
90 ],
91 ],
92 ],
93
94 'ipblocks, old' => [
95 MIGRATION_OLD, 'ipb_by', [
96 'tables' => [],
97 'fields' => [
98 'ipb_by' => 'ipb_by',
99 'ipb_by_text' => 'ipb_by_text',
100 'ipb_by_actor' => 'NULL',
101 ],
102 'joins' => [],
103 ],
104 ],
105 'ipblocks, write-both' => [
106 MIGRATION_WRITE_BOTH, 'ipb_by', [
107 'tables' => [ 'actor_ipb_by' => 'actor' ],
108 'fields' => [
109 'ipb_by' => 'COALESCE( actor_ipb_by.actor_user, ipb_by )',
110 'ipb_by_text' => 'COALESCE( actor_ipb_by.actor_name, ipb_by_text )',
111 'ipb_by_actor' => 'ipb_by_actor',
112 ],
113 'joins' => [
114 'actor_ipb_by' => [ 'LEFT JOIN', 'actor_ipb_by.actor_id = ipb_by_actor' ],
115 ],
116 ],
117 ],
118 'ipblocks, write-new' => [
119 MIGRATION_WRITE_NEW, 'ipb_by', [
120 'tables' => [ 'actor_ipb_by' => 'actor' ],
121 'fields' => [
122 'ipb_by' => 'COALESCE( actor_ipb_by.actor_user, ipb_by )',
123 'ipb_by_text' => 'COALESCE( actor_ipb_by.actor_name, ipb_by_text )',
124 'ipb_by_actor' => 'ipb_by_actor',
125 ],
126 'joins' => [
127 'actor_ipb_by' => [ 'LEFT JOIN', 'actor_ipb_by.actor_id = ipb_by_actor' ],
128 ],
129 ],
130 ],
131 'ipblocks, new' => [
132 MIGRATION_NEW, 'ipb_by', [
133 'tables' => [ 'actor_ipb_by' => 'actor' ],
134 'fields' => [
135 'ipb_by' => 'actor_ipb_by.actor_user',
136 'ipb_by_text' => 'actor_ipb_by.actor_name',
137 'ipb_by_actor' => 'ipb_by_actor',
138 ],
139 'joins' => [
140 'actor_ipb_by' => [ 'JOIN', 'actor_ipb_by.actor_id = ipb_by_actor' ],
141 ],
142 ],
143 ],
144
145 'Revision, old' => [
146 MIGRATION_OLD, 'rev_user', [
147 'tables' => [],
148 'fields' => [
149 'rev_user' => 'rev_user',
150 'rev_user_text' => 'rev_user_text',
151 'rev_actor' => 'NULL',
152 ],
153 'joins' => [],
154 ],
155 ],
156 'Revision, write-both' => [
157 MIGRATION_WRITE_BOTH, 'rev_user', [
158 'tables' => [
159 'temp_rev_user' => 'revision_actor_temp',
160 'actor_rev_user' => 'actor',
161 ],
162 'fields' => [
163 'rev_user' => 'COALESCE( actor_rev_user.actor_user, rev_user )',
164 'rev_user_text' => 'COALESCE( actor_rev_user.actor_name, rev_user_text )',
165 'rev_actor' => 'temp_rev_user.revactor_actor',
166 ],
167 'joins' => [
168 'temp_rev_user' => [ 'LEFT JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
169 'actor_rev_user' => [ 'LEFT JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
170 ],
171 ],
172 ],
173 'Revision, write-new' => [
174 MIGRATION_WRITE_NEW, 'rev_user', [
175 'tables' => [
176 'temp_rev_user' => 'revision_actor_temp',
177 'actor_rev_user' => 'actor',
178 ],
179 'fields' => [
180 'rev_user' => 'COALESCE( actor_rev_user.actor_user, rev_user )',
181 'rev_user_text' => 'COALESCE( actor_rev_user.actor_name, rev_user_text )',
182 'rev_actor' => 'temp_rev_user.revactor_actor',
183 ],
184 'joins' => [
185 'temp_rev_user' => [ 'LEFT JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
186 'actor_rev_user' => [ 'LEFT JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
187 ],
188 ],
189 ],
190 'Revision, new' => [
191 MIGRATION_NEW, 'rev_user', [
192 'tables' => [
193 'temp_rev_user' => 'revision_actor_temp',
194 'actor_rev_user' => 'actor',
195 ],
196 'fields' => [
197 'rev_user' => 'actor_rev_user.actor_user',
198 'rev_user_text' => 'actor_rev_user.actor_name',
199 'rev_actor' => 'temp_rev_user.revactor_actor',
200 ],
201 'joins' => [
202 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
203 'actor_rev_user' => [ 'JOIN', 'actor_rev_user.actor_id = temp_rev_user.revactor_actor' ],
204 ],
205 ],
206 ],
207 ];
208 }
209
218 public function testGetWhere( $stage, $key, $users, $useId, $expect ) {
219 $expect['conds'] = '(' . implode( ') OR (', $expect['orconds'] ) . ')';
220
221 if ( count( $users ) === 1 ) {
222 $users = reset( $users );
223 }
224
225 $m = $this->makeMigration( $stage );
226 $result = $m->getWhere( $this->db, $key, $users, $useId );
227 $this->assertEquals( $expect, $result );
228 }
229
230 public function provideGetWhere() {
231 $makeUserIdentity = function ( $id, $name, $actor ) {
232 $u = $this->getMock( UserIdentity::class );
233 $u->method( 'getId' )->willReturn( $id );
234 $u->method( 'getName' )->willReturn( $name );
235 $u->method( 'getActorId' )->willReturn( $actor );
236 return $u;
237 };
238
239 $genericUser = [ $makeUserIdentity( 1, 'User1', 11 ) ];
240 $complicatedUsers = [
241 $makeUserIdentity( 1, 'User1', 11 ),
242 $makeUserIdentity( 2, 'User2', 12 ),
243 $makeUserIdentity( 3, 'User3', 0 ),
244 $makeUserIdentity( 0, '192.168.12.34', 34 ),
245 $makeUserIdentity( 0, '192.168.12.35', 0 ),
246 ];
247
248 return [
249 'Simple table, old' => [
250 MIGRATION_OLD, 'rc_user', $genericUser, true, [
251 'tables' => [],
252 'orconds' => [ 'userid' => "rc_user = '1'" ],
253 'joins' => [],
254 ],
255 ],
256 'Simple table, write-both' => [
257 MIGRATION_WRITE_BOTH, 'rc_user', $genericUser, true, [
258 'tables' => [],
259 'orconds' => [
260 'actor' => "rc_actor = '11'",
261 'userid' => "rc_actor = '0' AND rc_user = '1'"
262 ],
263 'joins' => [],
264 ],
265 ],
266 'Simple table, write-new' => [
267 MIGRATION_WRITE_NEW, 'rc_user', $genericUser, true, [
268 'tables' => [],
269 'orconds' => [
270 'actor' => "rc_actor = '11'",
271 'userid' => "rc_actor = '0' AND rc_user = '1'"
272 ],
273 'joins' => [],
274 ],
275 ],
276 'Simple table, new' => [
277 MIGRATION_NEW, 'rc_user', $genericUser, true, [
278 'tables' => [],
279 'orconds' => [ 'actor' => "rc_actor = '11'" ],
280 'joins' => [],
281 ],
282 ],
283
284 'ipblocks, old' => [
285 MIGRATION_OLD, 'ipb_by', $genericUser, true, [
286 'tables' => [],
287 'orconds' => [ 'userid' => "ipb_by = '1'" ],
288 'joins' => [],
289 ],
290 ],
291 'ipblocks, write-both' => [
292 MIGRATION_WRITE_BOTH, 'ipb_by', $genericUser, true, [
293 'tables' => [],
294 'orconds' => [
295 'actor' => "ipb_by_actor = '11'",
296 'userid' => "ipb_by_actor = '0' AND ipb_by = '1'"
297 ],
298 'joins' => [],
299 ],
300 ],
301 'ipblocks, write-new' => [
302 MIGRATION_WRITE_NEW, 'ipb_by', $genericUser, true, [
303 'tables' => [],
304 'orconds' => [
305 'actor' => "ipb_by_actor = '11'",
306 'userid' => "ipb_by_actor = '0' AND ipb_by = '1'"
307 ],
308 'joins' => [],
309 ],
310 ],
311 'ipblocks, new' => [
312 MIGRATION_NEW, 'ipb_by', $genericUser, true, [
313 'tables' => [],
314 'orconds' => [ 'actor' => "ipb_by_actor = '11'" ],
315 'joins' => [],
316 ],
317 ],
318
319 'Revision, old' => [
320 MIGRATION_OLD, 'rev_user', $genericUser, true, [
321 'tables' => [],
322 'orconds' => [ 'userid' => "rev_user = '1'" ],
323 'joins' => [],
324 ],
325 ],
326 'Revision, write-both' => [
327 MIGRATION_WRITE_BOTH, 'rev_user', $genericUser, true, [
328 'tables' => [
329 'temp_rev_user' => 'revision_actor_temp',
330 ],
331 'orconds' => [
332 'actor' =>
333 "(temp_rev_user.revactor_actor IS NOT NULL) AND temp_rev_user.revactor_actor = '11'",
334 'userid' => "temp_rev_user.revactor_actor IS NULL AND rev_user = '1'"
335 ],
336 'joins' => [
337 'temp_rev_user' => [ 'LEFT JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
338 ],
339 ],
340 ],
341 'Revision, write-new' => [
342 MIGRATION_WRITE_NEW, 'rev_user', $genericUser, true, [
343 'tables' => [
344 'temp_rev_user' => 'revision_actor_temp',
345 ],
346 'orconds' => [
347 'actor' =>
348 "(temp_rev_user.revactor_actor IS NOT NULL) AND temp_rev_user.revactor_actor = '11'",
349 'userid' => "temp_rev_user.revactor_actor IS NULL AND rev_user = '1'"
350 ],
351 'joins' => [
352 'temp_rev_user' => [ 'LEFT JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
353 ],
354 ],
355 ],
356 'Revision, new' => [
357 MIGRATION_NEW, 'rev_user', $genericUser, true, [
358 'tables' => [
359 'temp_rev_user' => 'revision_actor_temp',
360 ],
361 'orconds' => [ 'actor' => "temp_rev_user.revactor_actor = '11'" ],
362 'joins' => [
363 'temp_rev_user' => [ 'JOIN', 'temp_rev_user.revactor_rev = rev_id' ],
364 ],
365 ],
366 ],
367
368 'Multiple users, old' => [
369 MIGRATION_OLD, 'rc_user', $complicatedUsers, true, [
370 'tables' => [],
371 'orconds' => [
372 'userid' => "rc_user IN ('1','2','3') ",
373 'username' => "rc_user_text IN ('192.168.12.34','192.168.12.35') "
374 ],
375 'joins' => [],
376 ],
377 ],
378 'Multiple users, write-both' => [
379 MIGRATION_WRITE_BOTH, 'rc_user', $complicatedUsers, true, [
380 'tables' => [],
381 'orconds' => [
382 'actor' => "rc_actor IN ('11','12','34') ",
383 'userid' => "rc_actor = '0' AND rc_user IN ('1','2','3') ",
384 'username' => "rc_actor = '0' AND rc_user_text IN ('192.168.12.34','192.168.12.35') "
385 ],
386 'joins' => [],
387 ],
388 ],
389 'Multiple users, write-new' => [
390 MIGRATION_WRITE_NEW, 'rc_user', $complicatedUsers, true, [
391 'tables' => [],
392 'orconds' => [
393 'actor' => "rc_actor IN ('11','12','34') ",
394 'userid' => "rc_actor = '0' AND rc_user IN ('1','2','3') ",
395 'username' => "rc_actor = '0' AND rc_user_text IN ('192.168.12.34','192.168.12.35') "
396 ],
397 'joins' => [],
398 ],
399 ],
400 'Multiple users, new' => [
401 MIGRATION_NEW, 'rc_user', $complicatedUsers, true, [
402 'tables' => [],
403 'orconds' => [ 'actor' => "rc_actor IN ('11','12','34') " ],
404 'joins' => [],
405 ],
406 ],
407
408 'Multiple users, no use ID, old' => [
409 MIGRATION_OLD, 'rc_user', $complicatedUsers, false, [
410 'tables' => [],
411 'orconds' => [
412 'username' => "rc_user_text IN ('User1','User2','User3','192.168.12.34','192.168.12.35') "
413 ],
414 'joins' => [],
415 ],
416 ],
417 'Multiple users, write-both' => [
418 MIGRATION_WRITE_BOTH, 'rc_user', $complicatedUsers, false, [
419 'tables' => [],
420 'orconds' => [
421 'actor' => "rc_actor IN ('11','12','34') ",
422 'username' => "rc_actor = '0' AND "
423 . "rc_user_text IN ('User1','User2','User3','192.168.12.34','192.168.12.35') "
424 ],
425 'joins' => [],
426 ],
427 ],
428 'Multiple users, write-new' => [
429 MIGRATION_WRITE_NEW, 'rc_user', $complicatedUsers, false, [
430 'tables' => [],
431 'orconds' => [
432 'actor' => "rc_actor IN ('11','12','34') ",
433 'username' => "rc_actor = '0' AND "
434 . "rc_user_text IN ('User1','User2','User3','192.168.12.34','192.168.12.35') "
435 ],
436 'joins' => [],
437 ],
438 ],
439 'Multiple users, new' => [
440 MIGRATION_NEW, 'rc_user', $complicatedUsers, false, [
441 'tables' => [],
442 'orconds' => [ 'actor' => "rc_actor IN ('11','12','34') " ],
443 'joins' => [],
444 ],
445 ],
446 ];
447 }
448
456 public function testInsertRoundTrip( $table, $key, $pk, $extraFields ) {
457 $u = $this->getTestUser()->getUser();
458 $user = $this->getMock( UserIdentity::class );
459 $user->method( 'getId' )->willReturn( $u->getId() );
460 $user->method( 'getName' )->willReturn( $u->getName() );
461 if ( $u->getActorId( $this->db ) ) {
462 $user->method( 'getActorId' )->willReturn( $u->getActorId() );
463 } else {
464 $this->db->insert(
465 'actor',
466 [ 'actor_user' => $u->getId(), 'actor_name' => $u->getName() ],
467 __METHOD__
468 );
469 $user->method( 'getActorId' )->willReturn( $this->db->insertId() );
470 }
471
472 $stages = [
477 ];
478
479 $nameKey = $key . '_text';
480 $actorKey = $key === 'ipb_by' ? 'ipb_by_actor' : substr( $key, 0, -5 ) . '_actor';
481
482 foreach ( $stages as $writeStage => $readRange ) {
483 if ( $key === 'ipb_by' ) {
484 $extraFields['ipb_address'] = __CLASS__ . "#$writeStage";
485 }
486
487 $w = $this->makeMigration( $writeStage );
488 $usesTemp = $key === 'rev_user';
489
490 if ( $usesTemp ) {
491 list( $fields, $callback ) = $w->getInsertValuesWithTempTable( $this->db, $key, $user );
492 } else {
493 $fields = $w->getInsertValues( $this->db, $key, $user );
494 }
495
496 if ( $writeStage <= MIGRATION_WRITE_BOTH ) {
497 $this->assertSame( $user->getId(), $fields[$key], "old field, stage=$writeStage" );
498 $this->assertSame( $user->getName(), $fields[$nameKey], "old field, stage=$writeStage" );
499 } else {
500 $this->assertArrayNotHasKey( $key, $fields, "old field, stage=$writeStage" );
501 $this->assertArrayNotHasKey( $nameKey, $fields, "old field, stage=$writeStage" );
502 }
503 if ( $writeStage >= MIGRATION_WRITE_BOTH && !$usesTemp ) {
504 $this->assertSame( $user->getActorId(), $fields[$actorKey], "new field, stage=$writeStage" );
505 } else {
506 $this->assertArrayNotHasKey( $actorKey, $fields, "new field, stage=$writeStage" );
507 }
508
509 $this->db->insert( $table, $extraFields + $fields, __METHOD__ );
510 $id = $this->db->insertId();
511 if ( $usesTemp ) {
512 $callback( $id, $extraFields );
513 }
514
515 for ( $readStage = $readRange[0]; $readStage <= $readRange[1]; $readStage++ ) {
516 $r = $this->makeMigration( $readStage );
517
518 $queryInfo = $r->getJoin( $key );
519 $row = $this->db->selectRow(
520 [ $table ] + $queryInfo['tables'],
521 $queryInfo['fields'],
522 [ $pk => $id ],
523 __METHOD__,
524 [],
525 $queryInfo['joins']
526 );
527
528 $this->assertSame( $user->getId(), (int)$row->$key, "w=$writeStage, r=$readStage, id" );
529 $this->assertSame( $user->getName(), $row->$nameKey, "w=$writeStage, r=$readStage, name" );
530 $this->assertSame(
531 $readStage === MIGRATION_OLD || $writeStage === MIGRATION_OLD ? 0 : $user->getActorId(),
532 (int)$row->$actorKey,
533 "w=$writeStage, r=$readStage, actor"
534 );
535 }
536 }
537 }
538
539 public static function provideInsertRoundTrip() {
540 $db = wfGetDB( DB_REPLICA ); // for timestamps
541
542 $ipbfields = [
543 ];
544 $revfields = [
545 ];
546
547 return [
548 'recentchanges' => [ 'recentchanges', 'rc_user', 'rc_id', [
549 'rc_timestamp' => $db->timestamp(),
550 'rc_namespace' => 0,
551 'rc_title' => 'Test',
552 'rc_this_oldid' => 42,
553 'rc_last_oldid' => 41,
554 'rc_source' => 'test',
555 ] ],
556 'ipblocks' => [ 'ipblocks', 'ipb_by', 'ipb_id', [
557 'ipb_range_start' => '',
558 'ipb_range_end' => '',
559 'ipb_timestamp' => $db->timestamp(),
560 'ipb_expiry' => $db->getInfinity(),
561 ] ],
562 'revision' => [ 'revision', 'rev_user', 'rev_id', [
563 'rev_page' => 42,
564 'rev_text_id' => 42,
565 'rev_len' => 0,
566 'rev_timestamp' => $db->timestamp(),
567 ] ],
568 ];
569 }
570
571 public static function provideStages() {
572 return [
573 'MIGRATION_OLD' => [ MIGRATION_OLD ],
574 'MIGRATION_WRITE_BOTH' => [ MIGRATION_WRITE_BOTH ],
575 'MIGRATION_WRITE_NEW' => [ MIGRATION_WRITE_NEW ],
576 'MIGRATION_NEW' => [ MIGRATION_NEW ],
577 ];
578 }
579
586 public function testInsertWrong( $stage ) {
587 $m = $this->makeMigration( $stage );
588 $m->getInsertValues( $this->db, 'rev_user', $this->getTestUser()->getUser() );
589 }
590
597 public function testInsertWithTempTableWrong( $stage ) {
598 $m = $this->makeMigration( $stage );
599 $m->getInsertValuesWithTempTable( $this->db, 'rc_user', $this->getTestUser()->getUser() );
600 }
601
606 public function testInsertWithTempTableDeprecated( $stage ) {
607 $wrap = TestingAccessWrapper::newFromClass( ActorMigration::class );
608 $wrap->formerTempTables += [ 'rc_user' => '1.30' ];
609
610 $this->hideDeprecated( 'ActorMigration::getInsertValuesWithTempTable for rc_user' );
611 $m = $this->makeMigration( $stage );
612 list( $fields, $callback )
613 = $m->getInsertValuesWithTempTable( $this->db, 'rc_user', $this->getTestUser()->getUser() );
614 $this->assertTrue( is_callable( $callback ) );
615 }
616
624 $m = $this->makeMigration( $stage );
625 list( $fields, $callback )
626 = $m->getInsertValuesWithTempTable( $this->db, 'rev_user', $this->getTestUser()->getUser() );
627 $callback( 1, [] );
628 }
629
630 public function testInsertUserIdentity() {
631 $user = $this->getTestUser()->getUser();
632 $userIdentity = $this->getMock( UserIdentity::class );
633 $userIdentity->method( 'getId' )->willReturn( $user->getId() );
634 $userIdentity->method( 'getName' )->willReturn( $user->getName() );
635 $userIdentity->method( 'getActorId' )->willReturn( 0 );
636
637 list( $cFields, $cCallback ) = CommentStore::newKey( 'rev_comment' )
638 ->insertWithTempTable( $this->db, '' );
639 $m = $this->makeMigration( MIGRATION_WRITE_BOTH );
640 list( $fields, $callback ) =
641 $m->getInsertValuesWithTempTable( $this->db, 'rev_user', $userIdentity );
642 $extraFields = [
643 'rev_page' => 42,
644 'rev_text_id' => 42,
645 'rev_len' => 0,
646 'rev_timestamp' => $this->db->timestamp(),
647 ] + $cFields;
648 $this->db->insert( 'revision', $extraFields + $fields, __METHOD__ );
649 $id = $this->db->insertId();
650 $callback( $id, $extraFields );
651 $cCallback( $id );
652
653 $qi = Revision::getQueryInfo();
654 $row = $this->db->selectRow(
655 $qi['tables'], $qi['fields'], [ 'rev_id' => $id ], __METHOD__, [], $qi['joins']
656 );
657 $this->assertSame( $user->getId(), (int)$row->rev_user );
658 $this->assertSame( $user->getName(), $row->rev_user_text );
659 $this->assertSame( $user->getActorId(), (int)$row->rev_actor );
660
661 $m = $this->makeMigration( MIGRATION_WRITE_BOTH );
662 $fields = $m->getInsertValues( $this->db, 'dummy_user', $userIdentity );
663 $this->assertSame( $user->getId(), $fields['dummy_user'] );
664 $this->assertSame( $user->getName(), $fields['dummy_user_text'] );
665
666 // This no longer works because despite mocking UserIdentiy::getActorId(), that
667 // method is not called, instead the actual database is queried, when $fields are set.
668 // Since dummy_actor has no row in the actor table, when getInsertValues needs to
669 // actor id it creates a new one
670 // $this->assertSame( $user->getActorId(), $fields['dummy_actor'] );
671 }
672
673 public function testConstructor() {
674 $m = ActorMigration::newMigration();
675 $this->assertInstanceOf( ActorMigration::class, $m );
676 $this->assertSame( $m, ActorMigration::newMigration() );
677 }
678
685 public function testIsAnon( $stage, $isAnon, $isNotAnon ) {
686 $m = $this->makeMigration( $stage );
687 $this->assertSame( $isAnon, $m->isAnon( 'foo' ) );
688 $this->assertSame( $isNotAnon, $m->isNotAnon( 'foo' ) );
689 }
690
691 public static function provideIsAnon() {
692 return [
693 'MIGRATION_OLD' => [ MIGRATION_OLD, 'foo = 0', 'foo != 0' ],
694 'MIGRATION_WRITE_BOTH' => [ MIGRATION_WRITE_BOTH, 'foo = 0', 'foo != 0' ],
695 'MIGRATION_WRITE_NEW' => [ MIGRATION_WRITE_NEW, 'foo = 0', 'foo != 0' ],
696 'MIGRATION_NEW' => [ MIGRATION_NEW, 'foo IS NULL', 'foo IS NOT NULL' ],
697 ];
698 }
699
700}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Database ActorMigration.
makeMigration( $stage)
Create an ActorMigration for a particular stage.
testGetWhere( $stage, $key, $users, $useId, $expect)
provideGetWhere
testInsertWithTempTableCallbackMissingFields( $stage)
provideStages
testGetJoin( $stage, $key, $expect)
provideGetJoin
testIsAnon( $stage, $isAnon, $isNotAnon)
provideIsAnon
testInsertWithTempTableDeprecated( $stage)
provideStages
testInsertWithTempTableWrong( $stage)
provideStages
testInsertWrong( $stage)
provideStages
testInsertRoundTrip( $table, $key, $pk, $extraFields)
provideInsertRoundTrip
This class handles the logic for the actor table migration.
Base class that store and restore the Language objects.
static TestUser[] $users
Database $db
Primary database.
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
getInfinity()
Find out when 'infinity' is.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
const MIGRATION_WRITE_NEW
Definition Defines.php:304
const MIGRATION_NEW
Definition Defines.php:305
const MIGRATION_WRITE_BOTH
Definition Defines.php:303
const MIGRATION_OLD
Definition Defines.php:302
Interface for objects representing user identity.
const DB_REPLICA
Definition defines.php:25