MediaWiki  REL1_31
ActorMigrationTest.php
Go to the documentation of this file.
1 <?php
2 
4 use 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() {
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 }
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:247
ActorMigrationTest\$tablesUsed
$tablesUsed
Definition: ActorMigrationTest.php:12
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
ActorMigrationTest\provideInsertRoundTrip
static provideInsertRoundTrip()
Definition: ActorMigrationTest.php:539
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:153
ActorMigrationTest\testInsertUserIdentity
testInsertUserIdentity()
Definition: ActorMigrationTest.php:630
MIGRATION_NEW
const MIGRATION_NEW
Definition: Defines.php:305
MIGRATION_WRITE_BOTH
const MIGRATION_WRITE_BOTH
Definition: Defines.php:303
ActorMigration
This class handles the logic for the actor table migration.
Definition: ActorMigration.php:35
ActorMigrationTest\testInsertWithTempTableCallbackMissingFields
testInsertWithTempTableCallbackMissingFields( $stage)
provideStages
Definition: ActorMigrationTest.php:623
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1993
ActorMigrationTest\makeMigration
makeMigration( $stage)
Create an ActorMigration for a particular stage.
Definition: ActorMigrationTest.php:25
CommentStore\newKey
static newKey( $key)
Static constructor for easier chaining.
Definition: CommentStore.php:116
ActorMigrationTest\provideGetJoin
static provideGetJoin()
Definition: ActorMigrationTest.php:41
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:32
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:89
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
MIGRATION_WRITE_NEW
const MIGRATION_WRITE_NEW
Definition: Defines.php:304
ActorMigrationTest\provideIsAnon
static provideIsAnon()
Definition: ActorMigrationTest.php:691
ActorMigrationTest\testInsertRoundTrip
testInsertRoundTrip( $table, $key, $pk, $extraFields)
provideInsertRoundTrip
Definition: ActorMigrationTest.php:456
Revision\getQueryInfo
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Definition: Revision.php:492
ActorMigrationTest\testInsertWithTempTableDeprecated
testInsertWithTempTableDeprecated( $stage)
provideStages
Definition: ActorMigrationTest.php:606
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2812
MediaWikiTestCase\hideDeprecated
hideDeprecated( $function)
Don't throw a warning if $function is deprecated and called later.
Definition: MediaWikiTestCase.php:1675
ActorMigrationTest\provideStages
static provideStages()
Definition: ActorMigrationTest.php:571
MediaWikiTestCase\$users
static TestUser[] $users
Definition: MediaWikiTestCase.php:49
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
ActorMigrationTest\testGetJoin
testGetJoin( $stage, $key, $expect)
provideGetJoin
Definition: ActorMigrationTest.php:35
ActorMigrationTest\provideGetWhere
provideGetWhere()
Definition: ActorMigrationTest.php:230
list
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
MIGRATION_OLD
const MIGRATION_OLD
Definition: Defines.php:302
ActorMigrationTest\testInsertWithTempTableWrong
testInsertWithTempTableWrong( $stage)
provideStages
Definition: ActorMigrationTest.php:597
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
ActorMigrationTest\testGetWhere
testGetWhere( $stage, $key, $users, $useId, $expect)
provideGetWhere
Definition: ActorMigrationTest.php:218
ActorMigrationTest\testConstructor
testConstructor()
Definition: ActorMigrationTest.php:673
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
ActorMigrationTest\testInsertWrong
testInsertWrong( $stage)
provideStages
Definition: ActorMigrationTest.php:586
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
ActorMigrationTest\testIsAnon
testIsAnon( $stage, $isAnon, $isNotAnon)
provideIsAnon
Definition: ActorMigrationTest.php:685
MediaWikiTestCase\$db
Database $db
Primary database.
Definition: MediaWikiTestCase.php:57
ActorMigrationTest
Database ActorMigration.
Definition: ActorMigrationTest.php:10