Add unit tests for Html helper methods and change messageBox visibility
authorjdlrobson <jdlrobson@gmail.com>
Wed, 15 Nov 2017 19:11:02 +0000 (11:11 -0800)
committerLegoktm <legoktm@member.fsf.org>
Tue, 21 Nov 2017 21:11:28 +0000 (21:11 +0000)
* 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

includes/Html.php
tests/phpunit/includes/HtmlTest.php

index 524fdcd..dfd80a8 100644 (file)
@@ -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;
                }
index f3d4916..e867f5e 100644 (file)
@@ -447,6 +447,47 @@ class HtmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Html::warningBox
+        * @covers Html::messageBox
+        */
+       public function testWarningBox() {
+               $this->assertEquals(
+                       Html::warningBox( 'warn' ),
+                       '<div class="warningbox">warn</div>'
+               );
+       }
+
+       /**
+        * @covers Html::errorBox
+        * @covers Html::messageBox
+        */
+       public function testErrorBox() {
+               $this->assertEquals(
+                       Html::errorBox( 'err' ),
+                       '<div class="errorbox">err</div>'
+               );
+               $this->assertEquals(
+                       Html::errorBox( 'err', 'heading' ),
+                       '<div class="errorbox"><h2>heading</h2>err</div>'
+               );
+       }
+
+       /**
+        * @covers Html::successBox
+        * @covers Html::messageBox
+        */
+       public function testSuccessBox() {
+               $this->assertEquals(
+                       Html::successBox( 'great' ),
+                       '<div class="successbox">great</div>'
+               );
+               $this->assertEquals(
+                       Html::successBox( '<script>beware no escaping!</script>' ),
+                       '<div class="successbox"><script>beware no escaping!</script></div>'
+               );
+       }
+
        /**
         * List of input element types values introduced by HTML5
         * Full list at https://www.w3.org/TR/html-markup/input.html