| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Content\WikitextContent; |
| 4 |
use MediaWiki\MainConfigNames; |
| 5 |
use MediaWiki\Parser\ParserOptions; |
| 6 |
use MediaWiki\Title\Title; |
| 7 |
use MediaWiki\User\User; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class ContentTransformerTest extends MediaWikiIntegrationTestCase { |
| 13 |
|
| 14 |
public static function preSaveTransformProvider() { |
| 15 |
return [ |
| 16 |
[ |
| 17 |
new WikitextContent( 'Test ~~~' ), |
| 18 |
'Test [[Special:Contributions/127.0.0.1|127.0.0.1]]' |
| 19 |
], |
| 20 |
]; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public function testPreSaveTransform( $content, $expectedContainText ) { |
| 28 |
$this->overrideConfigValue( MainConfigNames::LanguageCode, 'en' ); |
| 29 |
$services = $this->getServiceContainer(); |
| 30 |
$title = Title::makeTitle( NS_MAIN, 'Test' ); |
| 31 |
$user = new User(); |
| 32 |
$user->setName( "127.0.0.1" ); |
| 33 |
$options = ParserOptions::newFromUser( $user ); |
| 34 |
|
| 35 |
$newContent = $services->getContentTransformer()->preSaveTransform( $content, $title, $user, $options ); |
| 36 |
$this->assertSame( $expectedContainText, $newContent->serialize() ); |
| 37 |
} |
| 38 |
|
| 39 |
public static function preloadTransformProvider() { |
| 40 |
return [ |
| 41 |
[ |
| 42 |
new WikitextContent( '{{Foo}}<noinclude> censored</noinclude> information <!-- is very secret -->' ), |
| 43 |
'{{Foo}} information <!-- is very secret -->' |
| 44 |
], |
| 45 |
]; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function testPreloadTransform( $content, $expectedContainText ) { |
| 52 |
$services = $this->getServiceContainer(); |
| 53 |
$title = Title::makeTitle( NS_MAIN, 'Test' ); |
| 54 |
$options = ParserOptions::newFromAnon(); |
| 55 |
|
| 56 |
$newContent = $services->getContentTransformer()->preloadTransform( $content, $title, $options ); |
| 57 |
$this->assertSame( $expectedContainText, $newContent->serialize() ); |
| 58 |
} |
| 59 |
} |