wiki.techinc.nl/tests/phpunit/includes/content/Transform/ContentTransformerTest.php
Timo Tijhof 64734f61ee content: Widen @covers tags in phpunit tests
https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

> Given all called methods are de-facto and liberally claimed, and
> that we keep the coverage limited to the subject class, it maintains
> the spirit and intent by listing the class explicitly instead.
>
> PHPUnit offers a more precise tool when you need it (i.e. when testing
> legacy monster/god classes), but for well-written code, the
> class-wide tag is exactly what you want.
>
> We lose useful coverage and waste valuable time on keeping tags
> accurate through refactors (or worse, forget to do so).
> Tracking tiny per-method details wastes time in realizing (and
> fixing) when people inevitably don't keep them in sync, and time
> lost in finding uncovered code to write tests to realize it was
> already covered but "not yet claimed".

While at it, also fix PHPUnit warnings in CssContentHandlerIntegrationTest
and JavaScriptContentHandlerIntegrationTest about not having any
`@covers` annotations.

Change-Id: I5afd9fe0bca0fa86cc096f6e5e79f2ba1cfbfa77
2024-07-21 21:03:10 +00:00

57 lines
1.6 KiB
PHP

<?php
use MediaWiki\MainConfigNames;
use MediaWiki\Title\Title;
use MediaWiki\User\User;
/**
* @covers \MediaWiki\Content\Transform\ContentTransformer
*/
class ContentTransformerTest extends MediaWikiIntegrationTestCase {
public static function preSaveTransformProvider() {
return [
[
new WikitextContent( 'Test ~~~' ),
'Test [[Special:Contributions/127.0.0.1|127.0.0.1]]'
],
];
}
/**
*
* @dataProvider preSaveTransformProvider
*/
public function testPreSaveTransform( $content, $expectedContainText ) {
$this->overrideConfigValue( MainConfigNames::LanguageCode, 'en' );
$services = $this->getServiceContainer();
$title = Title::makeTitle( NS_MAIN, 'Test' );
$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() );
}
public static function preloadTransformProvider() {
return [
[
new WikitextContent( '{{Foo}}<noinclude> censored</noinclude> information <!-- is very secret -->' ),
'{{Foo}} information <!-- is very secret -->'
],
];
}
/**
* @dataProvider preloadTransformProvider
*/
public function testPreloadTransform( $content, $expectedContainText ) {
$services = $this->getServiceContainer();
$title = Title::makeTitle( NS_MAIN, 'Test' );
$options = ParserOptions::newFromAnon();
$newContent = $services->getContentTransformer()->preloadTransform( $content, $title, $options );
$this->assertSame( $expectedContainText, $newContent->serialize() );
}
}