| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Unit; |
| 4 |
|
| 5 |
use MediaWiki\Content\FallbackContent; |
| 6 |
use MediaWiki\Content\FallbackContentHandler; |
| 7 |
use MediaWiki\Revision\SlotRecord; |
| 8 |
use MediaWiki\Revision\SlotRenderingProvider; |
| 9 |
use MediaWiki\Title\Title; |
| 10 |
use MediaWikiUnitTestCase; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
class FallbackContentHandlerTest extends MediaWikiUnitTestCase { |
| 19 |
public function testSupportsDirectEditing() { |
| 20 |
$handler = new FallbackContentHandler( 'horkyporky' ); |
| 21 |
$this->assertFalse( $handler->supportsDirectEditing(), 'direct editing supported' ); |
| 22 |
} |
| 23 |
|
| 24 |
public function testSerializeContent() { |
| 25 |
$handler = new FallbackContentHandler( 'horkyporky' ); |
| 26 |
$content = new FallbackContent( 'hello world', 'horkyporky' ); |
| 27 |
|
| 28 |
$this->assertEquals( 'hello world', $handler->serializeContent( $content ) ); |
| 29 |
$this->assertEquals( |
| 30 |
'hello world', |
| 31 |
$handler->serializeContent( $content, 'application/horkyporky' ) |
| 32 |
); |
| 33 |
} |
| 34 |
|
| 35 |
public function testUnserializeContent() { |
| 36 |
$handler = new FallbackContentHandler( 'horkyporky' ); |
| 37 |
$content = $handler->unserializeContent( 'hello world' ); |
| 38 |
$this->assertEquals( 'hello world', $content->getData() ); |
| 39 |
|
| 40 |
$content = $handler->unserializeContent( 'hello world', 'application/horkyporky' ); |
| 41 |
$this->assertEquals( 'hello world', $content->getData() ); |
| 42 |
} |
| 43 |
|
| 44 |
public function testMakeEmptyContent() { |
| 45 |
$handler = new FallbackContentHandler( 'horkyporky' ); |
| 46 |
$content = $handler->makeEmptyContent(); |
| 47 |
|
| 48 |
$this->assertTrue( $content->isEmpty() ); |
| 49 |
$this->assertSame( '', $content->getData() ); |
| 50 |
} |
| 51 |
|
| 52 |
public function dataIsSupportedFormat() { |
| 53 |
return [ |
| 54 |
[ null, true ], |
| 55 |
[ 'application/octet-stream', true ], |
| 56 |
[ 'unknown/unknown', true ], |
| 57 |
[ 'text/plain', false ], |
| 58 |
[ 99887766, false ], |
| 59 |
]; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public function testIsSupportedFormat( $format, $supported ) { |
| 66 |
$handler = new FallbackContentHandler( 'horkyporky' ); |
| 67 |
$this->assertEquals( $supported, $handler->isSupportedFormat( $format ) ); |
| 68 |
} |
| 69 |
|
| 70 |
public function testGetSecondaryDataUpdates() { |
| 71 |
$title = $this->createMock( Title::class ); |
| 72 |
$content = new FallbackContent( '', 'horkyporky' ); |
| 73 |
$srp = $this->createMock( SlotRenderingProvider::class ); |
| 74 |
$handler = new FallbackContentHandler( 'horkyporky' ); |
| 75 |
|
| 76 |
$updates = $handler->getSecondaryDataUpdates( $title, $content, SlotRecord::MAIN, $srp ); |
| 77 |
$this->assertEquals( [], $updates ); |
| 78 |
} |
| 79 |
|
| 80 |
public function testGetDeletionUpdates() { |
| 81 |
$title = $this->createMock( Title::class ); |
| 82 |
$handler = new FallbackContentHandler( 'horkyporky' ); |
| 83 |
|
| 84 |
$updates = $handler->getDeletionUpdates( $title, SlotRecord::MAIN ); |
| 85 |
$this->assertEquals( [], $updates ); |
| 86 |
} |
| 87 |
|
| 88 |
} |