2019-08-21 15:51:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
|
|
|
|
use MediaWiki\Revision\SlotRenderingProvider;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group ContentHandler
|
|
|
|
|
*/
|
|
|
|
|
class UnknownContentHandlerTest extends MediaWikiLangTestCase {
|
|
|
|
|
/**
|
|
|
|
|
* @covers UnknownContentHandler::supportsDirectEditing
|
|
|
|
|
*/
|
|
|
|
|
public function testSupportsDirectEditing() {
|
|
|
|
|
$handler = new UnknownContentHandler( 'horkyporky' );
|
|
|
|
|
$this->assertFalse( $handler->supportsDirectEditing(), 'direct editing supported' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers UnknownContentHandler::serializeContent
|
|
|
|
|
*/
|
|
|
|
|
public function testSerializeContent() {
|
|
|
|
|
$handler = new UnknownContentHandler( 'horkyporky' );
|
|
|
|
|
$content = new UnknownContent( 'hello world', 'horkyporky' );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( 'hello world', $handler->serializeContent( $content ) );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'hello world',
|
|
|
|
|
$handler->serializeContent( $content, 'application/horkyporky' )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers UnknownContentHandler::unserializeContent
|
|
|
|
|
*/
|
|
|
|
|
public function testUnserializeContent() {
|
|
|
|
|
$handler = new UnknownContentHandler( 'horkyporky' );
|
|
|
|
|
$content = $handler->unserializeContent( 'hello world' );
|
|
|
|
|
$this->assertEquals( 'hello world', $content->getData() );
|
|
|
|
|
|
|
|
|
|
$content = $handler->unserializeContent( 'hello world', 'application/horkyporky' );
|
|
|
|
|
$this->assertEquals( 'hello world', $content->getData() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers UnknownContentHandler::makeEmptyContent
|
|
|
|
|
*/
|
|
|
|
|
public function testMakeEmptyContent() {
|
|
|
|
|
$handler = new UnknownContentHandler( 'horkyporky' );
|
|
|
|
|
$content = $handler->makeEmptyContent();
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $content->isEmpty() );
|
2019-09-17 14:28:35 +00:00
|
|
|
$this->assertSame( '', $content->getData() );
|
2019-08-21 15:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function dataIsSupportedFormat() {
|
|
|
|
|
return [
|
|
|
|
|
[ null, true ],
|
|
|
|
|
[ 'application/octet-stream', true ],
|
|
|
|
|
[ 'unknown/unknown', true ],
|
|
|
|
|
[ 'text/plain', false ],
|
|
|
|
|
[ 99887766, false ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataIsSupportedFormat
|
|
|
|
|
* @covers UnknownContentHandler::isSupportedFormat
|
|
|
|
|
*/
|
|
|
|
|
public function testIsSupportedFormat( $format, $supported ) {
|
|
|
|
|
$handler = new UnknownContentHandler( 'horkyporky' );
|
|
|
|
|
$this->assertEquals( $supported, $handler->isSupportedFormat( $format ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getSecondaryDataUpdates
|
|
|
|
|
*/
|
|
|
|
|
public function testGetSecondaryDataUpdates() {
|
|
|
|
|
$title = Title::newFromText( 'Somefile.jpg', NS_FILE );
|
|
|
|
|
$content = new UnknownContent( '', 'horkyporky' );
|
|
|
|
|
|
|
|
|
|
/** @var SlotRenderingProvider $srp */
|
2019-10-05 22:14:35 +00:00
|
|
|
$srp = $this->createMock( SlotRenderingProvider::class );
|
2019-08-21 15:51:10 +00:00
|
|
|
|
|
|
|
|
$handler = new UnknownContentHandler( 'horkyporky' );
|
|
|
|
|
$updates = $handler->getSecondaryDataUpdates( $title, $content, SlotRecord::MAIN, $srp );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( [], $updates );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getDeletionUpdates
|
|
|
|
|
*/
|
|
|
|
|
public function testGetDeletionUpdates() {
|
|
|
|
|
$title = Title::newFromText( 'Somefile.jpg', NS_FILE );
|
|
|
|
|
|
|
|
|
|
$handler = new UnknownContentHandler( 'horkyporky' );
|
|
|
|
|
$updates = $handler->getDeletionUpdates( $title, SlotRecord::MAIN );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( [], $updates );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ContentHandler::getDeletionUpdates
|
|
|
|
|
*/
|
|
|
|
|
public function testGetSlotDiffRenderer() {
|
|
|
|
|
$context = new RequestContext();
|
|
|
|
|
$context->setRequest( new FauxRequest() );
|
|
|
|
|
|
|
|
|
|
$handler = new UnknownContentHandler( 'horkyporky' );
|
|
|
|
|
$slotDiffRenderer = $handler->getSlotDiffRenderer( $context );
|
|
|
|
|
|
|
|
|
|
$oldContent = $handler->unserializeContent( 'Foo' );
|
|
|
|
|
$newContent = $handler->unserializeContent( 'Foo bar' );
|
|
|
|
|
|
|
|
|
|
$diff = $slotDiffRenderer->getDiff( $oldContent, $newContent );
|
|
|
|
|
$this->assertNotEmpty( $diff );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|