20 use PHPUnit\Framework\MockObject\MockObject;
23 use Wikimedia\TestingAccessWrapper;
45 $withHtml = $hints[
'generate-html'] ??
true;
48 $slots = $revision->getSlots()->getSlots();
52 foreach ( $slots
as $role => $slot ) {
54 $slotOutput[$role] =
$out;
56 $combinedOutput->mergeInternalMetaDataFrom(
$out );
57 $combinedOutput->mergeTrackingMetaDataFrom(
$out );
63 foreach ( $slotOutput
as $role =>
$out ) {
71 $combinedOutput->mergeHtmlMetaDataFrom(
$out );
74 $combinedOutput->setText(
$html );
77 return $combinedOutput;
88 ->disableOriginalConstructor()
90 $mock->expects( $this->
any() )
91 ->method(
'getNamespace' )
92 ->will( $this->returnValue(
NS_MAIN ) );
93 $mock->expects( $this->
any() )
95 ->will( $this->returnValue(
'RenderTestPage' ) );
96 $mock->expects( $this->
any() )
97 ->method(
'getPrefixedText' )
98 ->will( $this->returnValue(
'RenderTestPage' ) );
99 $mock->expects( $this->
any() )
100 ->method(
'getDBkey' )
101 ->will( $this->returnValue(
'RenderTestPage' ) );
102 $mock->expects( $this->
any() )
103 ->method(
'getArticleID' )
104 ->will( $this->returnValue( $articleId ) );
105 $mock->expects( $this->
any() )
106 ->method(
'getLatestRevId' )
107 ->will( $this->returnValue( $revisionId ) );
108 $mock->expects( $this->
any() )
109 ->method(
'getContentModel' )
111 $mock->expects( $this->
any() )
112 ->method(
'getPageLanguage' )
114 $mock->expects( $this->
any() )
115 ->method(
'isContentPage' )
116 ->will( $this->returnValue(
true ) );
117 $mock->expects( $this->
any() )
119 ->willReturnCallback(
function (
Title $other )
use ( $mock ) {
122 $mock->expects( $this->
any() )
123 ->method(
'userCan' )
124 ->willReturnCallback(
function ( $perm,
User $user )
use ( $mock ) {
125 return $user->isAllowed( $perm );
149 $text .=
"* page:{{PAGENAME}}!\n";
150 $text .=
"* rev:{{REVISIONID}}!\n";
151 $text .=
"* user:{{REVISIONUSER}}!\n";
152 $text .=
"* time:{{REVISIONTIMESTAMP}}!\n";
153 $text .=
"* [[Link It]]\n";
159 $mock = $this->getMockBuilder( $class )
160 ->disableOriginalConstructor()
164 'getPageAsLinkTarget',
170 $mock->method(
'getId' )->willReturn( $id );
171 $mock->method(
'getPageId' )->willReturn(
$title->getArticleID() );
172 $mock->method(
'getPageAsLinkTarget' )->willReturn(
$title );
173 $mock->method(
'getUser' )->willReturn( $frank );
174 $mock->method(
'getVisibility' )->willReturn( $visibility );
175 $mock->method(
'getTimestamp' )->willReturn(
'20180101000003' );
178 $mockAccess = TestingAccessWrapper::newFromObject( $mock );
182 $mockAccess->mSlots->setContent( $role, $cnt );
195 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
197 $this->assertSame(
$rev, $rr->getRevision() );
198 $this->assertSame(
$options, $rr->getOptions() );
200 $html = $rr->getRevisionParserOutput()->getText();
202 $this->assertContains(
'page:RenderTestPage!',
$html );
203 $this->assertContains(
'user:Frank!',
$html );
204 $this->assertContains(
'time:20180101000003!',
$html );
211 $text =
"(ONE)<includeonly>(TWO)</includeonly><noinclude>#{{:$name}}#</noinclude>";
222 $html = $rr->getRevisionParserOutput()->getText();
223 $this->assertContains(
'(ONE)#(ONE)(TWO)#',
$html );
233 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
235 $this->assertSame(
$rev, $rr->getRevision() );
236 $this->assertSame(
$options, $rr->getOptions() );
238 $html = $rr->getRevisionParserOutput()->getText();
240 $this->assertContains(
'page:RenderTestPage!',
$html );
241 $this->assertContains(
'rev:21!',
$html );
242 $this->assertContains(
'user:Frank!',
$html );
243 $this->assertContains(
'time:20180101000003!',
$html );
255 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
257 $this->assertSame(
$rev, $rr->getRevision() );
258 $this->assertSame(
$options, $rr->getOptions() );
260 $html = $rr->getRevisionParserOutput()->getText();
262 $this->assertContains(
'page:RenderTestPage!',
$html );
263 $this->assertContains(
'rev:11!',
$html );
264 $this->assertContains(
'user:Frank!',
$html );
265 $this->assertContains(
'time:20180101000003!',
$html );
277 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
279 $this->assertSame(
$rev, $rr->getRevision() );
280 $this->assertSame(
$options, $rr->getOptions() );
282 $html = $rr->getRevisionParserOutput()->getText();
284 $this->assertContains(
'page:RenderTestPage!',
$html );
285 $this->assertContains(
'rev:11!',
$html );
286 $this->assertContains(
'user:Frank!',
$html );
287 $this->assertContains(
'time:20180101000003!',
$html );
305 $rr->getRevisionParserOutput();
318 $sysop = $this->
getTestUser( [
'sysop' ] )->getUser();
323 $this->combinerCallback,
328 $this->assertTrue( $rr->isContentDeleted(),
'isContentDeleted' );
330 $this->assertSame(
$rev, $rr->getRevision() );
331 $this->assertSame(
$options, $rr->getOptions() );
333 $html = $rr->getRevisionParserOutput()->getText();
336 $this->assertContains(
'page:RenderTestPage!',
$html );
337 $this->assertContains(
'rev:11!',
$html );
338 $this->assertContains(
'user:Frank!',
$html );
339 $this->assertContains(
'time:20180101000003!',
$html );
358 $this->combinerCallback,
362 $this->assertTrue( $rr->isContentDeleted(),
'isContentDeleted' );
364 $this->assertSame(
$rev, $rr->getRevision() );
365 $this->assertSame(
$options, $rr->getOptions() );
367 $html = $rr->getRevisionParserOutput()->getText();
370 $this->assertContains(
'page:RenderTestPage!',
$html );
371 $this->assertContains(
'rev:11!',
$html );
372 $this->assertContains(
'user:Frank!',
$html );
373 $this->assertContains(
'time:20180101000003!',
$html );
390 $combinedOutput = $rr->getRevisionParserOutput();
392 $auxOutput = $rr->getSlotParserOutput(
'aux' );
394 $combinedHtml = $combinedOutput->getText();
395 $mainHtml = $mainOutput->getText();
396 $auxHtml = $auxOutput->getText();
398 $this->assertContains(
'Kittens', $mainHtml );
399 $this->assertContains(
'Goats', $auxHtml );
400 $this->assertNotContains(
'Goats', $mainHtml );
401 $this->assertNotContains(
'Kittens', $auxHtml );
402 $this->assertContains(
'Kittens', $combinedHtml );
403 $this->assertContains(
'Goats', $combinedHtml );
404 $this->assertContains(
'aux', $combinedHtml,
'slot section header' );
406 $combinedLinks = $combinedOutput->getLinks();
407 $mainLinks = $mainOutput->getLinks();
408 $auxLinks = $auxOutput->getLinks();
409 $this->assertTrue( isset( $combinedLinks[
NS_MAIN][
'Kittens'] ),
'links from main slot' );
410 $this->assertTrue( isset( $combinedLinks[
NS_MAIN][
'Goats'] ),
'links from aux slot' );
411 $this->assertFalse( isset( $mainLinks[
NS_MAIN][
'Goats'] ),
'no aux links in main' );
412 $this->assertFalse( isset( $auxLinks[
NS_MAIN][
'Kittens'] ),
'no main links in aux' );
421 $text .=
"* page:{{PAGENAME}}!\n";
422 $text .=
"* rev:{{REVISIONID}}!\n";
423 $text .=
"* user:{{REVISIONUSER}}!\n";
424 $text .=
"* time:{{REVISIONTIMESTAMP}}!\n";
433 $html = $rr->getRevisionParserOutput()->getText();
435 $this->assertContains(
'page:RenderTestPage!',
$html );
436 $this->assertContains(
'rev:!',
$html );
437 $this->assertContains(
'user:!',
$html );
438 $this->assertContains(
'time:!',
$html );
448 $text .=
"* page:{{PAGENAME}}!\n";
449 $text .=
"* rev:{{REVISIONID}}!\n";
450 $text .=
"* user:{{REVISIONUSER}}!\n";
451 $text .=
"* time:{{REVISIONTIMESTAMP}}!\n";
468 ->disableOriginalConstructor()
471 $revisionStore->expects( $this->once() )
472 ->method(
'getKnownCurrentRevision' )
474 ->willReturn( $actualRevision );
476 $this->
setService(
'RevisionStore', $revisionStore );
478 $html = $rr->getRevisionParserOutput()->getText();
480 $this->assertContains(
'page:RenderTestPage!',
$html );
481 $this->assertContains(
'rev:21!',
$html );
482 $this->assertContains(
'user:Frank!',
$html );
483 $this->assertContains(
'time:20180101000003!',
$html );
494 $rr->setRevisionParserOutput(
$output );
496 $this->assertSame(
$output, $rr->getRevisionParserOutput() );
497 $this->assertSame(
'Kittens', $rr->getRevisionParserOutput()->getText() );
500 $this->assertSame(
'Kittens', $rr->getSlotParserOutput(
SlotRecord::MAIN )->getText() );
506 ->setMethods( [
'getParserOutput' ] )
507 ->setConstructorArgs( [
'Whatever' ] )
509 $mockContent->method(
'getParserOutput' )
510 ->willReturnCallback(
function (
Title $title, $revId =
null,
513 if ( !$generateHtml ) {
516 $this->fail(
'Should not be called with $generateHtml == true' );
525 $rev->setContent(
'aux', $mockContent );
531 $this->assertFalse(
$output->hasText(),
'hasText' );
533 $output = $rr->getRevisionParserOutput( [
'generate-html' =>
false ] );
534 $this->assertFalse(
$output->hasText(),
'hasText' );
543 $text .=
"* page:{{PAGENAME}}!\n";
544 $text .=
"* rev:{{REVISIONID}}!\n";
545 $text .=
"* user:{{REVISIONUSER}}!\n";
546 $text .=
"* time:{{REVISIONTIMESTAMP}}!\n";
554 $firstOutput = $rr->getRevisionParserOutput();
556 $auxOutput = $rr->getSlotParserOutput(
'aux' );
562 $savedRev->setId( 23 );
564 $savedRev->setTimestamp(
'20180101000003' );
566 $rr->updateRevision( $savedRev );
568 $this->assertNotSame( $mainOutput, $rr->getSlotParserOutput(
SlotRecord::MAIN ),
'Reset main' );
569 $this->assertSame( $auxOutput, $rr->getSlotParserOutput(
'aux' ),
'Keep aux' );
571 $updatedOutput = $rr->getRevisionParserOutput();
572 $html = $updatedOutput->getText();
574 $this->assertNotSame( $firstOutput, $updatedOutput,
'Reset merged' );
575 $this->assertContains(
'page:RenderTestPage!',
$html );
576 $this->assertContains(
'rev:23!',
$html );
577 $this->assertContains(
'user:Frank!',
$html );
578 $this->assertContains(
'time:20180101000003!',
$html );
579 $this->assertContains(
'Goats',
$html );
581 $rr->updateRevision( $savedRev );
582 $this->assertSame( $updatedOutput, $rr->getRevisionParserOutput(),
'no more reset needed' );