Show warnings in HTMLForm and warnings as warnings on Login/Signup form
[lhc/web/wiklou.git] / tests / phpunit / includes / StatusTest.php
index 782fab0..ebc2d10 100644 (file)
@@ -376,9 +376,9 @@ class StatusTest extends MediaWikiLangTestCase {
                $status->warning( 'fooBar!' );
                $testCases['1StringWarning'] = [
                        $status,
-                       "<fooBar!>",
+                       "⧼fooBar!⧽",
                        "(wrap-short: (fooBar!))",
-                       "<p>&lt;fooBar!&gt;\n</p>",
+                       "<p>⧼fooBar!⧽\n</p>",
                        "<p>(wrap-short: (fooBar!))\n</p>",
                ];
 
@@ -387,9 +387,9 @@ class StatusTest extends MediaWikiLangTestCase {
                $status->warning( 'fooBar2!' );
                $testCases['2StringWarnings'] = [
                        $status,
-                       "* <fooBar!>\n* <fooBar2!>\n",
+                       "* ⧼fooBar!⧽\n* ⧼fooBar2!⧽\n",
                        "(wrap-long: * (fooBar!)\n* (fooBar2!)\n)",
-                       "<ul><li> &lt;fooBar!&gt;</li>\n<li> &lt;fooBar2!&gt;</li></ul>\n",
+                       "<ul><li> ⧼fooBar!⧽</li>\n<li> ⧼fooBar2!⧽</li></ul>\n",
                        "<p>(wrap-long: * (fooBar!)\n</p>\n<ul><li> (fooBar2!)</li></ul>\n<p>)\n</p>",
                ];
 
@@ -397,9 +397,9 @@ class StatusTest extends MediaWikiLangTestCase {
                $status->warning( new Message( 'fooBar!', [ 'foo', 'bar' ] ) );
                $testCases['1MessageWarning'] = [
                        $status,
-                       "<fooBar!>",
+                       "⧼fooBar!⧽",
                        "(wrap-short: (fooBar!: foo, bar))",
-                       "<p>&lt;fooBar!&gt;\n</p>",
+                       "<p>⧼fooBar!⧽\n</p>",
                        "<p>(wrap-short: (fooBar!: foo, bar))\n</p>",
                ];
 
@@ -408,9 +408,9 @@ class StatusTest extends MediaWikiLangTestCase {
                $status->warning( new Message( 'fooBar2!' ) );
                $testCases['2MessageWarnings'] = [
                        $status,
-                       "* <fooBar!>\n* <fooBar2!>\n",
+                       "* ⧼fooBar!⧽\n* ⧼fooBar2!⧽\n",
                        "(wrap-long: * (fooBar!: foo, bar)\n* (fooBar2!)\n)",
-                       "<ul><li> &lt;fooBar!&gt;</li>\n<li> &lt;fooBar2!&gt;</li></ul>\n",
+                       "<ul><li> ⧼fooBar!⧽</li>\n<li> ⧼fooBar2!⧽</li></ul>\n",
                        "<p>(wrap-long: * (fooBar!: foo, bar)\n</p>\n<ul><li> (fooBar2!)</li></ul>\n<p>)\n</p>",
                ];
 
@@ -645,4 +645,66 @@ class StatusTest extends MediaWikiLangTestCase {
                ];
        }
 
+       /**
+        * @dataProvider provideErrorsWarningsOnly
+        * @covers Status::getErrorsOnlyStatus
+        * @covers Status::getWarningsOnlyStatus
+        */
+       public function testGetErrorsWarningsOnlyStatus( $errorText, $warningText, $type, $errorResult,
+               $warningResult
+       ) {
+               $status = Status::newGood();
+               if ( $errorText ) {
+                       $status->fatal( $errorText );
+               }
+               if ( $warningText ) {
+                       $status->warning( $warningText );
+               }
+               $testStatus = $status->splitByErrorType()[$type];
+               $this->assertEquals( $errorResult, $testStatus->getErrorsByType( 'error' ) );
+               $this->assertEquals( $warningResult, $testStatus->getErrorsByType( 'warning' ) );
+       }
+
+       public static function provideErrorsWarningsOnly() {
+               return [
+                       [
+                               'Just an error',
+                               'Just a warning',
+                               0,
+                               [
+                                       0 => [
+                                               'type' => 'error',
+                                               'message' => 'Just an error',
+                                               'params' => []
+                                       ],
+                               ],
+                               [],
+                       ], [
+                               'Just an error',
+                               'Just a warning',
+                               1,
+                               [],
+                               [
+                                       0 => [
+                                               'type' => 'warning',
+                                               'message' => 'Just a warning',
+                                               'params' => []
+                                       ],
+                               ],
+                       ], [
+                               null,
+                               null,
+                               1,
+                               [],
+                               [],
+                       ], [
+                               null,
+                               null,
+                               0,
+                               [],
+                               [],
+                       ]
+               ];
+       }
+
 }