DAT-2811 make sure there are no whitespaces in class name

This commit is contained in:
Adam Robak 2015-05-22 12:18:54 +02:00 committed by rafal.kalinski
parent fce26a692d
commit e5ca491c07
2 changed files with 34 additions and 2 deletions

View file

@ -102,10 +102,12 @@ class PortableInfoboxParserTagController extends WikiaController {
private function getThemeWithDefault( $params, PPFrame $frame ) {
$value = isset( $params[ 'theme-source' ] ) ? $frame->getArgument( $params[ 'theme-source' ] ) : false;
return self::INFOBOX_THEME_PREFIX . $this->getThemePrefix( $params, $value );
$themeName = $this->getThemeName( $params, $value );
//make sure no whitespaces, prevents side effects
return self::INFOBOX_THEME_PREFIX . preg_replace( '|\s+|s', '-', $themeName );
}
private function getThemePrefix( $params, $value ) {
private function getThemeName( $params, $value ) {
return !empty( $value ) ? $value :
// default logic
( isset( $params[ 'theme' ] ) ? $params[ 'theme' ] : self::DEFAULT_THEME_NAME );

View file

@ -94,4 +94,34 @@ class PortableInfoboxParserTagControllerTest extends WikiaBaseTest {
PortableInfoboxParserTagController::INFOBOX_THEME_PREFIX . PortableInfoboxParserTagController::DEFAULT_THEME_NAME
) );
}
public function testWhiteSpacedThemeInfobox() {
$text = '<data><default>test</default></data>';
$defaultTheme = 'test test';
$expectedName = 'test-test';
$marker = $this->controller->renderInfobox( $text, [ 'theme' => $defaultTheme ], $this->parser,
$this->parser->getPreprocessor()->newFrame() )[ 0 ];
$output = $this->controller->replaceMarkers( $marker );
$this->assertTrue( $this->checkClassName(
$output,
PortableInfoboxParserTagController::INFOBOX_THEME_PREFIX . $expectedName
) );
}
public function testMultiWhiteSpacedThemeInfobox() {
$text = '<data><default>test</default></data>';
$defaultTheme = "test test\n test\ttest";
$expectedName = 'test-test-test-test';
$marker = $this->controller->renderInfobox( $text, [ 'theme' => $defaultTheme ], $this->parser,
$this->parser->getPreprocessor()->newFrame() )[ 0 ];
$output = $this->controller->replaceMarkers( $marker );
$this->assertTrue( $this->checkClassName(
$output,
PortableInfoboxParserTagController::INFOBOX_THEME_PREFIX . $expectedName
) );
}
}