<?php
+use Wikimedia\Assert\ParameterTypeException;
+
/**
* @covers TextSlotDiffRenderer
*/
/**
* @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() );
}
$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' => [
new InvalidArgumentException( '$oldContent and $newContent cannot both be null' ),
],
'non-text left content' => [
- $this->makeContent( '', 'testing-nontext' ),
- $this->makeContent( "aaa\nbbb\nccc" ),
- new InvalidArgumentException( 'TextSlotDiffRenderer does not handle DummyNonTextContent' ),
+ [ '', 'testing-nontext' ],
+ [ "aaa\nbbb\nccc" ],
+ new ParameterTypeException( '$oldContent', 'TextContent|null' ),
],
'non-text right content' => [
- $this->makeContent( "aaa\nbbb\nccc" ),
- $this->makeContent( '', 'testing-nontext' ),
- new InvalidArgumentException( 'TextSlotDiffRenderer does not handle DummyNonTextContent' ),
+ [ "aaa\nbbb\nccc" ],
+ [ '', 'testing-nontext' ],
+ new ParameterTypeException( '$newContent', 'TextContent|null' ),
],
];
}
$slotDiffRenderer = new TextSlotDiffRenderer();
$slotDiffRenderer->setStatsdDataFactory( new NullStatsdDataFactory() );
$slotDiffRenderer->setLanguage( Language::factory( 'en' ) );
- $slotDiffRenderer->setWikiDiff2MovedParagraphDetectionCutoff( 0 );
$slotDiffRenderer->setEngine( TextSlotDiffRenderer::ENGINE_PHP );
return $slotDiffRenderer;
}
* @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 );
}