1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
<?php
use MediaWiki\Installer\DatabaseInstaller;
use MediaWiki\Installer\Installer;
use MediaWiki\Installer\LocalSettingsGenerator;
/**
* @covers \MediaWiki\Installer\LocalSettingsGenerator
*/
class LocalSettingsGeneratorTest extends MediaWikiUnitTestCase {
private function getLocalSettingsGenerator( array $vars ): LocalSettingsGenerator {
$vars += [
'_Extensions' => [],
'_Skins' => []
];
$db = $this->createMock( DatabaseInstaller::class );
$db->method( 'getGlobalNames' )
->willReturn( [
'wgDBserver',
'wgDBname',
'wgDBuser',
'wgDBpassword',
'wgDBssl',
'wgDBprefix',
'wgDBTableOptions',
] );
$installer = $this->createMock( Installer::class );
$installer->method( 'getVar' )
->willReturnCallback( fn ( string $name ) => $vars[$name] ?? '' );
$installer->method( 'getDBInstaller' )
->willReturn( $db );
return new LocalSettingsGenerator( $installer );
}
// T372569, T355013
public function testShouldEscapeUserInput(): void {
$generator = $this->getLocalSettingsGenerator( [
'wgSitename' => "Sitename with 'apostrophe",
'wgDBpassword' => 'dollar$'
] );
$settings = $generator->getText();
$this->assertStringContainsString(
'$wgSitename = "Sitename with \'apostrophe";',
$settings
);
$this->assertStringContainsString(
'$wgDBpassword = "dollar\$"',
$settings
);
}
}
|