3 use MediaWiki\Revision\SlotRecord
;
4 use MediaWiki\Revision\SlotRenderingProvider
;
7 * @group ContentHandler
9 class UnknownContentHandlerTest
extends MediaWikiLangTestCase
{
11 * @covers UnknownContentHandler::supportsDirectEditing
13 public function testSupportsDirectEditing() {
14 $handler = new UnknownContentHandler( 'horkyporky' );
15 $this->assertFalse( $handler->supportsDirectEditing(), 'direct editing supported' );
19 * @covers UnknownContentHandler::serializeContent
21 public function testSerializeContent() {
22 $handler = new UnknownContentHandler( 'horkyporky' );
23 $content = new UnknownContent( 'hello world', 'horkyporky' );
25 $this->assertEquals( 'hello world', $handler->serializeContent( $content ) );
28 $handler->serializeContent( $content, 'application/horkyporky' )
33 * @covers UnknownContentHandler::unserializeContent
35 public function testUnserializeContent() {
36 $handler = new UnknownContentHandler( 'horkyporky' );
37 $content = $handler->unserializeContent( 'hello world' );
38 $this->assertEquals( 'hello world', $content->getData() );
40 $content = $handler->unserializeContent( 'hello world', 'application/horkyporky' );
41 $this->assertEquals( 'hello world', $content->getData() );
45 * @covers UnknownContentHandler::makeEmptyContent
47 public function testMakeEmptyContent() {
48 $handler = new UnknownContentHandler( 'horkyporky' );
49 $content = $handler->makeEmptyContent();
51 $this->assertTrue( $content->isEmpty() );
52 $this->assertEquals( '', $content->getData() );
55 public static function dataIsSupportedFormat() {
58 [ 'application/octet-stream', true ],
59 [ 'unknown/unknown', true ],
60 [ 'text/plain', false ],
66 * @dataProvider dataIsSupportedFormat
67 * @covers UnknownContentHandler::isSupportedFormat
69 public function testIsSupportedFormat( $format, $supported ) {
70 $handler = new UnknownContentHandler( 'horkyporky' );
71 $this->assertEquals( $supported, $handler->isSupportedFormat( $format ) );
75 * @covers ContentHandler::getSecondaryDataUpdates
77 public function testGetSecondaryDataUpdates() {
78 $title = Title
::newFromText( 'Somefile.jpg', NS_FILE
);
79 $content = new UnknownContent( '', 'horkyporky' );
81 /** @var SlotRenderingProvider $srp */
82 $srp = $this->getMock( SlotRenderingProvider
::class );
84 $handler = new UnknownContentHandler( 'horkyporky' );
85 $updates = $handler->getSecondaryDataUpdates( $title, $content, SlotRecord
::MAIN
, $srp );
87 $this->assertEquals( [], $updates );
91 * @covers ContentHandler::getDeletionUpdates
93 public function testGetDeletionUpdates() {
94 $title = Title
::newFromText( 'Somefile.jpg', NS_FILE
);
96 $handler = new UnknownContentHandler( 'horkyporky' );
97 $updates = $handler->getDeletionUpdates( $title, SlotRecord
::MAIN
);
99 $this->assertEquals( [], $updates );
103 * @covers ContentHandler::getDeletionUpdates
105 public function testGetSlotDiffRenderer() {
106 $context = new RequestContext();
107 $context->setRequest( new FauxRequest() );
109 $handler = new UnknownContentHandler( 'horkyporky' );
110 $slotDiffRenderer = $handler->getSlotDiffRenderer( $context );
112 $oldContent = $handler->unserializeContent( 'Foo' );
113 $newContent = $handler->unserializeContent( 'Foo bar' );
115 $diff = $slotDiffRenderer->getDiff( $oldContent, $newContent );
116 $this->assertNotEmpty( $diff );