3 use Wikimedia\ScopedCallback
;
4 use Wikimedia\TestingAccessWrapper
;
9 * @covers CommentStoreComment
11 class CommentStoreTest
extends MediaWikiLangTestCase
{
13 protected $tablesUsed = [
15 'revision_comment_temp',
21 * Create a store for a particular stage
23 * @return CommentStore
25 protected function makeStore( $stage ) {
27 $store = new CommentStore( $wgContLang, $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 $store = CommentStore
::newKey( $key );
39 TestingAccessWrapper
::newFromObject( $store )->stage
= $stage;
44 * @dataProvider provideGetFields
47 * @param array $expect
49 public function testGetFields_withKeyConstruction( $stage, $key, $expect ) {
50 $store = $this->makeStoreWithKey( $stage, $key );
51 $result = $store->getFields();
52 $this->assertEquals( $expect, $result );
56 * @dataProvider provideGetFields
59 * @param array $expect
61 public function testGetFields( $stage, $key, $expect ) {
62 $store = $this->makeStore( $stage );
63 $result = $store->getFields( $key );
64 $this->assertEquals( $expect, $result );
67 public static function provideGetFields() {
69 'Simple table, old' => [
70 MIGRATION_OLD
, 'ipb_reason',
71 [ 'ipb_reason_text' => 'ipb_reason', 'ipb_reason_data' => 'NULL', 'ipb_reason_cid' => 'NULL' ],
73 'Simple table, write-both' => [
74 MIGRATION_WRITE_BOTH
, 'ipb_reason',
75 [ 'ipb_reason_old' => 'ipb_reason', 'ipb_reason_id' => 'ipb_reason_id' ],
77 'Simple table, write-new' => [
78 MIGRATION_WRITE_NEW
, 'ipb_reason',
79 [ 'ipb_reason_old' => 'ipb_reason', 'ipb_reason_id' => 'ipb_reason_id' ],
81 'Simple table, new' => [
82 MIGRATION_NEW
, 'ipb_reason',
83 [ 'ipb_reason_id' => 'ipb_reason_id' ],
87 MIGRATION_OLD
, 'rev_comment',
89 'rev_comment_text' => 'rev_comment',
90 'rev_comment_data' => 'NULL',
91 'rev_comment_cid' => 'NULL',
94 'Revision, write-both' => [
95 MIGRATION_WRITE_BOTH
, 'rev_comment',
96 [ 'rev_comment_old' => 'rev_comment', 'rev_comment_pk' => 'rev_id' ],
98 'Revision, write-new' => [
99 MIGRATION_WRITE_NEW
, 'rev_comment',
100 [ 'rev_comment_old' => 'rev_comment', 'rev_comment_pk' => 'rev_id' ],
103 MIGRATION_NEW
, 'rev_comment',
104 [ 'rev_comment_pk' => 'rev_id' ],
108 MIGRATION_OLD
, 'img_description',
110 'img_description_text' => 'img_description',
111 'img_description_data' => 'NULL',
112 'img_description_cid' => 'NULL',
115 'Image, write-both' => [
116 MIGRATION_WRITE_BOTH
, 'img_description',
117 [ 'img_description_old' => 'img_description', 'img_description_pk' => 'img_name' ],
119 'Image, write-new' => [
120 MIGRATION_WRITE_NEW
, 'img_description',
121 [ 'img_description_old' => 'img_description', 'img_description_pk' => 'img_name' ],
124 MIGRATION_NEW
, 'img_description',
125 [ 'img_description_pk' => 'img_name' ],
131 * @dataProvider provideGetJoin
134 * @param array $expect
136 public function testGetJoin_withKeyConstruction( $stage, $key, $expect ) {
137 $store = $this->makeStoreWithKey( $stage, $key );
138 $result = $store->getJoin();
139 $this->assertEquals( $expect, $result );
143 * @dataProvider provideGetJoin
146 * @param array $expect
148 public function testGetJoin( $stage, $key, $expect ) {
149 $store = $this->makeStore( $stage );
150 $result = $store->getJoin( $key );
151 $this->assertEquals( $expect, $result );
154 public static function provideGetJoin() {
156 'Simple table, old' => [
157 MIGRATION_OLD
, 'ipb_reason', [
160 'ipb_reason_text' => 'ipb_reason',
161 'ipb_reason_data' => 'NULL',
162 'ipb_reason_cid' => 'NULL',
167 'Simple table, write-both' => [
168 MIGRATION_WRITE_BOTH
, 'ipb_reason', [
169 'tables' => [ 'comment_ipb_reason' => 'comment' ],
171 'ipb_reason_text' => 'COALESCE( comment_ipb_reason.comment_text, ipb_reason )',
172 'ipb_reason_data' => 'comment_ipb_reason.comment_data',
173 'ipb_reason_cid' => 'comment_ipb_reason.comment_id',
176 'comment_ipb_reason' => [ 'LEFT JOIN', 'comment_ipb_reason.comment_id = ipb_reason_id' ],
180 'Simple table, write-new' => [
181 MIGRATION_WRITE_NEW
, 'ipb_reason', [
182 'tables' => [ 'comment_ipb_reason' => 'comment' ],
184 'ipb_reason_text' => 'COALESCE( comment_ipb_reason.comment_text, ipb_reason )',
185 'ipb_reason_data' => 'comment_ipb_reason.comment_data',
186 'ipb_reason_cid' => 'comment_ipb_reason.comment_id',
189 'comment_ipb_reason' => [ 'LEFT JOIN', 'comment_ipb_reason.comment_id = ipb_reason_id' ],
193 'Simple table, new' => [
194 MIGRATION_NEW
, 'ipb_reason', [
195 'tables' => [ 'comment_ipb_reason' => 'comment' ],
197 'ipb_reason_text' => 'comment_ipb_reason.comment_text',
198 'ipb_reason_data' => 'comment_ipb_reason.comment_data',
199 'ipb_reason_cid' => 'comment_ipb_reason.comment_id',
202 'comment_ipb_reason' => [ 'JOIN', 'comment_ipb_reason.comment_id = ipb_reason_id' ],
208 MIGRATION_OLD
, 'rev_comment', [
211 'rev_comment_text' => 'rev_comment',
212 'rev_comment_data' => 'NULL',
213 'rev_comment_cid' => 'NULL',
218 'Revision, write-both' => [
219 MIGRATION_WRITE_BOTH
, 'rev_comment', [
221 'temp_rev_comment' => 'revision_comment_temp',
222 'comment_rev_comment' => 'comment',
225 'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
226 'rev_comment_data' => 'comment_rev_comment.comment_data',
227 'rev_comment_cid' => 'comment_rev_comment.comment_id',
230 'temp_rev_comment' => [ 'LEFT JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
231 'comment_rev_comment' => [ 'LEFT JOIN',
232 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
236 'Revision, write-new' => [
237 MIGRATION_WRITE_NEW
, 'rev_comment', [
239 'temp_rev_comment' => 'revision_comment_temp',
240 'comment_rev_comment' => 'comment',
243 'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
244 'rev_comment_data' => 'comment_rev_comment.comment_data',
245 'rev_comment_cid' => 'comment_rev_comment.comment_id',
248 'temp_rev_comment' => [ 'LEFT JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
249 'comment_rev_comment' => [ 'LEFT JOIN',
250 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
255 MIGRATION_NEW
, 'rev_comment', [
257 'temp_rev_comment' => 'revision_comment_temp',
258 'comment_rev_comment' => 'comment',
261 'rev_comment_text' => 'comment_rev_comment.comment_text',
262 'rev_comment_data' => 'comment_rev_comment.comment_data',
263 'rev_comment_cid' => 'comment_rev_comment.comment_id',
266 'temp_rev_comment' => [ 'JOIN', 'temp_rev_comment.revcomment_rev = rev_id' ],
267 'comment_rev_comment' => [ 'JOIN',
268 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id' ],
274 MIGRATION_OLD
, 'img_description', [
277 'img_description_text' => 'img_description',
278 'img_description_data' => 'NULL',
279 'img_description_cid' => 'NULL',
284 'Image, write-both' => [
285 MIGRATION_WRITE_BOTH
, 'img_description', [
287 'temp_img_description' => 'image_comment_temp',
288 'comment_img_description' => 'comment',
291 'img_description_text' => 'COALESCE( comment_img_description.comment_text, img_description )',
292 'img_description_data' => 'comment_img_description.comment_data',
293 'img_description_cid' => 'comment_img_description.comment_id',
296 'temp_img_description' => [ 'LEFT JOIN', 'temp_img_description.imgcomment_name = img_name' ],
297 'comment_img_description' => [ 'LEFT JOIN',
298 'comment_img_description.comment_id = temp_img_description.imgcomment_description_id' ],
302 'Image, write-new' => [
303 MIGRATION_WRITE_NEW
, 'img_description', [
305 'temp_img_description' => 'image_comment_temp',
306 'comment_img_description' => 'comment',
309 'img_description_text' => 'COALESCE( comment_img_description.comment_text, img_description )',
310 'img_description_data' => 'comment_img_description.comment_data',
311 'img_description_cid' => 'comment_img_description.comment_id',
314 'temp_img_description' => [ 'LEFT JOIN', 'temp_img_description.imgcomment_name = img_name' ],
315 'comment_img_description' => [ 'LEFT JOIN',
316 'comment_img_description.comment_id = temp_img_description.imgcomment_description_id' ],
321 MIGRATION_NEW
, 'img_description', [
323 'temp_img_description' => 'image_comment_temp',
324 'comment_img_description' => 'comment',
327 'img_description_text' => 'comment_img_description.comment_text',
328 'img_description_data' => 'comment_img_description.comment_data',
329 'img_description_cid' => 'comment_img_description.comment_id',
332 'temp_img_description' => [ 'JOIN', 'temp_img_description.imgcomment_name = img_name' ],
333 'comment_img_description' => [ 'JOIN',
334 'comment_img_description.comment_id = temp_img_description.imgcomment_description_id' ],
341 private function assertComment( $expect, $actual, $from ) {
342 $this->assertSame( $expect['text'], $actual->text
, "text $from" );
343 $this->assertInstanceOf( get_class( $expect['message'] ), $actual->message
,
344 "message class $from" );
345 $this->assertSame( $expect['message']->getKeysToTry(), $actual->message
->getKeysToTry(),
346 "message keys $from" );
347 $this->assertEquals( $expect['message']->text(), $actual->message
->text(),
348 "message rendering $from" );
349 $this->assertEquals( $expect['data'], $actual->data
, "data $from" );
353 * @dataProvider provideInsertRoundTrip
354 * @param string $table
357 * @param string $extraFields
358 * @param string|Message $comment
359 * @param array|null $data
360 * @param array $expect
362 public function testInsertRoundTrip( $table, $key, $pk, $extraFields, $comment, $data, $expect ) {
364 'text' => $expect['text'],
365 'message' => new RawMessage( '$1', [ $expect['text'] ] ),
370 MIGRATION_OLD
=> [ MIGRATION_OLD
, MIGRATION_WRITE_NEW
],
371 MIGRATION_WRITE_BOTH
=> [ MIGRATION_OLD
, MIGRATION_NEW
],
372 MIGRATION_WRITE_NEW
=> [ MIGRATION_WRITE_BOTH
, MIGRATION_NEW
],
373 MIGRATION_NEW
=> [ MIGRATION_WRITE_BOTH
, MIGRATION_NEW
],
376 foreach ( $stages as $writeStage => $readRange ) {
377 if ( $key === 'ipb_reason' ) {
378 $extraFields['ipb_address'] = __CLASS__
. "#$writeStage";
381 $wstore = $this->makeStore( $writeStage );
382 $usesTemp = $key === 'rev_comment';
385 list( $fields, $callback ) = $wstore->insertWithTempTable(
386 $this->db
, $key, $comment, $data
389 $fields = $wstore->insert( $this->db
, $key, $comment, $data );
392 if ( $writeStage <= MIGRATION_WRITE_BOTH
) {
393 $this->assertSame( $expect['text'], $fields[$key], "old field, stage=$writeStage" );
395 $this->assertArrayNotHasKey( $key, $fields, "old field, stage=$writeStage" );
397 if ( $writeStage >= MIGRATION_WRITE_BOTH
&& !$usesTemp ) {
398 $this->assertArrayHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
400 $this->assertArrayNotHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
403 $this->db
->insert( $table, $extraFields +
$fields, __METHOD__
);
404 $id = $this->db
->insertId();
409 for ( $readStage = $readRange[0]; $readStage <= $readRange[1]; $readStage++
) {
410 $rstore = $this->makeStore( $readStage );
412 $fieldRow = $this->db
->selectRow(
414 $rstore->getFields( $key ),
419 $queryInfo = $rstore->getJoin( $key );
420 $joinRow = $this->db
->selectRow(
421 [ $table ] +
$queryInfo['tables'],
422 $queryInfo['fields'],
429 $this->assertComment(
430 $writeStage === MIGRATION_OLD ||
$readStage === MIGRATION_OLD ?
$expectOld : $expect,
431 $rstore->getCommentLegacy( $this->db
, $key, $fieldRow ),
432 "w=$writeStage, r=$readStage, from getFields()"
434 $this->assertComment(
435 $writeStage === MIGRATION_OLD ||
$readStage === MIGRATION_OLD ?
$expectOld : $expect,
436 $rstore->getComment( $key, $joinRow ),
437 "w=$writeStage, r=$readStage, from getJoin()"
444 * @dataProvider provideInsertRoundTrip
445 * @param string $table
448 * @param string $extraFields
449 * @param string|Message $comment
450 * @param array|null $data
451 * @param array $expect
453 public function testInsertRoundTrip_withKeyConstruction(
454 $table, $key, $pk, $extraFields, $comment, $data, $expect
457 'text' => $expect['text'],
458 'message' => new RawMessage( '$1', [ $expect['text'] ] ),
463 MIGRATION_OLD
=> [ MIGRATION_OLD
, MIGRATION_WRITE_NEW
],
464 MIGRATION_WRITE_BOTH
=> [ MIGRATION_OLD
, MIGRATION_NEW
],
465 MIGRATION_WRITE_NEW
=> [ MIGRATION_WRITE_BOTH
, MIGRATION_NEW
],
466 MIGRATION_NEW
=> [ MIGRATION_WRITE_BOTH
, MIGRATION_NEW
],
469 foreach ( $stages as $writeStage => $readRange ) {
470 if ( $key === 'ipb_reason' ) {
471 $extraFields['ipb_address'] = __CLASS__
. "#$writeStage";
474 $wstore = $this->makeStoreWithKey( $writeStage, $key );
475 $usesTemp = $key === 'rev_comment';
478 list( $fields, $callback ) = $wstore->insertWithTempTable(
479 $this->db
, $comment, $data
482 $fields = $wstore->insert( $this->db
, $comment, $data );
485 if ( $writeStage <= MIGRATION_WRITE_BOTH
) {
486 $this->assertSame( $expect['text'], $fields[$key], "old field, stage=$writeStage" );
488 $this->assertArrayNotHasKey( $key, $fields, "old field, stage=$writeStage" );
490 if ( $writeStage >= MIGRATION_WRITE_BOTH
&& !$usesTemp ) {
491 $this->assertArrayHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
493 $this->assertArrayNotHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" );
496 $this->db
->insert( $table, $extraFields +
$fields, __METHOD__
);
497 $id = $this->db
->insertId();
502 for ( $readStage = $readRange[0]; $readStage <= $readRange[1]; $readStage++
) {
503 $rstore = $this->makeStoreWithKey( $readStage, $key );
505 $fieldRow = $this->db
->selectRow(
507 $rstore->getFields(),
512 $queryInfo = $rstore->getJoin();
513 $joinRow = $this->db
->selectRow(
514 [ $table ] +
$queryInfo['tables'],
515 $queryInfo['fields'],
522 $this->assertComment(
523 $writeStage === MIGRATION_OLD ||
$readStage === MIGRATION_OLD ?
$expectOld : $expect,
524 $rstore->getCommentLegacy( $this->db
, $fieldRow ),
525 "w=$writeStage, r=$readStage, from getFields()"
527 $this->assertComment(
528 $writeStage === MIGRATION_OLD ||
$readStage === MIGRATION_OLD ?
$expectOld : $expect,
529 $rstore->getComment( $joinRow ),
530 "w=$writeStage, r=$readStage, from getJoin()"
536 public static function provideInsertRoundTrip() {
537 $db = wfGetDB( DB_REPLICA
); // for timestamps
539 $msgComment = new Message( 'parentheses', [ 'message comment' ] );
540 $textCommentMsg = new RawMessage( '$1', [ 'text comment' ] );
541 $nestedMsgComment = new Message( [ 'parentheses', 'rawmessage' ], [ new Message( 'mainpage' ) ] );
543 'ipb_range_start' => '',
544 'ipb_range_end' => '',
546 'ipb_timestamp' => $db->timestamp(),
547 'ipb_expiry' => $db->getInfinity(),
554 'rev_user_text' => '',
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->assertInstanceOf( CommentStore
::class, CommentStore
::newKey( 'dummy' ) );