From: jdlrobson Date: Wed, 15 Nov 2017 19:11:02 +0000 (-0800) Subject: Add unit tests for Html helper methods and change messageBox visibility X-Git-Tag: 1.31.0-rc.0~1440^2 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=ba45450febab7e5d8aad439fb1e6da4b0d2a3ee9;p=lhc%2Fweb%2Fwiklou.git Add unit tests for Html helper methods and change messageBox visibility * Messagebox is now private to Html class to discourage unconventional usages * Tests are added for all three helper methods added in 4e7021a2318 Bug: T166915 Change-Id: I1c3e4131b2439c0f4fb94ad4e616a909b52d6b78 --- diff --git a/includes/Html.php b/includes/Html.php index 524fdcd7d9..dfd80a8c43 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -683,7 +683,7 @@ class Html { * @param string $heading (optional) * @return string of HTML representing a box. */ - public static function messageBox( $html, $className, $heading = '' ) { + private static function messageBox( $html, $className, $heading = '' ) { if ( $heading ) { $html = self::element( 'h2', [], $heading ) . $html; } diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index f3d49161a5..e867f5ec7b 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -447,6 +447,47 @@ class HtmlTest extends MediaWikiTestCase { ); } + /** + * @covers Html::warningBox + * @covers Html::messageBox + */ + public function testWarningBox() { + $this->assertEquals( + Html::warningBox( 'warn' ), + '
warn
' + ); + } + + /** + * @covers Html::errorBox + * @covers Html::messageBox + */ + public function testErrorBox() { + $this->assertEquals( + Html::errorBox( 'err' ), + '
err
' + ); + $this->assertEquals( + Html::errorBox( 'err', 'heading' ), + '

heading

err
' + ); + } + + /** + * @covers Html::successBox + * @covers Html::messageBox + */ + public function testSuccessBox() { + $this->assertEquals( + Html::successBox( 'great' ), + '
great
' + ); + $this->assertEquals( + Html::successBox( '' ), + '
' + ); + } + /** * List of input element types values introduced by HTML5 * Full list at https://www.w3.org/TR/html-markup/input.html