6 use PHPUnit\Framework\MockObject\MockObject;
20 return preg_replace(
'/<!--.*?-->/s',
'',
$output->getHTML() );
33 if ( is_string(
$title ) ) {
41 foreach ( $revisionContents
as $key => $cont ) {
42 if ( is_string( $cont ) ) {
46 $u = $page->newPageUpdater(
$user );
47 $u->setContent( SlotRecord::MAIN, $cont );
50 $revisions[ $key ] =
$rev;
62 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ], $revisions );
64 $idA = $revisions[1]->getId();
65 $idB = $revisions[2]->getId();
69 $this->assertSame( $idA,
$article->getOldID() );
71 $this->assertSame( $idA,
$article->getRevIdFetched() );
75 $this->assertSame( 0,
$article->getOldID() );
77 $this->assertSame( $idB,
$article->getRevIdFetched() );
84 $this->assertSame( $idA,
$article->getOldID() );
86 $this->assertSame( $idA,
$article->getRevIdFetched() );
93 $this->assertSame( 0,
$article->getOldID() );
95 $this->assertSame( $idB,
$article->getRevIdFetched() );
99 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ] );
107 $this->assertNotContains(
'id="mw-revision-info"', $this->
getHtml(
$output ) );
108 $this->assertNotContains(
'id="mw-revision-nav"', $this->
getHtml(
$output ) );
112 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ] );
119 $cache = MediaWikiServices::getInstance()->getParserCache();
125 $this->assertContains(
'Cached Text', $this->
getHtml(
$output ) );
135 $redirectText =
'#REDIRECT [[' . $target->getPrefixedText() .
']]';
137 $page = $this->
getPage( __METHOD__, [ $redirectText ] );
143 $this->assertNotNull(
144 $article->getRedirectTarget()->getPrefixedDBkey()
147 $target->getPrefixedDBkey(),
148 $article->getRedirectTarget()->getPrefixedDBkey()
152 $this->assertContains(
'class="redirectText"', $this->
getHtml( $output ) );
153 $this->assertContains(
154 '>' . htmlspecialchars( $target->getPrefixedText() ) .
'<',
160 $dummy = $this->
getPage( __METHOD__, [
'Dummy' ] );
161 $dummyRev = $dummy->getRevision()->getRevisionRecord();
162 $title = $dummy->getTitle();
168 'isParserCacheSupported',
170 'unserializeContent',
174 ->setConstructorArgs( [
'NotText', [
'application/frobnitz' ] ] )
177 $mockHandler->method(
'isParserCacheSupported' )
178 ->willReturn(
false );
181 'ContentHandlerForModelID',
189 $content->method(
'getParserOutput' )
190 ->willReturn(
new ParserOutput(
'Structured Output' ) );
192 ->willReturn(
'NotText' );
194 ->willReturn( [ (
object)[
'x' =>
'stuff' ] ] );
199 $rev->setId( $dummyRev->getId() );
201 $rev->setUser( $dummyRev->getUser() );
202 $rev->setComment( $dummyRev->getComment() );
203 $rev->setTimestamp( $dummyRev->getTimestamp() );
211 ->setMethods( [
'getRevision',
'getLatest' ] )
212 ->setConstructorArgs( [
$title ] )
215 $page->method(
'getRevision' )
216 ->willReturn(
$rev );
217 $page->method(
'getLatest' )
218 ->willReturn(
$rev->getId() );
225 $this->assertContains(
'Structured Output', $this->
getHtml(
$output ) );
231 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ], $revisions );
232 $idA = $revisions[1]->getId();
240 $this->assertContains(
'id="mw-revision-info"',
$output->getSubtitle() );
241 $this->assertContains(
'id="mw-revision-nav"',
$output->getSubtitle() );
243 $this->assertNotContains(
'id="revision-info-current"',
$output->getSubtitle() );
249 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ], $revisions );
250 $idB = $revisions[2]->getId();
258 $this->assertContains(
'id="mw-revision-info-current"',
$output->getSubtitle() );
259 $this->assertContains(
'id="mw-revision-nav"',
$output->getSubtitle() );
264 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A' ], $revisions );
265 $badId = $revisions[1]->getId() + 100;
272 $this->assertContains(
'missing-revision: ' . $badId, $this->
getHtml(
$output ) );
279 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ], $revisions );
280 $idA = $revisions[1]->getId();
286 'value' => [ RevisionRecord::DELETED_TEXT => 1 ],
287 'comment' =>
"Testing",
295 $this->assertContains(
'(rev-deleted-text-permission)', $this->
getHtml(
$output ) );
303 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ], $revisions );
304 $idA = $revisions[1]->getId();
310 'value' => [ RevisionRecord::DELETED_TEXT => 1 ],
311 'comment' =>
"Testing",
317 $context->getOutput()->setTitle( $page->getTitle() );
318 $context->getRequest()->setVal(
'unhide', 1 );
323 $this->assertContains(
'(rev-deleted-text-view)', $this->
getHtml(
$output ) );
330 $page = $this->
getPage( __METHOD__ );
337 $this->assertContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );
341 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ] );
342 $page->doDeleteArticle(
'Test' );
349 $this->assertContains(
'moveddeleted', $this->
getHtml(
$output ) );
350 $this->assertContains(
'logentry-delete-delete', $this->
getHtml(
$output ) );
351 $this->assertContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );
366 $this->assertContains(
367 wfMessage(
'mainpage' )->inContentLanguage()->parse(),
370 $this->assertNotContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );
375 $user->addToDatabase();
386 $this->assertContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );
387 $this->assertNotContains(
'(userpage-userdoesnotexist-view)', $this->
getHtml(
$output ) );
402 $this->assertContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );
403 $this->assertContains(
'(userpage-userdoesnotexist-view:', $this->
getHtml(
$output ) );
407 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A' ] );
415 $this->assertSame(
$article, $articlePage,
'$articlePage' );
418 $outputDone->setTitleText(
'Hook Title' );
420 $articlePage->
getContext()->getOutput()->addParserOutput( $outputDone );
429 $this->assertSame(
'Hook Title',
$output->getPageTitle() );
433 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A' ] );
442 $useParserCache =
false;
447 'ArticleContentViewCustom',
449 $this->assertSame( $page->getTitle(),
$title,
'$title' );
450 $this->assertSame(
'Test A',
$content->getNativeData(),
'$content' );
452 $output->addHTML(
'Hook Text' );
458 'ArticleContentViewCustom hook (used in hook-ArticleContentViewCustom-closure)'
464 $this->assertNotContains(
'Test A', $this->
getHtml( $output ) );
465 $this->assertContains(
'Hook Text', $this->
getHtml( $output ) );
469 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A' ] );
478 $useParserCache =
false;
483 'ArticleRevisionViewCustom',
487 $this->assertSame( $page->getTitle(),
$title,
'$title' );
488 $this->assertSame(
'Test A',
$content->getNativeData(),
'$content' );
490 $output->addHTML(
'Hook Text' );
498 $this->assertNotContains(
'Test A', $this->
getHtml( $output ) );
499 $this->assertContains(
'Hook Text', $this->
getHtml( $output ) );
503 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A' ] );
512 $useParserCache =
false;
517 'ArticleAfterFetchContentObject',
519 $this->assertSame(
$article, $articlePage,
'$articlePage' );
520 $this->assertSame(
'Test A',
$content->getNativeData(),
'$content' );
527 'ArticleAfterFetchContentObject hook'
528 .
' (used in hook-ArticleAfterFetchContentObject-closure)'
539 $page = $this->
getPage( __METHOD__ );
545 'ShowMissingArticle',
547 $this->assertSame(
$article, $articlePage,
'$articlePage' );
549 $articlePage->
getContext()->getOutput()->addHTML(
'Hook Text' );
556 $this->assertContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );