tests: Complete test coverage of HtmlArmor
[lhc/web/wiklou.git] / tests / phpunit / includes / CommentStoreTest.php
index 6dd0925..9369f30 100644 (file)
@@ -404,17 +404,25 @@ class CommentStoreTest extends MediaWikiLangTestCase {
        }
 
        public static function provideInsertRoundTrip() {
+               $db = wfGetDB( DB_REPLICA ); // for timestamps
+
                $msgComment = new Message( 'parentheses', [ 'message comment' ] );
                $textCommentMsg = new RawMessage( '$1', [ 'text comment' ] );
                $nestedMsgComment = new Message( [ 'parentheses', 'rawmessage' ], [ new Message( 'mainpage' ) ] );
                $ipbfields = [
                        'ipb_range_start' => '',
                        'ipb_range_end' => '',
+                       'ipb_by' => 0,
+                       'ipb_timestamp' => $db->timestamp(),
+                       'ipb_expiry' => $db->getInfinity(),
                ];
                $revfields = [
                        'rev_page' => 42,
                        'rev_text_id' => 42,
                        'rev_len' => 0,
+                       'rev_user' => 0,
+                       'rev_user_text' => '',
+                       'rev_timestamp' => $db->timestamp(),
                ];
                $comStoreComment = new CommentStoreComment(
                        null, 'comment store comment', null, [ 'foo' => 'bar' ]
@@ -607,6 +615,31 @@ class CommentStoreTest extends MediaWikiLangTestCase {
                $this->assertTrue( is_callable( $callback ) );
        }
 
+       public function testInsertTruncation() {
+               $comment = str_repeat( '💣', 16400 );
+               $truncated1 = str_repeat( '💣', 63 ) . '...';
+               $truncated2 = str_repeat( '💣', CommentStore::COMMENT_CHARACTER_LIMIT - 3 ) . '...';
+
+               $store = $this->makeStore( MIGRATION_WRITE_BOTH, 'ipb_reason' );
+               $fields = $store->insert( $this->db, $comment );
+               $this->assertSame( $truncated1, $fields['ipb_reason'] );
+               $stored = $this->db->selectField(
+                       'comment', 'comment_text', [ 'comment_id' => $fields['ipb_reason_id'] ], __METHOD__
+               );
+               $this->assertSame( $truncated2, $stored );
+       }
+
+       /**
+        * @expectedException OverflowException
+        * @expectedExceptionMessage Comment data is too long (65611 bytes, maximum is 65535)
+        */
+       public function testInsertTooMuchData() {
+               $store = $this->makeStore( MIGRATION_WRITE_BOTH, 'ipb_reason' );
+               $store->insert( $this->db, 'foo', [
+                       'long' => str_repeat( '💣', 16400 )
+               ] );
+       }
+
        public function testConstructor() {
                $this->assertInstanceOf( CommentStore::class, CommentStore::newKey( 'dummy' ) );
        }