Merge "Prevent write operations to database replicas."
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionTest.php
index 3d0556e..e4ea40f 100644 (file)
@@ -20,6 +20,35 @@ class RevisionTest extends MediaWikiTestCase {
                                'content' => new JavaScriptContent( 'hellow world.' )
                        ],
                ];
+               // FIXME: test with and without user ID, and with a user object.
+               // We can't prepare that here though, since we don't yet have a dummy DB
+       }
+
+       /**
+        * @param string $model
+        * @return Title
+        */
+       public function getMockTitle( $model = CONTENT_MODEL_WIKITEXT ) {
+               $mock = $this->getMockBuilder( Title::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $mock->expects( $this->any() )
+                       ->method( 'getNamespace' )
+                       ->will( $this->returnValue( $this->getDefaultWikitextNS() ) );
+               $mock->expects( $this->any() )
+                       ->method( 'getPrefixedText' )
+                       ->will( $this->returnValue( 'RevisionTest' ) );
+               $mock->expects( $this->any() )
+                       ->method( 'getDBKey' )
+                       ->will( $this->returnValue( 'RevisionTest' ) );
+               $mock->expects( $this->any() )
+                       ->method( 'getArticleID' )
+                       ->will( $this->returnValue( 23 ) );
+               $mock->expects( $this->any() )
+                       ->method( 'getModel' )
+                       ->will( $this->returnValue( $model ) );
+
+               return $mock;
        }
 
        /**
@@ -34,6 +63,15 @@ class RevisionTest extends MediaWikiTestCase {
                $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
        }
 
+       /**
+        * @covers Revision::__construct
+        * @covers Revision::constructFromRowArray
+        */
+       public function testConstructFromEmptyArray() {
+               $rev = new Revision( [], 0, $this->getMockTitle() );
+               $this->assertNull( $rev->getContent(), 'no content object should be available' );
+       }
+
        public function provideConstructFromArray_userSetAsExpected() {
                yield 'no user defaults to wgUser' => [
                        [
@@ -137,6 +175,15 @@ class RevisionTest extends MediaWikiTestCase {
                new Revision( $rowArray );
        }
 
+       /**
+        * @covers Revision::__construct
+        * @covers Revision::constructFromRowArray
+        */
+       public function testConstructFromNothing() {
+               $rev = new Revision( [] );
+               $this->assertNull( $rev->getId(), 'getId()' );
+       }
+
        public function provideConstructFromRow() {
                yield 'Full construction' => [
                        [
@@ -201,7 +248,7 @@ class RevisionTest extends MediaWikiTestCase {
        /**
         * @dataProvider provideConstructFromRow
         * @covers Revision::__construct
-        * @covers Revision::constructFromDbRowObject
+        * @covers Revision::constructFromRowArray
         */
        public function testConstructFromRow( array $arrayData, $assertions ) {
                $row = (object)$arrayData;
@@ -491,25 +538,25 @@ class RevisionTest extends MediaWikiTestCase {
                ];
                yield '(ISO-8859-1 encoding), string in string out' => [
                        'ISO-8859-1',
-                       iconv( 'utf8', 'ISO-8859-1', "1®Àþ1" ),
+                       iconv( 'utf-8', 'ISO-8859-1', "1®Àþ1" ),
                        [],
                        '1®Àþ1',
                ];
                yield '(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [
                        'ISO-8859-1',
-                       gzdeflate( iconv( 'utf8', 'ISO-8859-1', "4®Àþ4" ) ),
+                       gzdeflate( iconv( 'utf-8', 'ISO-8859-1', "4®Àþ4" ) ),
                        [ 'gzip' ],
                        '4®Àþ4',
                ];
                yield '(ISO-8859-1 encoding), serialized object in with object flags returns string' => [
                        'ISO-8859-1',
-                       serialize( new TitleValue( 0, iconv( 'utf8', 'ISO-8859-1', "3®Àþ3" ) ) ),
+                       serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "3®Àþ3" ) ) ),
                        [ 'object' ],
                        '3®Àþ3',
                ];
                yield '(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [
                        'ISO-8859-1',
-                       gzdeflate( serialize( new TitleValue( 0, iconv( 'utf8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
+                       gzdeflate( serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
                        [ 'gzip', 'object' ],
                        '2®Àþ2',
                ];