Merge "FauxRequest: don’t override getValues()"
[lhc/web/wiklou.git] / tests / phpunit / includes / content / UnknownContentHandlerTest.php
1 <?php
2
3 use MediaWiki\Revision\SlotRecord;
4 use MediaWiki\Revision\SlotRenderingProvider;
5
6 /**
7 * @group ContentHandler
8 */
9 class UnknownContentHandlerTest extends MediaWikiLangTestCase {
10 /**
11 * @covers UnknownContentHandler::supportsDirectEditing
12 */
13 public function testSupportsDirectEditing() {
14 $handler = new UnknownContentHandler( 'horkyporky' );
15 $this->assertFalse( $handler->supportsDirectEditing(), 'direct editing supported' );
16 }
17
18 /**
19 * @covers UnknownContentHandler::serializeContent
20 */
21 public function testSerializeContent() {
22 $handler = new UnknownContentHandler( 'horkyporky' );
23 $content = new UnknownContent( 'hello world', 'horkyporky' );
24
25 $this->assertEquals( 'hello world', $handler->serializeContent( $content ) );
26 $this->assertEquals(
27 'hello world',
28 $handler->serializeContent( $content, 'application/horkyporky' )
29 );
30 }
31
32 /**
33 * @covers UnknownContentHandler::unserializeContent
34 */
35 public function testUnserializeContent() {
36 $handler = new UnknownContentHandler( '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 /**
45 * @covers UnknownContentHandler::makeEmptyContent
46 */
47 public function testMakeEmptyContent() {
48 $handler = new UnknownContentHandler( 'horkyporky' );
49 $content = $handler->makeEmptyContent();
50
51 $this->assertTrue( $content->isEmpty() );
52 $this->assertSame( '', $content->getData() );
53 }
54
55 public static function dataIsSupportedFormat() {
56 return [
57 [ null, true ],
58 [ 'application/octet-stream', true ],
59 [ 'unknown/unknown', true ],
60 [ 'text/plain', false ],
61 [ 99887766, false ],
62 ];
63 }
64
65 /**
66 * @dataProvider dataIsSupportedFormat
67 * @covers UnknownContentHandler::isSupportedFormat
68 */
69 public function testIsSupportedFormat( $format, $supported ) {
70 $handler = new UnknownContentHandler( 'horkyporky' );
71 $this->assertEquals( $supported, $handler->isSupportedFormat( $format ) );
72 }
73
74 /**
75 * @covers ContentHandler::getSecondaryDataUpdates
76 */
77 public function testGetSecondaryDataUpdates() {
78 $title = Title::newFromText( 'Somefile.jpg', NS_FILE );
79 $content = new UnknownContent( '', 'horkyporky' );
80
81 /** @var SlotRenderingProvider $srp */
82 $srp = $this->getMock( SlotRenderingProvider::class );
83
84 $handler = new UnknownContentHandler( 'horkyporky' );
85 $updates = $handler->getSecondaryDataUpdates( $title, $content, SlotRecord::MAIN, $srp );
86
87 $this->assertEquals( [], $updates );
88 }
89
90 /**
91 * @covers ContentHandler::getDeletionUpdates
92 */
93 public function testGetDeletionUpdates() {
94 $title = Title::newFromText( 'Somefile.jpg', NS_FILE );
95
96 $handler = new UnknownContentHandler( 'horkyporky' );
97 $updates = $handler->getDeletionUpdates( $title, SlotRecord::MAIN );
98
99 $this->assertEquals( [], $updates );
100 }
101
102 /**
103 * @covers ContentHandler::getDeletionUpdates
104 */
105 public function testGetSlotDiffRenderer() {
106 $context = new RequestContext();
107 $context->setRequest( new FauxRequest() );
108
109 $handler = new UnknownContentHandler( 'horkyporky' );
110 $slotDiffRenderer = $handler->getSlotDiffRenderer( $context );
111
112 $oldContent = $handler->unserializeContent( 'Foo' );
113 $newContent = $handler->unserializeContent( 'Foo bar' );
114
115 $diff = $slotDiffRenderer->getDiff( $oldContent, $newContent );
116 $this->assertNotEmpty( $diff );
117 }
118
119 }