Merge "Render namespace lists in the user's language"
[lhc/web/wiklou.git] / tests / phpunit / includes / page / WikiPageDbTestBase.php
index 4cb2b47..fee4583 100644 (file)
@@ -2,6 +2,7 @@
 
 use MediaWiki\Edit\PreparedEdit;
 use MediaWiki\MediaWikiServices;
+use MediaWiki\Revision\SlotRecord;
 use MediaWiki\Storage\RevisionSlotsUpdate;
 use PHPUnit\Framework\MockObject\MockObject;
 use Wikimedia\TestingAccessWrapper;
@@ -807,6 +808,23 @@ abstract class WikiPageDbTestBase extends MediaWikiLangTestCase {
                                "#REDIRECT [[hello world]]",
                                "Hello world"
                        ],
+                       // The below added to protect against Media namespace
+                       // redirects which throw a fatal: (T203942)
+                       [
+                               'WikiPageTest_testGetRedirectTarget_3',
+                               CONTENT_MODEL_WIKITEXT,
+                               "#REDIRECT [[Media:hello_world]]",
+                               "File:Hello world"
+                       ],
+                       // Test fragments longer than 255 bytes (T207876)
+                       [
+                               'WikiPageTest_testGetRedirectTarget_4',
+                               CONTENT_MODEL_WIKITEXT,
+                               // phpcs:ignore Generic.Files.LineLength
+                               '#REDIRECT [[Foobar#🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿]]',
+                               // phpcs:ignore Generic.Files.LineLength
+                               'Foobar#🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬󠁦󠁲󠁿🏴󠁮󠁬...'
+                       ]
                ];
        }
 
@@ -827,7 +845,7 @@ abstract class WikiPageDbTestBase extends MediaWikiLangTestCase {
 
                # now, test the actual redirect
                $t = $page->getRedirectTarget();
-               $this->assertEquals( $target, is_null( $t ) ? null : $t->getPrefixedText() );
+               $this->assertEquals( $target, is_null( $t ) ? null : $t->getFullText() );
        }
 
        /**
@@ -1232,7 +1250,7 @@ more stuff
                );
 
                // TODO: MCR: assert origin once we write slot data
-               // $mainSlot = $page->getRevision()->getRevisionRecord()->getSlot( 'main' );
+               // $mainSlot = $page->getRevision()->getRevisionRecord()->getSlot( SlotRecord::MAIN );
                // $this->assertTrue( $mainSlot->isInherited(), 'isInherited' );
                // $this->assertSame( $rev2->getId(), $mainSlot->getOrigin(), 'getOrigin' );
        }
@@ -2416,10 +2434,10 @@ more stuff
 
                // provide context, so the cache can be kept in place
                $slotsUpdate = new revisionSlotsUpdate();
-               $slotsUpdate->modifyContent( 'main', $content );
+               $slotsUpdate->modifyContent( SlotRecord::MAIN, $content );
 
                $updater = $page->newPageUpdater( $user, $slotsUpdate );
-               $updater->setContent( 'main', $content );
+               $updater->setContent( SlotRecord::MAIN, $content );
                $revision = $updater->saveRevision(
                        CommentStoreComment::newUnsavedComment( 'test' ),
                        EDIT_NEW
@@ -2448,7 +2466,7 @@ more stuff
                $user = $revision->getUser();
 
                $slotsUpdate = new RevisionSlotsUpdate();
-               $slotsUpdate->modifyContent( 'main', new WikitextContent( 'Hello World' ) );
+               $slotsUpdate->modifyContent( SlotRecord::MAIN, new WikitextContent( 'Hello World' ) );
 
                // get a virgin updater
                $updater1 = $page->getDerivedDataUpdater( $user );
@@ -2460,7 +2478,7 @@ more stuff
                $this->assertSame( $updater1, $page->getDerivedDataUpdater( $user, $revision ) );
 
                $slotsUpdate = RevisionSlotsUpdate::newFromContent(
-                       [ 'main' => $revision->getContent( 'main' ) ]
+                       [ SlotRecord::MAIN => $revision->getContent( SlotRecord::MAIN ) ]
                );
                $this->assertSame( $updater1, $page->getDerivedDataUpdater( $user, null, $slotsUpdate ) );