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' );
193 $content->expects( $this->never() )->method(
'getNativeData' );
198 $rev->setId( $dummyRev->getId() );
200 $rev->setUser( $dummyRev->getUser() );
201 $rev->setComment( $dummyRev->getComment() );
202 $rev->setTimestamp( $dummyRev->getTimestamp() );
210 ->setMethods( [
'getRevision',
'getLatest' ] )
211 ->setConstructorArgs( [
$title ] )
214 $page->method(
'getRevision' )
215 ->willReturn(
$rev );
216 $page->method(
'getLatest' )
217 ->willReturn(
$rev->getId() );
224 $this->assertContains(
'Structured Output', $this->
getHtml(
$output ) );
230 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ], $revisions );
231 $idA = $revisions[1]->getId();
239 $this->assertContains(
'id="mw-revision-info"',
$output->getSubtitle() );
240 $this->assertContains(
'id="mw-revision-nav"',
$output->getSubtitle() );
242 $this->assertNotContains(
'id="revision-info-current"',
$output->getSubtitle() );
248 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ], $revisions );
249 $idB = $revisions[2]->getId();
257 $this->assertContains(
'id="mw-revision-info-current"',
$output->getSubtitle() );
258 $this->assertContains(
'id="mw-revision-nav"',
$output->getSubtitle() );
263 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A' ], $revisions );
264 $badId = $revisions[1]->getId() + 100;
271 $this->assertContains(
'missing-revision: ' . $badId, $this->
getHtml(
$output ) );
278 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ], $revisions );
279 $idA = $revisions[1]->getId();
285 'value' => [ RevisionRecord::DELETED_TEXT => 1 ],
286 'comment' =>
"Testing",
294 $this->assertContains(
'(rev-deleted-text-permission)', $this->
getHtml(
$output ) );
302 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ], $revisions );
303 $idA = $revisions[1]->getId();
309 'value' => [ RevisionRecord::DELETED_TEXT => 1 ],
310 'comment' =>
"Testing",
316 $context->getOutput()->setTitle( $page->getTitle() );
317 $context->getRequest()->setVal(
'unhide', 1 );
322 $this->assertContains(
'(rev-deleted-text-view)', $this->
getHtml(
$output ) );
329 $page = $this->
getPage( __METHOD__ );
336 $this->assertContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );
340 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A', 2 =>
'Test B' ] );
341 $page->doDeleteArticle(
'Test' );
348 $this->assertContains(
'moveddeleted', $this->
getHtml(
$output ) );
349 $this->assertContains(
'logentry-delete-delete', $this->
getHtml(
$output ) );
350 $this->assertContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );
365 $this->assertContains(
366 wfMessage(
'mainpage' )->inContentLanguage()->parse(),
369 $this->assertNotContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );
374 $user->addToDatabase();
385 $this->assertContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );
386 $this->assertNotContains(
'(userpage-userdoesnotexist-view)', $this->
getHtml(
$output ) );
401 $this->assertContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );
402 $this->assertContains(
'(userpage-userdoesnotexist-view:', $this->
getHtml(
$output ) );
406 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A' ] );
414 $this->assertSame(
$article, $articlePage,
'$articlePage' );
417 $outputDone->setTitleText(
'Hook Title' );
419 $articlePage->
getContext()->getOutput()->addParserOutput( $outputDone );
428 $this->assertSame(
'Hook Title',
$output->getPageTitle() );
432 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A' ] );
441 $useParserCache =
false;
446 'ArticleContentViewCustom',
448 $this->assertSame( $page->getTitle(),
$title,
'$title' );
449 $this->assertSame(
'Test A',
$content->getText(),
'$content' );
451 $output->addHTML(
'Hook Text' );
457 'ArticleContentViewCustom hook (used in hook-ArticleContentViewCustom-closure)'
463 $this->assertNotContains(
'Test A', $this->
getHtml( $output ) );
464 $this->assertContains(
'Hook Text', $this->
getHtml( $output ) );
468 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A' ] );
477 $useParserCache =
false;
482 'ArticleRevisionViewCustom',
485 $this->assertSame( $page->getTitle(),
$title,
'$title' );
486 $this->assertSame(
'Test A',
$content->getText(),
'$content' );
488 $output->addHTML(
'Hook Text' );
496 $this->assertNotContains(
'Test A', $this->
getHtml( $output ) );
497 $this->assertContains(
'Hook Text', $this->
getHtml( $output ) );
501 $page = $this->
getPage( __METHOD__, [ 1 =>
'Test A' ] );
510 $useParserCache =
false;
515 'ArticleAfterFetchContentObject',
517 $this->assertSame(
$article, $articlePage,
'$articlePage' );
518 $this->assertSame(
'Test A',
$content->getText(),
'$content' );
525 'ArticleAfterFetchContentObject hook'
526 .
' (used in hook-ArticleAfterFetchContentObject-closure)'
537 $page = $this->
getPage( __METHOD__ );
543 'ShowMissingArticle',
545 $this->assertSame(
$article, $articlePage,
'$articlePage' );
547 $articlePage->
getContext()->getOutput()->addHTML(
'Hook Text' );
554 $this->assertContains(
'(noarticletextanon)', $this->
getHtml(
$output ) );