+ list( $fields, $callback ) = $wstore->insertWithTempTable(
+ $this->db, $key, $comment, $data
+ );
+ } else {
+ $fields = $wstore->insert( $this->db, $key, $comment, $data );
+ }
+
+ if ( $writeStage <= MIGRATION_WRITE_BOTH ) {
+ $this->assertSame( $expect['text'], $fields[$key], "old field, stage=$writeStage" );
+ } else {
+ $this->assertArrayNotHasKey( $key, $fields, "old field, stage=$writeStage" );
+ }
+ if ( $writeStage >= MIGRATION_WRITE_BOTH && !$usesTemp ) {
+ $this->assertArrayHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
+ } else {
+ $this->assertArrayNotHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
+ }
+
+ $this->db->insert( $table, $extraFields + $fields, __METHOD__ );
+ $id = $this->db->insertId();
+ if ( $usesTemp ) {
+ $callback( $id );
+ }
+
+ for ( $readStage = $readRange[0]; $readStage <= $readRange[1]; $readStage++ ) {
+ $rstore = $this->makeStore( $readStage );
+
+ $fieldRow = $this->db->selectRow(
+ $table,
+ $rstore->getFields( $key ),
+ [ $pk => $id ],
+ __METHOD__
+ );
+
+ $queryInfo = $rstore->getJoin( $key );
+ $joinRow = $this->db->selectRow(
+ [ $table ] + $queryInfo['tables'],
+ $queryInfo['fields'],
+ [ $pk => $id ],
+ __METHOD__,
+ [],
+ $queryInfo['joins']
+ );
+
+ $this->assertComment(
+ $writeStage === MIGRATION_OLD || $readStage === MIGRATION_OLD ? $expectOld : $expect,
+ $rstore->getCommentLegacy( $this->db, $key, $fieldRow ),
+ "w=$writeStage, r=$readStage, from getFields()"
+ );
+ $this->assertComment(
+ $writeStage === MIGRATION_OLD || $readStage === MIGRATION_OLD ? $expectOld : $expect,
+ $rstore->getComment( $key, $joinRow ),
+ "w=$writeStage, r=$readStage, from getJoin()"
+ );
+ }
+ }
+ }
+
+ /**
+ * @dataProvider provideInsertRoundTrip
+ * @param string $table
+ * @param string $key
+ * @param string $pk
+ * @param string $extraFields
+ * @param string|Message $comment
+ * @param array|null $data
+ * @param array $expect
+ */
+ public function testInsertRoundTrip_withKeyConstruction(
+ $table, $key, $pk, $extraFields, $comment, $data, $expect
+ ) {
+ $expectOld = [
+ 'text' => $expect['text'],
+ 'message' => new RawMessage( '$1', [ $expect['text'] ] ),
+ 'data' => null,
+ ];
+
+ $stages = [
+ MIGRATION_OLD => [ MIGRATION_OLD, MIGRATION_WRITE_NEW ],
+ MIGRATION_WRITE_BOTH => [ MIGRATION_OLD, MIGRATION_NEW ],
+ MIGRATION_WRITE_NEW => [ MIGRATION_WRITE_BOTH, MIGRATION_NEW ],
+ MIGRATION_NEW => [ MIGRATION_WRITE_BOTH, MIGRATION_NEW ],
+ ];
+
+ foreach ( $stages as $writeStage => $readRange ) {
+ if ( $key === 'ipb_reason' ) {
+ $extraFields['ipb_address'] = __CLASS__ . "#$writeStage";
+ }
+
+ $wstore = $this->makeStoreWithKey( $writeStage, $key );
+ $usesTemp = $key === 'rev_comment';
+
+ if ( $usesTemp ) {
+ list( $fields, $callback ) = $wstore->insertWithTempTable(
+ $this->db, $comment, $data
+ );