jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/400131 )

Change subject: Add tests for several methods of Xml
......................................................................


Add tests for several methods of Xml

Added tests for methods: monthSelector, span, buildTable, buildTableRow

Change-Id: I5ca6bb231b5ed95f57f649a92d659245a4852c85
---
M tests/phpunit/includes/XmlTest.php
1 file changed, 81 insertions(+), 0 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/phpunit/includes/XmlTest.php 
b/tests/phpunit/includes/XmlTest.php
index 4d4fa7b..d26f3ec 100644
--- a/tests/phpunit/includes/XmlTest.php
+++ b/tests/phpunit/includes/XmlTest.php
@@ -141,6 +141,57 @@
                $this->assertEquals( '</element>', Xml::closeElement( 'element' 
), 'closeElement() shortcut' );
        }
 
+       public function provideMonthSelector() {
+               global $wgLang;
+
+               $header = '<select name="month" id="month" 
class="mw-month-selector">';
+               $header2 = '<select name="month" id="monthSelector" 
class="mw-month-selector">';
+               $monthsString = '';
+               for ( $i = 1; $i < 13; $i++ ) {
+                       $monthName = $wgLang->getMonthName( $i );
+                       $monthsString .= "<option 
value=\"{$i}\">{$monthName}</option>";
+                       if ( $i !== 12 ) {
+                               $monthsString .= "\n";
+                       }
+               }
+               $monthsString2 = str_replace(
+                       '<option value="12">December</option>',
+                       '<option value="12" selected="">December</option>',
+                       $monthsString
+               );
+               $end = '</select>';
+
+               $allMonths = "<option value=\"AllMonths\">all</option>\n";
+               return [
+                       [ $header . $monthsString . $end, '', null, 'month' ],
+                       [ $header . $monthsString2 . $end, 12, null, 'month' ],
+                       [ $header2 . $monthsString . $end, '', null, 
'monthSelector' ],
+                       [ $header . $allMonths . $monthsString . $end, '', 
'AllMonths', 'month' ],
+
+               ];
+       }
+
+       /**
+        * @covers Xml::monthSelector
+        * @dataProvider provideMonthSelector
+        */
+       public function testMonthSelector( $expected, $selected, $allmonths, 
$id ) {
+               $this->assertEquals(
+                       $expected,
+                       Xml::monthSelector( $selected, $allmonths, $id )
+               );
+       }
+
+       /**
+        * @covers Xml::span
+        */
+       public function testSpan() {
+               $this->assertEquals(
+                       '<span class="foo" id="testSpan">element</span>',
+                       Xml::span( 'element', 'foo', [ 'id' => 'testSpan' ] )
+               );
+       }
+
        /**
         * @covers Xml::dateMenu
         */
@@ -533,4 +584,34 @@
                        'Entire element with legend and attributes'
                );
        }
+
+       /**
+        * @covers Xml::testBuildTable
+        */
+       public function testBuildTable() {
+               $firstRow = [ 'foo', 'bar' ];
+               $secondRow = [ 'Berlin', 'Tehran' ];
+               $headers = [ 'header1', 'header2' ];
+               $expected = '<table id="testTable"><thead 
id="testTable"><th>header1</th>' .
+                       
'<th>header2</th></thead><tr><td>foo</td><td>bar</td></tr><tr><td>Berlin</td>' .
+                       '<td>Tehran</td></tr></table>';
+               $this->assertEquals(
+                       $expected,
+                       Xml::buildTable(
+                               [ $firstRow, $secondRow ],
+                               [ 'id' => 'testTable' ],
+                               $headers
+                       )
+               );
+       }
+
+       /**
+        * @covers Xml::testBuildTableRow
+        */
+       public function testBuildTableRow() {
+               $this->assertEquals(
+                       '<tr id="testRow"><td>foo</td><td>bar</td></tr>',
+                       Xml::buildTableRow( [ 'id' => 'testRow' ], [ 'foo', 
'bar' ] )
+               );
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/400131
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5ca6bb231b5ed95f57f649a92d659245a4852c85
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to