2021-07-21 01:03:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-08-06 13:40:20 +00:00
|
|
|
use MediaWiki\Content\WikitextContent;
|
2022-07-21 22:18:27 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-09-19 12:13:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2022-07-21 22:18:27 +00:00
|
|
|
|
2024-07-21 18:16:16 +00:00
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Content\Transform\ContentTransformer
|
|
|
|
|
*/
|
2021-07-21 01:03:59 +00:00
|
|
|
class ContentTransformerTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
|
2023-05-19 22:32:30 +00:00
|
|
|
public static function preSaveTransformProvider() {
|
2021-07-21 01:03:59 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
new WikitextContent( 'Test ~~~' ),
|
|
|
|
|
'Test [[Special:Contributions/127.0.0.1|127.0.0.1]]'
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider preSaveTransformProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testPreSaveTransform( $content, $expectedContainText ) {
|
2022-07-21 22:18:27 +00:00
|
|
|
$this->overrideConfigValue( MainConfigNames::LanguageCode, 'en' );
|
2022-01-12 20:13:39 +00:00
|
|
|
$services = $this->getServiceContainer();
|
2023-06-19 19:54:57 +00:00
|
|
|
$title = Title::makeTitle( NS_MAIN, 'Test' );
|
2021-07-21 01:03:59 +00:00
|
|
|
$user = new User();
|
|
|
|
|
$user->setName( "127.0.0.1" );
|
|
|
|
|
$options = ParserOptions::newFromUser( $user );
|
|
|
|
|
|
|
|
|
|
$newContent = $services->getContentTransformer()->preSaveTransform( $content, $title, $user, $options );
|
|
|
|
|
$this->assertSame( $expectedContainText, $newContent->serialize() );
|
|
|
|
|
}
|
2021-08-09 13:39:19 +00:00
|
|
|
|
2023-05-19 22:32:30 +00:00
|
|
|
public static function preloadTransformProvider() {
|
2021-08-09 13:39:19 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
new WikitextContent( '{{Foo}}<noinclude> censored</noinclude> information <!-- is very secret -->' ),
|
|
|
|
|
'{{Foo}} information <!-- is very secret -->'
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider preloadTransformProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testPreloadTransform( $content, $expectedContainText ) {
|
2022-01-12 20:13:39 +00:00
|
|
|
$services = $this->getServiceContainer();
|
2023-06-19 19:54:57 +00:00
|
|
|
$title = Title::makeTitle( NS_MAIN, 'Test' );
|
2021-08-09 13:39:19 +00:00
|
|
|
$options = ParserOptions::newFromAnon();
|
|
|
|
|
|
|
|
|
|
$newContent = $services->getContentTransformer()->preloadTransform( $content, $title, $options );
|
|
|
|
|
$this->assertSame( $expectedContainText, $newContent->serialize() );
|
|
|
|
|
}
|
2021-07-21 01:03:59 +00:00
|
|
|
}
|