3 use MediaWiki\MediaWikiServices
;
4 use Wikimedia\ScopedCallback
;
5 use Wikimedia\TestingAccessWrapper
;
10 * @covers CommentStoreComment
12 class CommentStoreTest
extends MediaWikiLangTestCase
{
14 protected $tablesUsed = [
16 'revision_comment_temp',
22 * Create a store for a particular stage
24 * @return CommentStore
26 protected function makeStore( $stage ) {
27 $store = new CommentStore( MediaWikiServices
::getInstance()->getContentLanguage(), $stage );
32 * Create a store for a particular stage and key (for testing deprecated behaviour)
35 * @return CommentStore
37 protected function makeStoreWithKey( $stage, $key ) {
38 $this->hideDeprecated( 'CommentStore::newKey' );
39 $store = CommentStore
::newKey( $key );
40 TestingAccessWrapper
::newFromObject( $store )->stage
= $stage;
45 * @dataProvider provideGetFields
48 * @param array $expect
50 public function testGetFields_withKeyConstruction( $stage, $key, $expect ) {
51 $store = $this->makeStoreWithKey( $stage, $key );
52 $result = $store->getFields();
53 $this->assertEquals( $expect, $result );
57 * @dataProvider provideGetFields
60 * @param array $expect
62 public function testGetFields( $stage, $key, $expect ) {
63 $store = $this->makeStore( $stage );
64 $result = $store->getFields( $key );
65 $this->assertEquals( $expect, $result );
68 public static function provideGetFields() {
70 'Simple table, old' => [
71 MIGRATION_OLD
, 'ipb_reason',
72 [ 'ipb_reason_text' => 'ipb_reason', 'ipb_reason_data' => 'NULL', 'ipb_reason_cid' => 'NULL' ],
74 'Simple table, write-both' => [
75 MIGRATION_WRITE_BOTH
, 'ipb_reason',
76 [ 'ipb_reason_old' => 'ipb_reason', 'ipb_reason_id' => 'ipb_reason_id' ],
78 'Simple table, write-new' => [
79 MIGRATION_WRITE_NEW
, 'ipb_reason',
80 [ 'ipb_reason_old' => 'ipb_reason', 'ipb_reason_id' => 'ipb_reason_id' ],
82 'Simple table, new' => [
83 MIGRATION_NEW
, 'ipb_reason',
84 [ 'ipb_reason_id' => 'ipb_reason_id' ],
88 MIGRATION_OLD
, 'rev_comment',
90 'rev_comment_text' => 'rev_comment',
91 'rev_comment_data' => 'NULL',
92 'rev_comment_cid' => 'NULL',
95 'Revision, write-both' => [
96 MIGRATION_WRITE_BOTH
, 'rev_comment',
97 [ 'rev_comment_old' => 'rev_comment', 'rev_comment_pk' => 'rev_id' ],
99 'Revision, write-new' => [
100 MIGRATION_WRITE_NEW
, 'rev_comment',
101 [ 'rev_comment_old' => 'rev_comment', 'rev_comment_pk' => 'rev_id' ],
104 MIGRATION_NEW
, 'rev_comment',
105 [ 'rev_comment_pk' => 'rev_id' ],
109 MIGRATION_OLD
, 'img_description',
111 'img_description_text' => 'img_description',
112 'img_description_data' => 'NULL',
113 'img_description_cid' => 'NULL',
116 'Image, write-both' => [
117 MIGRATION_WRITE_BOTH
, 'img_description',
118 [ 'img_description_old' => 'img_description', 'img_description_pk' => 'img_name' ],
120 'Image, write-new' => [
121 MIGRATION_WRITE_NEW
, 'img_description',
122 [ 'img_description_old' => 'img_description', 'img_description_pk' => 'img_name' ],
125 MIGRATION_NEW
, 'img_description',
126 [ 'img_description_pk' => 'img_name' ],
132 * @dataProvider provideGetJoin
135 * @param array $expect
137 public function testGetJoin_withKeyConstruction( $stage, $key, $expect ) {
138 $store = $this->makeStoreWithKey( $stage, $key );
139 $result = $store->getJoin();
140 $this->assertEquals( $expect, $result );
144 * @dataProvider provideGetJoin
147 * @param array $expect
149 public function testGetJoin( $stage, $key, $expect ) {
150 $store = $this->makeStore( $stage );
151 $result = $store->getJoin( $key );
152 $this->assertEquals( $expect, $result );
155 public static function provideGetJoin() {
157 'Simple table, old' => [
158 MIGRATION_OLD
, 'ipb_reason', [
161 'ipb_reason_text' => 'ipb_reason',
162 'ipb_reason_data' => 'NULL',
163 'ipb_reason_cid' => 'NULL',
168 'Simple table, write-both' => [
169 MIGRATION_WRITE_BOTH
, 'ipb_reason', [
170 'tables' => [ 'comment_ipb_reason' => 'comment' ],
172 'ipb_reason_text' => 'COALESCE( comment_ipb_reason.comment_text, ipb_reason )',
173 'ipb_reason_data' => 'comment_ipb_reason.comment_data',
174 'ipb_reason_cid' => 'comment_ipb_reason.comment_id',
177 'comment_ipb_reason' => [ 'LEFT JOIN', 'comment_ipb_reason.comment_id = ipb_reason_id' ],
181 'Simple table, write-new' => [
182 MIGRATION_WRITE_NEW
, 'ipb_reason', [
183 'tables' => [ 'comment_ipb_reason' => 'comment' ],
185 'ipb_reason_text' => 'COALESCE( comment_ipb_reason.comment_text, ipb_reason )',
186 'ipb_reason_data' => 'comment_ipb_reason.comment_data',
187 'ipb_reason_cid' => 'comment_ipb_reason.comment_id',
190 'comment_ipb_reason' => [ 'LEFT JOIN', 'comment_ipb_reason.comment_id = ipb_reason_id' ],
194 'Simple table, new' => [
195 MIGRATION_NEW
, 'ipb_reason', [
196 'tables' => [ 'comment_ipb_reason' => 'comment' ],
198 'ipb_reason_text' => 'comment_ipb_reason.comment_text',
199 'ipb_reason_data' => 'comment_ipb_reason.comment_data',
200 'ipb_reason_cid' => 'comment_ipb_reason.comment_id',
203 'comment_ipb_reason' => [ 'JOIN', 'comment_ipb_reason.comment_id = ipb_reason_id' ],
209 MIGRATION_OLD
, 'rev_comment', [
212 'rev_comment_text' => 'rev_comment',
213 'rev_comment_data' => 'NULL',
214 'rev_comment_cid' => 'NULL',
219 'Revision, write-both' => [
220 MIGRATION_WRITE_BOTH
, 'rev_comment', [
222 'temp_rev_comment' => 'revision_comment_temp',
223 'comment_rev_comment' => 'comment',
226 'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
227 'rev_comment_data' => 'comment_rev_comment.comment_data',
228 'rev_comment_cid' => 'comment_rev_comment.comment_id',
231 'temp_rev_comment' => [ 'LEFT JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
232 'comment_rev_comment' => [ 'LEFT JOIN',
233 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
237 'Revision, write-new' => [
238 MIGRATION_WRITE_NEW
, 'rev_comment', [
240 'temp_rev_comment' => 'revision_comment_temp',
241 'comment_rev_comment' => 'comment',
244 'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
245 'rev_comment_data' => 'comment_rev_comment.comment_data',
246 'rev_comment_cid' => 'comment_rev_comment.comment_id',
249 'temp_rev_comment' => [ 'LEFT JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
250 'comment_rev_comment' => [ 'LEFT JOIN',
251 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
256 MIGRATION_NEW
, 'rev_comment', [
258 'temp_rev_comment' => 'revision_comment_temp',
259 'comment_rev_comment' => 'comment',
262 'rev_comment_text' => 'comment_rev_comment.comment_text',
263 'rev_comment_data' => 'comment_rev_comment.comment_data',
264 'rev_comment_cid' => 'comment_rev_comment.comment_id',
267 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
268 'comment_rev_comment' => [ 'JOIN',
269 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
275 MIGRATION_OLD
, 'img_description', [
278 'img_description_text' => 'img_description',
279 'img_description_data' => 'NULL',
280 'img_description_cid' => 'NULL',
285 'Image, write-both' => [
286 MIGRATION_WRITE_BOTH
, 'img_description', [
288 'temp_img_description' => 'image_comment_temp',
289 'comment_img_description' => 'comment',
292 'img_description_text' => 'COALESCE( comment_img_description.comment_text, img_description )',
293 'img_description_data' => 'comment_img_description.comment_data',
294 'img_description_cid' => 'comment_img_description.comment_id',
297 'temp_img_description' => [ 'LEFT JOIN', 'temp_img_description.imgcomment_name = img_name' ],
298 'comment_img_description' => [ 'LEFT JOIN',
299 'comment_img_description.comment_id = temp_img_description.imgcomment_description_id' ],
303 'Image, write-new' => [
304 MIGRATION_WRITE_NEW
, 'img_description', [
306 'temp_img_description' => 'image_comment_temp',
307 'comment_img_description' => 'comment',
310 'img_description_text' => 'COALESCE( comment_img_description.comment_text, img_description )',
311 'img_description_data' => 'comment_img_description.comment_data',
312 'img_description_cid' => 'comment_img_description.comment_id',
315 'temp_img_description' => [ 'LEFT JOIN', 'temp_img_description.imgcomment_name = img_name' ],
316 'comment_img_description' => [ 'LEFT JOIN',
317 'comment_img_description.comment_id = temp_img_description.imgcomment_description_id' ],
322 MIGRATION_NEW
, 'img_description', [
324 'temp_img_description' => 'image_comment_temp',
325 'comment_img_description' => 'comment',
328 'img_description_text' => 'comment_img_description.comment_text',
329 'img_description_data' => 'comment_img_description.comment_data',
330 'img_description_cid' => 'comment_img_description.comment_id',
333 'temp_img_description' => [ 'JOIN', 'temp_img_description.imgcomment_name = img_name' ],
334 'comment_img_description' => [ 'JOIN',
335 'comment_img_description.comment_id = temp_img_description.imgcomment_description_id' ],
342 private function assertComment( $expect, $actual, $from ) {
343 $this->assertSame( $expect['text'], $actual->text
, "text $from" );
344 $this->assertInstanceOf( get_class( $expect['message'] ), $actual->message
,
345 "message class $from" );
346 $this->assertSame( $expect['message']->getKeysToTry(), $actual->message
->getKeysToTry(),
347 "message keys $from" );
348 $this->assertEquals( $expect['message']->text(), $actual->message
->text(),
349 "message rendering $from" );
350 $this->assertEquals( $expect['data'], $actual->data
, "data $from" );
354 * @dataProvider provideInsertRoundTrip
355 * @param string $table
358 * @param string $extraFields
359 * @param string|Message $comment
360 * @param array|null $data
361 * @param array $expect
363 public function testInsertRoundTrip( $table, $key, $pk, $extraFields, $comment, $data, $expect ) {
365 'text' => $expect['text'],
366 'message' => new RawMessage( '$1', [ $expect['text'] ] ),
371 MIGRATION_OLD
=> [ MIGRATION_OLD
, MIGRATION_WRITE_BOTH
, MIGRATION_WRITE_NEW
],
372 MIGRATION_WRITE_BOTH
=> [ MIGRATION_OLD
, MIGRATION_WRITE_BOTH
, MIGRATION_WRITE_NEW
,
374 MIGRATION_WRITE_NEW
=> [ MIGRATION_WRITE_BOTH
, MIGRATION_WRITE_NEW
, MIGRATION_NEW
],
375 MIGRATION_NEW
=> [ MIGRATION_WRITE_BOTH
, MIGRATION_WRITE_NEW
, MIGRATION_NEW
],
378 foreach ( $stages as $writeStage => $possibleReadStages ) {
379 if ( $key === 'ipb_reason' ) {
380 $extraFields['ipb_address'] = __CLASS__
. "#$writeStage";
383 $wstore = $this->makeStore( $writeStage );
384 $usesTemp = $key === 'rev_comment';
387 list( $fields, $callback ) = $wstore->insertWithTempTable(
388 $this->db
, $key, $comment, $data
391 $fields = $wstore->insert( $this->db
, $key, $comment, $data );
394 if ( $writeStage <= MIGRATION_WRITE_BOTH
) {
395 $this->assertSame( $expect['text'], $fields[$key], "old field, stage=$writeStage" );
397 $this->assertArrayNotHasKey( $key, $fields, "old field, stage=$writeStage" );
399 if ( $writeStage >= MIGRATION_WRITE_BOTH
&& !$usesTemp ) {
400 $this->assertArrayHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
402 $this->assertArrayNotHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
405 $this->db
->insert( $table, $extraFields +
$fields, __METHOD__
);
406 $id = $this->db
->insertId();
411 foreach ( $possibleReadStages as $readStage ) {
412 $rstore = $this->makeStore( $readStage );
414 $fieldRow = $this->db
->selectRow(
416 $rstore->getFields( $key ),
421 $queryInfo = $rstore->getJoin( $key );
422 $joinRow = $this->db
->selectRow(
423 [ $table ] +
$queryInfo['tables'],
424 $queryInfo['fields'],
431 $this->assertComment(
432 $writeStage === MIGRATION_OLD ||
$readStage === MIGRATION_OLD ?
$expectOld : $expect,
433 $rstore->getCommentLegacy( $this->db
, $key, $fieldRow ),
434 "w=$writeStage, r=$readStage, from getFields()"
436 $this->assertComment(
437 $writeStage === MIGRATION_OLD ||
$readStage === MIGRATION_OLD ?
$expectOld : $expect,
438 $rstore->getComment( $key, $joinRow ),
439 "w=$writeStage, r=$readStage, from getJoin()"
446 * @dataProvider provideInsertRoundTrip
447 * @param string $table
450 * @param string $extraFields
451 * @param string|Message $comment
452 * @param array|null $data
453 * @param array $expect
455 public function testInsertRoundTrip_withKeyConstruction(
456 $table, $key, $pk, $extraFields, $comment, $data, $expect
459 'text' => $expect['text'],
460 'message' => new RawMessage( '$1', [ $expect['text'] ] ),
465 MIGRATION_OLD
=> [ MIGRATION_OLD
, MIGRATION_WRITE_BOTH
, MIGRATION_WRITE_NEW
],
466 MIGRATION_WRITE_BOTH
=> [ MIGRATION_OLD
, MIGRATION_WRITE_BOTH
, MIGRATION_WRITE_NEW
,
468 MIGRATION_WRITE_NEW
=> [ MIGRATION_WRITE_BOTH
, MIGRATION_WRITE_NEW
, MIGRATION_NEW
],
469 MIGRATION_NEW
=> [ MIGRATION_WRITE_BOTH
, MIGRATION_WRITE_NEW
, MIGRATION_NEW
],
472 foreach ( $stages as $writeStage => $possibleReadStages ) {
473 if ( $key === 'ipb_reason' ) {
474 $extraFields['ipb_address'] = __CLASS__
. "#$writeStage";
477 $wstore = $this->makeStoreWithKey( $writeStage, $key );
478 $usesTemp = $key === 'rev_comment';
481 list( $fields, $callback ) = $wstore->insertWithTempTable(
482 $this->db
, $comment, $data
485 $fields = $wstore->insert( $this->db
, $comment, $data );
488 if ( $writeStage <= MIGRATION_WRITE_BOTH
) {
489 $this->assertSame( $expect['text'], $fields[$key], "old field, stage=$writeStage" );
491 $this->assertArrayNotHasKey( $key, $fields, "old field, stage=$writeStage" );
493 if ( $writeStage >= MIGRATION_WRITE_BOTH
&& !$usesTemp ) {
494 $this->assertArrayHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
496 $this->assertArrayNotHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
499 $this->db
->insert( $table, $extraFields +
$fields, __METHOD__
);
500 $id = $this->db
->insertId();
505 foreach ( $possibleReadStages as $readStage ) {
506 $rstore = $this->makeStoreWithKey( $readStage, $key );
508 $fieldRow = $this->db
->selectRow(
510 $rstore->getFields(),
515 $queryInfo = $rstore->getJoin();
516 $joinRow = $this->db
->selectRow(
517 [ $table ] +
$queryInfo['tables'],
518 $queryInfo['fields'],
525 $this->assertComment(
526 $writeStage === MIGRATION_OLD ||
$readStage === MIGRATION_OLD ?
$expectOld : $expect,
527 $rstore->getCommentLegacy( $this->db
, $fieldRow ),
528 "w=$writeStage, r=$readStage, from getFields()"
530 $this->assertComment(
531 $writeStage === MIGRATION_OLD ||
$readStage === MIGRATION_OLD ?
$expectOld : $expect,
532 $rstore->getComment( $joinRow ),
533 "w=$writeStage, r=$readStage, from getJoin()"
539 public static function provideInsertRoundTrip() {
540 $db = wfGetDB( DB_REPLICA
); // for timestamps
542 $msgComment = new Message( 'parentheses', [ 'message comment' ] );
543 $textCommentMsg = new RawMessage( '$1', [ 'text comment' ] );
544 $nestedMsgComment = new Message( [ 'parentheses', 'rawmessage' ], [ new Message( 'mainpage' ) ] );
546 'ipb_range_start' => '',
547 'ipb_range_end' => '',
548 'ipb_timestamp' => $db->timestamp(),
549 'ipb_expiry' => $db->getInfinity(),
555 'rev_timestamp' => $db->timestamp(),
557 $comStoreComment = new CommentStoreComment(
558 null, 'comment store comment', null, [ 'foo' => 'bar' ]
562 'Simple table, text comment' => [
563 'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, 'text comment', null, [
564 'text' => 'text comment',
565 'message' => $textCommentMsg,
569 'Simple table, text comment with data' => [
570 'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, 'text comment', [ 'message' => 42 ], [
571 'text' => 'text comment',
572 'message' => $textCommentMsg,
573 'data' => [ 'message' => 42 ],
576 'Simple table, message comment' => [
577 'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, $msgComment, null, [
578 'text' => '(message comment)',
579 'message' => $msgComment,
583 'Simple table, message comment with data' => [
584 'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, $msgComment, [ 'message' => 42 ], [
585 'text' => '(message comment)',
586 'message' => $msgComment,
587 'data' => [ 'message' => 42 ],
590 'Simple table, nested message comment' => [
591 'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, $nestedMsgComment, null, [
592 'text' => '(Main Page)',
593 'message' => $nestedMsgComment,
597 'Simple table, CommentStoreComment' => [
598 'ipblocks', 'ipb_reason', 'ipb_id', $ipbfields, clone $comStoreComment, [ 'baz' => 'baz' ], [
599 'text' => 'comment store comment',
600 'message' => $comStoreComment->message
,
601 'data' => [ 'foo' => 'bar' ],
605 'Revision, text comment' => [
606 'revision', 'rev_comment', 'rev_id', $revfields, 'text comment', null, [
607 'text' => 'text comment',
608 'message' => $textCommentMsg,
612 'Revision, text comment with data' => [
613 'revision', 'rev_comment', 'rev_id', $revfields, 'text comment', [ 'message' => 42 ], [
614 'text' => 'text comment',
615 'message' => $textCommentMsg,
616 'data' => [ 'message' => 42 ],
619 'Revision, message comment' => [
620 'revision', 'rev_comment', 'rev_id', $revfields, $msgComment, null, [
621 'text' => '(message comment)',
622 'message' => $msgComment,
626 'Revision, message comment with data' => [
627 'revision', 'rev_comment', 'rev_id', $revfields, $msgComment, [ 'message' => 42 ], [
628 'text' => '(message comment)',
629 'message' => $msgComment,
630 'data' => [ 'message' => 42 ],
633 'Revision, nested message comment' => [
634 'revision', 'rev_comment', 'rev_id', $revfields, $nestedMsgComment, null, [
635 'text' => '(Main Page)',
636 'message' => $nestedMsgComment,
640 'Revision, CommentStoreComment' => [
641 'revision', 'rev_comment', 'rev_id', $revfields, clone $comStoreComment, [ 'baz' => 'baz' ], [
642 'text' => 'comment store comment',
643 'message' => $comStoreComment->message
,
644 'data' => [ 'foo' => 'bar' ],
650 public function testGetCommentErrors() {
651 Wikimedia\
suppressWarnings();
652 $reset = new ScopedCallback( 'Wikimedia\restoreWarnings' );
654 $store = $this->makeStore( MIGRATION_OLD
);
655 $res = $store->getComment( 'dummy', [ 'dummy' => 'comment' ] );
656 $this->assertSame( '', $res->text
);
657 $res = $store->getComment( 'dummy', [ 'dummy' => 'comment' ], true );
658 $this->assertSame( 'comment', $res->text
);
660 $store = $this->makeStore( MIGRATION_NEW
);
662 $store->getComment( 'dummy', [ 'dummy' => 'comment' ] );
663 $this->fail( 'Expected exception not thrown' );
664 } catch ( InvalidArgumentException
$ex ) {
665 $this->assertSame( '$row does not contain fields needed for comment dummy', $ex->getMessage() );
667 $res = $store->getComment( 'dummy', [ 'dummy' => 'comment' ], true );
668 $this->assertSame( 'comment', $res->text
);
670 $store->getComment( 'dummy', [ 'dummy_id' => 1 ] );
671 $this->fail( 'Expected exception not thrown' );
672 } catch ( InvalidArgumentException
$ex ) {
674 '$row does not contain fields needed for comment dummy and getComment(), '
675 . 'but does have fields for getCommentLegacy()',
680 $store = $this->makeStore( MIGRATION_NEW
);
682 $store->getComment( 'rev_comment', [ 'rev_comment' => 'comment' ] );
683 $this->fail( 'Expected exception not thrown' );
684 } catch ( InvalidArgumentException
$ex ) {
686 '$row does not contain fields needed for comment rev_comment', $ex->getMessage()
689 $res = $store->getComment( 'rev_comment', [ 'rev_comment' => 'comment' ], true );
690 $this->assertSame( 'comment', $res->text
);
692 $store->getComment( 'rev_comment', [ 'rev_comment_pk' => 1 ] );
693 $this->fail( 'Expected exception not thrown' );
694 } catch ( InvalidArgumentException
$ex ) {
696 '$row does not contain fields needed for comment rev_comment and getComment(), '
697 . 'but does have fields for getCommentLegacy()',
703 public static function provideStages() {
705 'MIGRATION_OLD' => [ MIGRATION_OLD
],
706 'MIGRATION_WRITE_BOTH' => [ MIGRATION_WRITE_BOTH
],
707 'MIGRATION_WRITE_NEW' => [ MIGRATION_WRITE_NEW
],
708 'MIGRATION_NEW' => [ MIGRATION_NEW
],
713 * @dataProvider provideStages
715 * @expectedException InvalidArgumentException
716 * @expectedExceptionMessage Must use insertWithTempTable() for rev_comment
718 public function testInsertWrong( $stage ) {
719 $store = $this->makeStore( $stage );
720 $store->insert( $this->db
, 'rev_comment', 'foo' );
724 * @dataProvider provideStages
726 * @expectedException InvalidArgumentException
727 * @expectedExceptionMessage Must use insert() for ipb_reason
729 public function testInsertWithTempTableWrong( $stage ) {
730 $store = $this->makeStore( $stage );
731 $store->insertWithTempTable( $this->db
, 'ipb_reason', 'foo' );
735 * @dataProvider provideStages
738 public function testInsertWithTempTableDeprecated( $stage ) {
739 $wrap = TestingAccessWrapper
::newFromClass( CommentStore
::class );
740 $wrap->formerTempTables +
= [ 'ipb_reason' => '1.30' ];
742 $this->hideDeprecated( 'CommentStore::insertWithTempTable for ipb_reason' );
743 $store = $this->makeStore( $stage );
744 list( $fields, $callback ) = $store->insertWithTempTable( $this->db
, 'ipb_reason', 'foo' );
745 $this->assertTrue( is_callable( $callback ) );
748 public function testInsertTruncation() {
749 $comment = str_repeat( '💣', 16400 );
750 $truncated1 = str_repeat( '💣', 63 ) . '...';
751 $truncated2 = str_repeat( '💣', CommentStore
::COMMENT_CHARACTER_LIMIT
- 3 ) . '...';
753 $store = $this->makeStore( MIGRATION_WRITE_BOTH
);
754 $fields = $store->insert( $this->db
, 'ipb_reason', $comment );
755 $this->assertSame( $truncated1, $fields['ipb_reason'] );
756 $stored = $this->db
->selectField(
757 'comment', 'comment_text', [ 'comment_id' => $fields['ipb_reason_id'] ], __METHOD__
759 $this->assertSame( $truncated2, $stored );
763 * @expectedException OverflowException
764 * @expectedExceptionMessage Comment data is too long (65611 bytes, maximum is 65535)
766 public function testInsertTooMuchData() {
767 $store = $this->makeStore( MIGRATION_WRITE_BOTH
);
768 $store->insert( $this->db
, 'ipb_reason', 'foo', [
769 'long' => str_repeat( '💣', 16400 )
773 public function testGetStore() {
774 $this->assertInstanceOf( CommentStore
::class, CommentStore
::getStore() );
777 public function testNewKey() {
778 $this->hideDeprecated( 'CommentStore::newKey' );
779 $this->assertInstanceOf( CommentStore
::class, CommentStore
::newKey( 'dummy' ) );