X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Feditpage%2FTextboxBuilderTest.php;h=4195f968f55acdda4777c746ef51d5854ce1819b;hb=7c36faa73bf6105e0f66f2dd531440c9afe0b732;hp=668baddfe6c5192ec7c55e4b2db1ad65ccbb72ff;hpb=59c5caf10c47c0042ce1a4d824e21cb47efa166c;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/editpage/TextboxBuilderTest.php b/tests/phpunit/includes/editpage/TextboxBuilderTest.php index 668baddfe6..4195f968f5 100644 --- a/tests/phpunit/includes/editpage/TextboxBuilderTest.php +++ b/tests/phpunit/includes/editpage/TextboxBuilderTest.php @@ -86,4 +86,125 @@ class TextboxBuilderTest extends MediaWikiTestCase { // classes ok when nothing to be merged $this->assertSame( 'mw-editfont-monospace', $attribs3['class'] ); } + + public function provideMergeClassesIntoAttributes() { + return [ + [ + [], + [], + [], + ], + [ + [ 'mw-new-classname' ], + [], + [ 'class' => 'mw-new-classname' ], + ], + [ + [], + [ 'title' => 'My Title' ], + [ 'title' => 'My Title' ], + ], + [ + [ 'mw-new-classname' ], + [ 'title' => 'My Title' ], + [ 'title' => 'My Title', 'class' => 'mw-new-classname' ], + ], + [ + [ 'mw-new-classname' ], + [ 'class' => 'mw-existing-classname' ], + [ 'class' => 'mw-existing-classname mw-new-classname' ], + ], + [ + [ 'mw-new-classname', 'mw-existing-classname' ], + [ 'class' => 'mw-existing-classname' ], + [ 'class' => 'mw-existing-classname mw-new-classname' ], + ], + ]; + } + + /** + * @dataProvider provideMergeClassesIntoAttributes + */ + public function testMergeClassesIntoAttributes( $inputClasses, $inputAttributes, $expected ) { + $builder = new TextboxBuilder(); + $this->assertSame( + $expected, + $builder->mergeClassesIntoAttributes( $inputClasses, $inputAttributes ) + ); + } + + public function provideGetTextboxProtectionCSSClasses() { + return [ + [ + [ '' ], + [ 'isProtected' ], + [], + ], + [ + true, + [], + [], + ], + [ + true, + [ 'isProtected' ], + [ 'mw-textarea-protected' ] + ], + [ + true, + [ 'isProtected', 'isSemiProtected' ], + [ 'mw-textarea-sprotected' ], + ], + [ + true, + [ 'isProtected', 'isCascadeProtected' ], + [ 'mw-textarea-protected', 'mw-textarea-cprotected' ], + ], + [ + true, + [ 'isProtected', 'isCascadeProtected', 'isSemiProtected' ], + [ 'mw-textarea-sprotected', 'mw-textarea-cprotected' ], + ], + ]; + } + + /** + * @dataProvider provideGetTextboxProtectionCSSClasses + */ + public function testGetTextboxProtectionCSSClasses( + $restrictionLevels, + $protectionModes, + $expected + ) { + $this->setMwGlobals( [ + // set to trick MWNamespace::getRestrictionLevels + 'wgRestrictionLevels' => $restrictionLevels + ] ); + + $builder = new TextboxBuilder(); + $this->assertSame( $expected, $builder->getTextboxProtectionCSSClasses( + $this->mockProtectedTitle( $protectionModes ) + ) ); + } + + /** + * @return Title + */ + private function mockProtectedTitle( $methodsToReturnTrue ) { + $title = $this->getMockBuilder( Title::class ) + ->disableOriginalConstructor() + ->getMock(); + + $title->expects( $this->any() ) + ->method( 'getNamespace' ) + ->will( $this->returnValue( 1 ) ); + + foreach ( $methodsToReturnTrue as $method ) { + $title->expects( $this->any() ) + ->method( $method ) + ->will( $this->returnValue( true ) ); + } + + return $title; + } }