Drop strings for wgExternalDiffEngine, deprecated in 1.27 and 1.32
[lhc/web/wiklou.git] / tests / phpunit / includes / diff / DifferenceEngineTest.php
index 3336235..46eaaea 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 
-use MediaWiki\Storage\MutableRevisionRecord;
-use MediaWiki\Storage\RevisionRecord;
-use MediaWiki\Storage\SlotRecord;
+use MediaWiki\Revision\MutableRevisionRecord;
+use MediaWiki\Revision\RevisionRecord;
+use MediaWiki\Revision\SlotRecord;
 use Wikimedia\TestingAccessWrapper;
 
 /**
@@ -157,25 +157,22 @@ class DifferenceEngineTest extends MediaWikiTestCase {
         * @dataProvider provideGenerateContentDiffBody
         */
        public function testGenerateContentDiffBody(
-               Content $oldContent, Content $newContent, $expectedDiff
+               array $oldContentArgs, array $newContentArgs, $expectedDiff
        ) {
-               // Set $wgExternalDiffEngine to something bogus to try to force use of
-               // the PHP engine rather than wikidiff2.
-               $this->setMwGlobals( [
-                       'wgExternalDiffEngine' => '/dev/null',
+               $this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
+                       'testing-nontext' => DummyNonTextContentHandler::class,
                ] );
+               $oldContent = ContentHandler::makeContent( ...$oldContentArgs );
+               $newContent = ContentHandler::makeContent( ...$newContentArgs );
 
                $differenceEngine = new DifferenceEngine();
                $diff = $differenceEngine->generateContentDiffBody( $oldContent, $newContent );
                $this->assertSame( $expectedDiff, $this->getPlainDiff( $diff ) );
        }
 
