Merge "Use pseudo elements to style changelist-separators on Contributions"
[lhc/web/wiklou.git] / tests / phpunit / includes / page / ArticleViewTest.php
index d721274..d07a9e1 100644 (file)
@@ -2,6 +2,7 @@
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Storage\MutableRevisionRecord;
 use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
 use PHPUnit\Framework\MockObject\MockObject;
 
 /**
@@ -43,7 +44,7 @@ class ArticleViewTest extends MediaWikiTestCase {
                        }
 
                        $u = $page->newPageUpdater( $user );
-                       $u->setContent( 'main', $cont );
+                       $u->setContent( SlotRecord::MAIN, $cont );
                        $rev = $u->saveRevision( CommentStoreComment::newUnsavedComment( 'Rev ' . $key ) );
 
                        $revisions[ $key ] = $rev;
@@ -201,7 +202,7 @@ class ArticleViewTest extends MediaWikiTestCase {
                $rev->setComment( $dummyRev->getComment() );
                $rev->setTimestamp( $dummyRev->getTimestamp() );
 
-               $rev->setContent( 'main', $content );
+               $rev->setContent( SlotRecord::MAIN, $content );
 
                $rev = new Revision( $rev );
 
@@ -425,6 +426,44 @@ class ArticleViewTest extends MediaWikiTestCase {
                        }
                );
 
+               $this->hideDeprecated(
+                       'ArticleContentViewCustom hook (used in hook-ArticleContentViewCustom-closure)'
+               );
+
+               $article->view();
+
+               $output = $article->getContext()->getOutput();
+               $this->assertNotContains( 'Test A', $this->getHtml( $output ) );
+               $this->assertContains( 'Hook Text', $this->getHtml( $output ) );
+       }
+
+       public function testArticleRevisionViewCustomHook() {
+               $page = $this->getPage( __METHOD__, [ 1 => 'Test A' ] );
+
+               $article = new Article( $page->getTitle(), 0 );
+               $article->getContext()->getOutput()->setTitle( $page->getTitle() );
+
+               // use ArticleViewHeader hook to bypass the parser cache
+               $this->setTemporaryHook(
+                       'ArticleViewHeader',
+                       function ( Article $articlePage, &$outputDone, &$useParserCache ) use ( $article ) {
+                               $useParserCache = false;
+                       }
+               );
+
+               $this->setTemporaryHook(
+                       'ArticleRevisionViewCustom',
+                       function ( RevisionRecord $rev, Title $title, $oldid, OutputPage $output ) use ( $page ) {
+                               $content = $rev->getContent( SlotRecord::MAIN );
+
+                               $this->assertSame( $page->getTitle(), $title, '$title' );
+                               $this->assertSame( 'Test A', $content->getNativeData(), '$content' );
+
+                               $output->addHTML( 'Hook Text' );
+                               return false;
+                       }
+               );
+
                $article->view();
 
                $output = $article->getContext()->getOutput();
@@ -456,6 +495,11 @@ class ArticleViewTest extends MediaWikiTestCase {
                        }
                );
 
+               $this->hideDeprecated(
+                       'ArticleAfterFetchContentObject hook'
+                       . ' (used in hook-ArticleAfterFetchContentObject-closure)'
+               );
+
                $article->view();
 
                $output = $article->getContext()->getOutput();