mediawiki-extensions-Templa.../tests/phpunit/TemplateStylesCodeEditorHooksTest.php
Umherirrender 8808ab0a15 tests: Cover CodeEditorHooks
Change-Id: I8a094d14347bb58850b7f864320f30420b18460f
2023-11-06 19:46:50 +00:00

45 lines
1.1 KiB
PHP

<?php
use MediaWiki\Extension\TemplateStyles\CodeEditorHooks;
use MediaWiki\Title\Title;
/**
* @group TemplateStyles
* @covers \MediaWiki\Extension\TemplateStyles\CodeEditorHooks
*/
class TemplateStylesCodeEditorHooksTest extends MediaWikiLangTestCase {
protected function setUp(): void {
parent::setUp();
$this->markTestSkippedIfExtensionNotLoaded( 'CodeEditor' );
}
/**
* @dataProvider provideOnCodeEditorGetPageLanguage
*/
public function testOnCodeEditorGetPageLanguage( $useCodeEditor, $model, $expect ) {
$this->setMwGlobals( [
'wgTemplateStylesUseCodeEditor' => $useCodeEditor,
] );
$title = Title::makeTitle( NS_TEMPLATE, 'Test.css' );
$lang = 'unchanged';
$ret = ( new CodeEditorHooks )->onCodeEditorGetPageLanguage(
$title, $lang, $model, 'text/x-whatever'
);
$this->assertSame( !$expect, $ret );
$this->assertSame( $expect ? 'css' : 'unchanged', $lang );
}
public static function provideOnCodeEditorGetPageLanguage() {
return [
[ true, 'wikitext', false ],
[ true, 'css', false ],
[ true, 'sanitized-css', true ],
[ false, 'sanitized-css', false ],
];
}
}