X-Git-Url: https://git.cyclocoop.org/%242?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fdiff%2FTextSlotDiffRendererTest.php;h=3eb12011d283c54b249df836d62425cad1cf237c;hb=eba2737ab9f27017bd269cf1b3129fe1cfffbb30;hp=e08efacd26f7e6c51ca82f5c3386f47d9fda89b7;hpb=d1592cdf05dd20fa0739301abbd78eb8eb1503f0;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/diff/TextSlotDiffRendererTest.php b/tests/phpunit/includes/diff/TextSlotDiffRendererTest.php index e08efacd26..3eb12011d2 100644 --- a/tests/phpunit/includes/diff/TextSlotDiffRendererTest.php +++ b/tests/phpunit/includes/diff/TextSlotDiffRendererTest.php @@ -9,14 +9,22 @@ class TextSlotDiffRendererTest extends MediaWikiTestCase { /** * @dataProvider provideGetDiff - * @param Content|null $oldContent - * @param Content|null $newContent + * @param array|null $oldContentArgs To pass to makeContent() (if not null) + * @param array|null $newContentArgs * @param string|Exception $expectedResult * @throws Exception */ public function testGetDiff( - Content $oldContent = null, Content $newContent = null, $expectedResult + array $oldContentArgs = null, array $newContentArgs = null, $expectedResult ) { + $this->mergeMwGlobalArrayValue( 'wgContentHandlers', [ + 'testing' => DummyContentHandlerForTesting::class, + 'testing-nontext' => DummyNonTextContentHandler::class, + ] ); + + $oldContent = $oldContentArgs ? self::makeContent( ...$oldContentArgs ) : null; + $newContent = $newContentArgs ? self::makeContent( ...$newContentArgs ) : null; + if ( $expectedResult instanceof Exception ) { $this->setExpectedException( get_class( $expectedResult ), $expectedResult->getMessage() ); } @@ -30,31 +38,26 @@ class TextSlotDiffRendererTest extends MediaWikiTestCase { $this->assertSame( $expectedResult, $plainDiff ); } - public function provideGetDiff() { - $this->mergeMwGlobalArrayValue( 'wgContentHandlers', [ - 'testing' => DummyContentHandlerForTesting::class, - 'testing-nontext' => DummyNonTextContentHandler::class, - ] ); - + public static function provideGetDiff() { return [ 'same text' => [ - $this->makeContent( "aaa\nbbb\nccc" ), - $this->makeContent( "aaa\nbbb\nccc" ), + [ "aaa\nbbb\nccc" ], + [ "aaa\nbbb\nccc" ], "", ], 'different text' => [ - $this->makeContent( "aaa\nbbb\nccc" ), - $this->makeContent( "aaa\nxxx\nccc" ), + [ "aaa\nbbb\nccc" ], + [ "aaa\nxxx\nccc" ], " aaa aaa\n-bbb+xxx\n ccc ccc", ], 'no right content' => [ - $this->makeContent( "aaa\nbbb\nccc" ), + [ "aaa\nbbb\nccc" ], null, "-aaa+ \n-bbb \n-ccc ", ], 'no left content' => [ null, - $this->makeContent( "aaa\nbbb\nccc" ), + [ "aaa\nbbb\nccc" ], "- +aaa\n +bbb\n +ccc", ], 'no content' => [ @@ -63,13 +66,13 @@ class TextSlotDiffRendererTest extends MediaWikiTestCase { new InvalidArgumentException( '$oldContent and $newContent cannot both be null' ), ], 'non-text left content' => [ - $this->makeContent( '', 'testing-nontext' ), - $this->makeContent( "aaa\nbbb\nccc" ), + [ '', 'testing-nontext' ], + [ "aaa\nbbb\nccc" ], new ParameterTypeException( '$oldContent', 'TextContent|null' ), ], 'non-text right content' => [ - $this->makeContent( "aaa\nbbb\nccc" ), - $this->makeContent( '', 'testing-nontext' ), + [ "aaa\nbbb\nccc" ], + [ '', 'testing-nontext' ], new ParameterTypeException( '$newContent', 'TextContent|null' ), ], ]; @@ -84,7 +87,6 @@ class TextSlotDiffRendererTest extends MediaWikiTestCase { $slotDiffRenderer = new TextSlotDiffRenderer(); $slotDiffRenderer->setStatsdDataFactory( new NullStatsdDataFactory() ); $slotDiffRenderer->setLanguage( Language::factory( 'en' ) ); - $slotDiffRenderer->setWikiDiff2MovedParagraphDetectionCutoff( 0 ); $slotDiffRenderer->setEngine( TextSlotDiffRenderer::ENGINE_PHP ); return $slotDiffRenderer; } @@ -108,7 +110,7 @@ class TextSlotDiffRendererTest extends MediaWikiTestCase { * @param string $model * @return null|TextContent */ - private function makeContent( $str, $model = CONTENT_MODEL_TEXT ) { + private static function makeContent( $str, $model = CONTENT_MODEL_TEXT ) { return ContentHandler::makeContent( $str, null, $model ); }