20 use PHPUnit\Framework\MockObject\MockObject;
40 ->disableOriginalConstructor()
42 $mock->expects( $this->
any() )
43 ->method(
'getNamespace' )
44 ->will( $this->returnValue(
NS_MAIN ) );
45 $mock->expects( $this->
any() )
47 ->will( $this->returnValue( __CLASS__ ) );
48 $mock->expects( $this->
any() )
49 ->method(
'getPrefixedText' )
50 ->will( $this->returnValue( __CLASS__ ) );
51 $mock->expects( $this->
any() )
52 ->method(
'getDBkey' )
53 ->will( $this->returnValue( __CLASS__ ) );
54 $mock->expects( $this->
any() )
55 ->method(
'getArticleID' )
56 ->will( $this->returnValue( $articleId ) );
57 $mock->expects( $this->
any() )
58 ->method(
'getLatestRevId' )
59 ->will( $this->returnValue( $revisionId ) );
60 $mock->expects( $this->
any() )
61 ->method(
'getContentModel' )
63 $mock->expects( $this->
any() )
64 ->method(
'getPageLanguage' )
66 $mock->expects( $this->
any() )
67 ->method(
'isContentPage' )
68 ->will( $this->returnValue(
true ) );
69 $mock->expects( $this->
any() )
72 function (
Title $other )
use ( $mock ) {
76 $mock->expects( $this->
any() )
80 return $user->isAllowed( $perm );
96 $db->method(
'selectField' )
98 function ( $table, $fields, $cond )
use ( $maxRev, $linkCount ) {
122 $lb->method(
'getConnection' )
125 $lb->method(
'getConnectionRef' )
128 $lb->method(
'getLazyConnectionRef' )
134 ->disableOriginalConstructor()
136 $slotRoles->method(
'getMap' )
140 $roleReg->defineRole(
'main',
function () {
149 if ( [ $table, $fields, $cond ] === [
'revision',
'MAX(rev_id)', [] ] ) {
153 $this->fail(
'Unexpected call to selectField' );
154 throw new LogicException(
'Ooops' );
163 $rev->setTimestamp(
'20180101000003' );
167 $text .=
"* page:{{PAGENAME}}\n";
168 $text .=
"* rev:{{REVISIONID}}\n";
169 $text .=
"* user:{{REVISIONUSER}}\n";
170 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
171 $text .=
"* [[Link It]]\n";
178 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
180 $this->assertSame(
$rev, $rr->getRevision() );
181 $this->assertSame(
$options, $rr->getOptions() );
183 $html = $rr->getRevisionParserOutput()->getText();
185 $this->assertContains(
'page:' . __CLASS__,
$html );
186 $this->assertContains(
'rev:101',
$html );
187 $this->assertContains(
'user:Frank',
$html );
188 $this->assertContains(
'time:20180101000003',
$html );
200 $rev->setTimestamp(
'20180101000003' );
204 $text .=
"* page:{{PAGENAME}}\n";
205 $text .=
"* rev:{{REVISIONID}}\n";
206 $text .=
"* user:{{REVISIONUSER}}\n";
207 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
214 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
216 $this->assertSame(
$rev, $rr->getRevision() );
217 $this->assertSame(
$options, $rr->getOptions() );
219 $html = $rr->getRevisionParserOutput()->getText();
221 $this->assertContains(
'page:' . __CLASS__,
$html );
222 $this->assertContains(
'rev:21',
$html );
223 $this->assertContains(
'user:Frank',
$html );
224 $this->assertContains(
'time:20180101000003',
$html );
236 $rev->setTimestamp(
'20180101000003' );
240 $text .=
"* page:{{PAGENAME}}\n";
241 $text .=
"* rev:{{REVISIONID}}\n";
242 $text .=
"* user:{{REVISIONUSER}}\n";
243 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
248 $rr = $renderer->getRenderedRevision(
$rev,
$options,
null, [
'use-master' =>
true ] );
250 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
252 $html = $rr->getRevisionParserOutput()->getText();
254 $this->assertContains(
'rev:21',
$html );
266 $rev->setTimestamp(
'20180101000003' );
269 $text =
"uncached text";
275 $rr = $renderer->getRenderedRevision(
279 [
'known-revision-output' =>
$output ]
282 $this->assertSame(
$output, $rr->getRevisionParserOutput() );
283 $this->assertSame(
'cached text', $rr->getRevisionParserOutput()->getText() );
284 $this->assertSame(
'cached text', $rr->getSlotParserOutput(
SlotRecord::MAIN )->getText() );
294 $rev->setTimestamp(
'20180101000003' );
298 $text .=
"* page:{{PAGENAME}}\n";
299 $text .=
"* rev:{{REVISIONID}}\n";
300 $text .=
"* user:{{REVISIONUSER}}\n";
301 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
308 $this->assertFalse( $rr->isContentDeleted(),
'isContentDeleted' );
310 $this->assertSame(
$rev, $rr->getRevision() );
311 $this->assertSame(
$options, $rr->getOptions() );
313 $html = $rr->getRevisionParserOutput()->getText();
315 $this->assertContains(
'page:' . __CLASS__,
$html );
316 $this->assertContains(
'rev:11',
$html );
317 $this->assertContains(
'user:Frank',
$html );
318 $this->assertContains(
'time:20180101000003',
$html );
320 $this->assertSame(
$html, $rr->getSlotParserOutput(
'main' )->getText() );
331 $rev->setTimestamp(
'20180101000003' );
335 $text .=
"* page:{{PAGENAME}}\n";
336 $text .=
"* rev:{{REVISIONID}}\n";
337 $text .=
"* user:{{REVISIONUSER}}\n";
338 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
345 $this->assertNull( $rr,
'getRenderedRevision' );
356 $rev->setTimestamp(
'20180101000003' );
360 $text .=
"* page:{{PAGENAME}}\n";
361 $text .=
"* rev:{{REVISIONID}}\n";
362 $text .=
"* user:{{REVISIONUSER}}\n";
363 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
368 $sysop = $this->
getTestUser( [
'sysop' ] )->getUser();
369 $rr = $renderer->getRenderedRevision(
$rev,
$options, $sysop );
371 $this->assertTrue( $rr->isContentDeleted(),
'isContentDeleted' );
373 $this->assertSame(
$rev, $rr->getRevision() );
374 $this->assertSame(
$options, $rr->getOptions() );
376 $html = $rr->getRevisionParserOutput()->getText();
379 $this->assertContains(
'page:' . __CLASS__,
$html );
380 $this->assertContains(
'rev:11',
$html );
381 $this->assertContains(
'user:Frank',
$html );
382 $this->assertContains(
'time:20180101000003',
$html );
384 $this->assertSame(
$html, $rr->getSlotParserOutput(
'main' )->getText() );
395 $rev->setTimestamp(
'20180101000003' );
399 $text .=
"* page:{{PAGENAME}}\n";
400 $text .=
"* rev:{{REVISIONID}}\n";
401 $text .=
"* user:{{REVISIONUSER}}\n";
402 $text .=
"* time:{{REVISIONTIMESTAMP}}\n";
407 $rr = $renderer->getRenderedRevision(
414 $this->assertTrue( $rr->isContentDeleted(),
'isContentDeleted' );
416 $this->assertSame(
$rev, $rr->getRevision() );
417 $this->assertSame(
$options, $rr->getOptions() );
419 $html = $rr->getRevisionParserOutput()->getText();
422 $this->assertContains(
'page:' . __CLASS__,
$html );
423 $this->assertContains(
'rev:11',
$html );
424 $this->assertContains(
'user:Frank',
$html );
425 $this->assertContains(
'time:20180101000003',
$html );
427 $this->assertSame(
$html, $rr->getSlotParserOutput(
'main' )->getText() );
436 $rev->setTimestamp(
'20180101000003' );
442 $rr = $renderer->getRenderedRevision(
$rev );
444 $combinedOutput = $rr->getRevisionParserOutput();
446 $auxOutput = $rr->getSlotParserOutput(
'aux' );
448 $combinedHtml = $combinedOutput->getText();
449 $mainHtml = $mainOutput->getText();
450 $auxHtml = $auxOutput->getText();
452 $this->assertContains(
'Kittens', $mainHtml );
453 $this->assertContains(
'Goats', $auxHtml );
454 $this->assertNotContains(
'Goats', $mainHtml );
455 $this->assertNotContains(
'Kittens', $auxHtml );
456 $this->assertContains(
'Kittens', $combinedHtml );
457 $this->assertContains(
'Goats', $combinedHtml );
458 $this->assertContains(
'>aux<', $combinedHtml,
'slot header' );
459 $this->assertNotContains(
'<mw:slotheader', $combinedHtml,
'slot header placeholder' );
462 $this->assertContains(
'class="mw-parser-output"', $mainHtml );
463 $this->assertContains(
'class="mw-parser-output"', $auxHtml );
464 $this->assertContains(
'class="mw-parser-output"', $combinedHtml );
467 $this->assertSame( 1, preg_match_all(
'#class="mw-parser-output"#', $combinedHtml ) );
468 $this->assertNotContains(
'class="mw-parser-output"', $combinedOutput->getRawText() );
470 $combinedLinks = $combinedOutput->getLinks();
471 $mainLinks = $mainOutput->getLinks();
472 $auxLinks = $auxOutput->getLinks();
473 $this->assertTrue( isset( $combinedLinks[
NS_MAIN][
'Kittens'] ),
'links from main slot' );
474 $this->assertTrue( isset( $combinedLinks[
NS_MAIN][
'Goats'] ),
'links from aux slot' );
475 $this->assertFalse( isset( $mainLinks[
NS_MAIN][
'Goats'] ),
'no aux links in main' );
476 $this->assertFalse( isset( $auxLinks[
NS_MAIN][
'Kittens'] ),
'no main links in aux' );
482 ->setMethods( [
'getParserOutput' ] )
483 ->setConstructorArgs( [
'Whatever' ] )
485 $mockContent->method(
'getParserOutput' )
486 ->willReturnCallback(
function (
Title $title, $revId =
null,
489 if ( !$generateHtml ) {
492 $this->fail(
'Should not be called with $generateHtml == true' );
502 $rev->setContent(
'aux', $mockContent );
505 $rr = $renderer->getRenderedRevision(
$rev );
508 $this->assertFalse(
$output->hasText(),
'hasText' );
510 $output = $rr->getRevisionParserOutput( [
'generate-html' =>
false ] );
511 $this->assertFalse(
$output->hasText(),
'hasText' );