| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Content\FallbackContent; |
| 4 |
use MediaWiki\Content\FallbackContentHandler; |
| 5 |
use MediaWiki\Content\TextContent; |
| 6 |
use MediaWiki\Content\TextContentHandler; |
| 7 |
use MediaWiki\Message\Message; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class UnsupportedSlotDiffRendererTest extends MediaWikiUnitTestCase { |
| 13 |
|
| 14 |
public function provideDiff() { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
$oldContent = $this->createMock( TextContent::class ); |
| 20 |
$oldContent->method( 'getModel' )->willReturn( CONTENT_MODEL_TEXT ); |
| 21 |
$oldContent->method( 'getContentHandler' )->willReturn( new TextContentHandler() ); |
| 22 |
|
| 23 |
$newContent = $this->createMock( TextContent::class ); |
| 24 |
$newContent->method( 'getModel' )->willReturn( CONTENT_MODEL_TEXT ); |
| 25 |
$newContent->method( 'getContentHandler' )->willReturn( new TextContentHandler() ); |
| 26 |
|
| 27 |
$badContent = $this->createMock( FallbackContent::class ); |
| 28 |
$badContent->method( 'getModel' )->willReturn( 'xyzzy' ); |
| 29 |
$badContent->method( 'getContentHandler' )->willReturn( new FallbackContentHandler( 'xyzzy' ) ); |
| 30 |
|
| 31 |
yield [ '(unsupported-content-diff)', $oldContent, null ]; |
| 32 |
yield [ '(unsupported-content-diff)', null, $newContent ]; |
| 33 |
yield [ '(unsupported-content-diff)', $oldContent, $newContent ]; |
| 34 |
yield [ '(unsupported-content-diff2)', $badContent, $newContent ]; |
| 35 |
yield [ '(unsupported-content-diff2)', $oldContent, $badContent ]; |
| 36 |
yield [ '(unsupported-content-diff)', null, $badContent ]; |
| 37 |
yield [ '(unsupported-content-diff)', $badContent, null ]; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public function testDiff( $expected, $oldContent, $newContent ) { |
| 44 |
$localizer = $this->createMock( MessageLocalizer::class ); |
| 45 |
|
| 46 |
$localizer->method( 'msg' ) |
| 47 |
->willReturnCallback( function ( $key, ...$params ) { |
| 48 |
$msg = $this->createMock( Message::class ); |
| 49 |
$msg->method( 'parse' )->willReturn( "($key)" ); |
| 50 |
return $msg; |
| 51 |
} ); |
| 52 |
|
| 53 |
$sdr = new UnsupportedSlotDiffRenderer( $localizer ); |
| 54 |
$this->assertStringContainsString( $expected, $sdr->getDiff( $oldContent, $newContent ) ); |
| 55 |
} |
| 56 |
|
| 57 |
} |