-       public function provideGenerateContentDiffBody() {
-               $this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
-                       'testing-nontext' => DummyNonTextContentHandler::class,
-               ] );
-               $content1 = ContentHandler::makeContent( 'xxx', null, CONTENT_MODEL_TEXT );
-               $content2 = ContentHandler::makeContent( 'yyy', null, CONTENT_MODEL_TEXT );
+       public static function provideGenerateContentDiffBody() {
+               $content1 = [ 'xxx', null, CONTENT_MODEL_TEXT ];
+               $content2 = [ 'yyy', null, CONTENT_MODEL_TEXT ];
 
                return [
                        'self-diff' => [ $content1, $content1, '' ],
@@ -184,12 +181,6 @@ class DifferenceEngineTest extends MediaWikiTestCase {
        }
 
        public function testGenerateTextDiffBody() {
-               // Set $wgExternalDiffEngine to something bogus to try to force use of
-               // the PHP engine rather than wikidiff2.
-               $this->setMwGlobals( [
-                       'wgExternalDiffEngine' => '/dev/null',
-               ] );
-
                $oldText = "aaa\nbbb\nccc";
                $newText = "aaa\nxxx\nccc";
                $expectedDiff = " aaa aaa\n-bbb+xxx\n ccc ccc";
@@ -200,12 +191,6 @@ class DifferenceEngineTest extends MediaWikiTestCase {
        }
 
        public function testSetContent() {
-               // Set $wgExternalDiffEngine to something bogus to try to force use of
-               // the PHP engine rather than wikidiff2.
-               $this->setMwGlobals( [
-                       'wgExternalDiffEngine' => '/dev/null',
-               ] );
-
                $oldContent = ContentHandler::makeContent( 'xxx', null, CONTENT_MODEL_TEXT );
                $newContent = ContentHandler::makeContent( 'yyy', null, CONTENT_MODEL_TEXT );
 
@@ -216,9 +201,9 @@ class DifferenceEngineTest extends MediaWikiTestCase {
        }
 
        public function testSetRevisions() {
-               $main1 = SlotRecord::newUnsaved( 'main',
+               $main1 = SlotRecord::newUnsaved( SlotRecord::MAIN,
                        ContentHandler::makeContent( 'xxx', null, CONTENT_MODEL_TEXT ) );
-               $main2 = SlotRecord::newUnsaved( 'main',
+               $main2 = SlotRecord::newUnsaved( SlotRecord::MAIN,
                        ContentHandler::makeContent( 'yyy', null, CONTENT_MODEL_TEXT ) );
                $rev1 = $this->getRevisionRecord( $main1 );
                $rev2 = $this->getRevisionRecord( $main2 );
@@ -240,12 +225,6 @@ class DifferenceEngineTest extends MediaWikiTestCase {
        public function testGetDiffBody(
                RevisionRecord $oldRevision = null, RevisionRecord $newRevision = null, $expectedDiff
        ) {
-               // Set $wgExternalDiffEngine to something bogus to try to force use of
-               // the PHP engine rather than wikidiff2.
-               $this->setMwGlobals( [
-                       'wgExternalDiffEngine' => '/dev/null',
-               ] );
-
                if ( $expectedDiff instanceof Exception ) {
                        $this->setExpectedException( get_class( $expectedDiff ), $expectedDiff->getMessage() );
                }
@@ -260,9 +239,9 @@ class DifferenceEngineTest extends MediaWikiTestCase {
        }
 
        public function provideGetDiffBody() {
-               $main1 = SlotRecord::newUnsaved( 'main',
+               $main1 = SlotRecord::newUnsaved( SlotRecord::MAIN,
                        ContentHandler::makeContent( 'xxx', null, CONTENT_MODEL_TEXT ) );
-               $main2 = SlotRecord::newUnsaved( 'main',
+               $main2 = SlotRecord::newUnsaved( SlotRecord::MAIN,
                        ContentHandler::makeContent( 'yyy', null, CONTENT_MODEL_TEXT ) );
                $slot1 = SlotRecord::newUnsaved( 'slot',
                        ContentHandler::makeContent( 'aaa', null, CONTENT_MODEL_TEXT ) );
@@ -313,14 +292,14 @@ class DifferenceEngineTest extends MediaWikiTestCase {
                $customContentHandler->expects( $this->any() )
                        ->method( 'createDifferenceEngine' )
                        ->willReturn( $customDifferenceEngine );
-               /** @var $customContentHandler ContentHandler */
+               /** @var ContentHandler $customContentHandler */
                $customContent = $this->getMockBuilder( Content::class )
                        ->setMethods( [ 'getContentHandler' ] )
                        ->getMockForAbstractClass();
                $customContent->expects( $this->any() )
                        ->method( 'getContentHandler' )
                        ->willReturn( $customContentHandler );
-               /** @var $customContent Content */
+               /** @var Content $customContent */
                $customContent2 = clone $customContent;
 
                $slotDiffRenderer = $customContentHandler->getSlotDiffRenderer( RequestContext::getMain() );
@@ -343,12 +322,30 @@ class DifferenceEngineTest extends MediaWikiTestCase {
                        trim( strip_tags( $diff ), "\n" ) );
        }
 
+       /**
+        * @param int $id
+        * @return Title
+        */
+       private function getMockTitle( $id = 23 ) {
+               $mock = $this->getMockBuilder( Title::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $mock->expects( $this->any() )
+                       ->method( 'getDBkey' )
+                       ->will( $this->returnValue( __CLASS__ ) );
+               $mock->expects( $this->any() )
+                       ->method( 'getArticleID' )
+                       ->will( $this->returnValue( $id ) );
+
+               return $mock;
+       }
+
        /**
         * @param SlotRecord[] $slots
         * @return MutableRevisionRecord
         */
        private function getRevisionRecord( ...$slots ) {
-               $title = Title::newFromText( 'Foo' );
+               $title = $this->getMockTitle();
                $revision = new MutableRevisionRecord( $title );
                foreach ( $slots as $slot ) {
                        $revision->setSlot( $slot );