Debian Codegraph @

tests/phpunit/includes/content/FallbackContentHandlerTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Content\FallbackContent;
4 use MediaWiki\Content\FallbackContentHandler;
5 use MediaWiki\Context\RequestContext;
6 use MediaWiki\Parser\ParserObserver;
7 use MediaWiki\Parser\ParserOptions;
8 use MediaWiki\Request\FauxRequest;
9 use MediaWiki\Title\Title;
10
11 /**
12 * See also unit tests at \MediaWiki\Tests\Unit\FallbackContentHandlerTest
13 *
14 * @group ContentHandler
15 * @covers \MediaWiki\Content\FallbackContentHandler
16 * @covers \MediaWiki\Content\ContentHandler
17 */
18 class FallbackContentHandlerTest extends MediaWikiLangTestCase {
19
20 private const CONTENT_MODEL = 'xyzzy';
21
22 protected function setUp(): void {
23 parent::setUp();
24 $this->mergeMwGlobalArrayValue(
25 'wgContentHandlers',
26 [ self::CONTENT_MODEL => FallbackContentHandler::class ]
27 );
28 $this->setService( '_ParserObserver', $this->createMock( ParserObserver::class ) );
29 }
30
31 private function newContent( string $data, string $type = self::CONTENT_MODEL ) {
32 return new FallbackContent( $data, $type );
33 }
34
35 public function testGetSlotDiffRenderer() {
36 $context = new RequestContext();
37 $context->setRequest( new FauxRequest() );
38
39 $handler = new FallbackContentHandler( 'horkyporky' );
40 $this->hideDeprecated( 'ContentHandler::getSlotDiffRendererInternal' );
41 $slotDiffRenderer = $handler->getSlotDiffRenderer( $context );
42
43 $oldContent = $handler->unserializeContent( 'Foo' );
44 $newContent = $handler->unserializeContent( 'Foo bar' );
45
46 $diff = $slotDiffRenderer->getDiff( $oldContent, $newContent );
47 $this->assertNotEmpty( $diff );
48 }
49
50 public function testGetParserOutput() {
51 $this->setUserLang( 'en' );
52 $this->setContentLang( 'qqx' );
53
54 $title = $this->createMock( Title::class );
55 $title->method( 'getPageLanguage' )
56 ->willReturn( $this->getServiceContainer()->getContentLanguage() );
57
58 $content = $this->newContent( 'Horkyporky' );
59 $contentRenderer = $this->getServiceContainer()->getContentRenderer();
60 $opts = ParserOptions::newFromAnon();
61 // TODO T371004
62 $po = $contentRenderer->getParserOutput( $content, $title, null, $opts );
63 $html = $po->runOutputPipeline( $opts, [] )->getContentHolderText();
64 $html = preg_replace( '#<!--.*?-->#sm', '', $html ); // strip comments
65
66 $this->assertStringNotContainsString( 'Horkyporky', $html );
67 $this->assertStringNotContainsString( '(unsupported-content-model)', $html );
68 }
69 }