mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 11:59:56 +00:00
DAT-2811 make sure there are no whitespaces in class name
This commit is contained in:
parent
fce26a692d
commit
e5ca491c07
|
@ -102,10 +102,12 @@ class PortableInfoboxParserTagController extends WikiaController {
|
||||||
|
|
||||||
private function getThemeWithDefault( $params, PPFrame $frame ) {
|
private function getThemeWithDefault( $params, PPFrame $frame ) {
|
||||||
$value = isset( $params[ 'theme-source' ] ) ? $frame->getArgument( $params[ 'theme-source' ] ) : false;
|
$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 :
|
return !empty( $value ) ? $value :
|
||||||
// default logic
|
// default logic
|
||||||
( isset( $params[ 'theme' ] ) ? $params[ 'theme' ] : self::DEFAULT_THEME_NAME );
|
( isset( $params[ 'theme' ] ) ? $params[ 'theme' ] : self::DEFAULT_THEME_NAME );
|
||||||
|
|
|
@ -94,4 +94,34 @@ class PortableInfoboxParserTagControllerTest extends WikiaBaseTest {
|
||||||
PortableInfoboxParserTagController::INFOBOX_THEME_PREFIX . PortableInfoboxParserTagController::DEFAULT_THEME_NAME
|
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
|
||||||
|
) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue