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() );
466 [
'actor_user' => $u->getId(),
'actor_name' => $u->getName() ],
469 $user->method(
'getActorId' )->willReturn( $this->db->insertId() );
479 $nameKey = $key .
'_text';
480 $actorKey = $key ===
'ipb_by' ?
'ipb_by_actor' : substr( $key, 0, -5 ) .
'_actor';
482 foreach ( $stages as $writeStage => $readRange ) {
483 if ( $key ===
'ipb_by' ) {
484 $extraFields[
'ipb_address'] = __CLASS__ .
"#$writeStage";
488 $usesTemp = $key ===
'rev_user';
491 list( $fields, $callback ) = $w->getInsertValuesWithTempTable( $this->db, $key, $user );
493 $fields = $w->getInsertValues( $this->db, $key, $user );
497 $this->assertSame( $user->getId(), $fields[$key],
"old field, stage=$writeStage" );
498 $this->assertSame( $user->getName(), $fields[$nameKey],
"old field, stage=$writeStage" );
500 $this->assertArrayNotHasKey( $key, $fields,
"old field, stage=$writeStage" );
501 $this->assertArrayNotHasKey( $nameKey, $fields,
"old field, stage=$writeStage" );
504 $this->assertSame( $user->getActorId(), $fields[$actorKey],
"new field, stage=$writeStage" );
506 $this->assertArrayNotHasKey( $actorKey, $fields,
"new field, stage=$writeStage" );
509 $this->db->insert( $table, $extraFields + $fields, __METHOD__ );
510 $id = $this->db->insertId();
512 $callback( $id, $extraFields );
515 for ( $readStage = $readRange[0]; $readStage <= $readRange[1]; $readStage++ ) {
518 $queryInfo = $r->getJoin( $key );
519 $row = $this->db->selectRow(
520 [ $table ] + $queryInfo[
'tables'],
521 $queryInfo[
'fields'],
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" );
532 (int)$row->$actorKey,
533 "w=$writeStage, r=$readStage, actor"
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 );
637 list( $cFields, $cCallback ) = CommentStore::newKey(
'rev_comment' )
638 ->insertWithTempTable( $this->db,
'' );
640 list( $fields, $callback ) =
641 $m->getInsertValuesWithTempTable( $this->db,
'rev_user', $userIdentity );
646 'rev_timestamp' => $this->db->timestamp(),
648 $this->db->insert(
'revision', $extraFields + $fields, __METHOD__ );
649 $id = $this->db->insertId();
650 $callback( $id, $extraFields );
653 $qi = Revision::getQueryInfo();
654 $row = $this->db->selectRow(
655 $qi[
'tables'], $qi[
'fields'], [
'rev_id' => $id ], __METHOD__, [], $qi[
'joins']
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 );
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'] );