Html: Fixes Error: [] operator not supported for strings

Bug: T341534
Change-Id: Iba9101e5fcf83f547b864c5782866962a3772a3f
This commit is contained in:
Jon Robson 2023-07-10 16:15:07 -07:00 committed by Jdlrobson
parent f6a789e274
commit f6a674bc37
2 changed files with 19 additions and 2 deletions

View file

@ -152,8 +152,9 @@ class Html {
if ( isset( $attrs['class'] ) ) {
$classAsArray = is_string( $attrs[ 'class' ] ) ? explode( ' ', $attrs[ 'class' ] ) : $attrs[ 'class' ];
if ( !in_array( $cdxInputClass, $classAsArray ) ) {
$attrs['class'][] = 'mw-ui-input';
$classAsArray[] = 'mw-ui-input';
}
$attrs['class'] = $classAsArray;
} else {
$attrs['class'] = 'mw-ui-input';
}

View file

@ -11,7 +11,6 @@ class HtmlTest extends MediaWikiIntegrationTestCase {
protected function setUp(): void {
parent::setUp();
$this->overrideConfigValue( MainConfigNames::UseMediaWikiUIEverywhere, false );
$this->overrideConfigValue( MainConfigNames::UsePigLatinVariant, false );
$langFactory = $this->getServiceContainer()->getLanguageFactory();
@ -831,6 +830,23 @@ class HtmlTest extends MediaWikiIntegrationTestCase {
}
$this->assertSame( $expected, $html );
}
public function testGetTextInputAttributes() {
$this->setMwGlobals( 'wgUseMediaWikiUIEverywhere', true );
$attrs = Html::getTextInputAttributes( [ 'class' => 'foo' ] );
$attrsNew = Html::getTextInputAttributes( [ 'class' => 'cdx-text-input__input' ] );
$attrsArray = Html::getTextInputAttributes( [
'class' => [ 'foo' ]
] );
$attrsArrayNew = Html::getTextInputAttributes( [
'class' => [ 'cdx-text-input__input', 'bar' ]
] );
$this->assertSame( [ 'foo', 'mw-ui-input' ], $attrs[ 'class' ] );
$this->assertSame( [ 'cdx-text-input__input' ], $attrsNew[ 'class' ] );
$this->assertSame( [ 'foo', 'mw-ui-input' ], $attrsArray[ 'class' ] );
$this->assertSame( [ 'cdx-text-input__input', 'bar' ], $attrsArrayNew[ 'class' ] );
}
}
class HtmlTestValue {