MediaWiki  REL1_24
HtmlTest.php
Go to the documentation of this file.
00001 <?php
00004 class HtmlTest extends MediaWikiTestCase {
00005 
00006     protected function setUp() {
00007         parent::setUp();
00008 
00009         $langCode = 'en';
00010         $langObj = Language::factory( $langCode );
00011 
00012         // Hardcode namespaces during test runs,
00013         // so that html output based on existing namespaces
00014         // can be properly evaluated.
00015         $langObj->setNamespaces( array(
00016             -2 => 'Media',
00017             -1 => 'Special',
00018             0 => '',
00019             1 => 'Talk',
00020             2 => 'User',
00021             3 => 'User_talk',
00022             4 => 'MyWiki',
00023             5 => 'MyWiki_Talk',
00024             6 => 'File',
00025             7 => 'File_talk',
00026             8 => 'MediaWiki',
00027             9 => 'MediaWiki_talk',
00028             10 => 'Template',
00029             11 => 'Template_talk',
00030             14 => 'Category',
00031             15 => 'Category_talk',
00032             100 => 'Custom',
00033             101 => 'Custom_talk',
00034         ) );
00035 
00036         $this->setMwGlobals( array(
00037             'wgLanguageCode' => $langCode,
00038             'wgContLang' => $langObj,
00039             'wgLang' => $langObj,
00040             'wgWellFormedXml' => false,
00041         ) );
00042     }
00043 
00047     public function testElementBasics() {
00048         $this->assertEquals(
00049             '<img>',
00050             Html::element( 'img', null, '' ),
00051             'No close tag for short-tag elements'
00052         );
00053 
00054         $this->assertEquals(
00055             '<element></element>',
00056             Html::element( 'element', null, null ),
00057             'Close tag for empty element (null, null)'
00058         );
00059 
00060         $this->assertEquals(
00061             '<element></element>',
00062             Html::element( 'element', array(), '' ),
00063             'Close tag for empty element (array, string)'
00064         );
00065 
00066         $this->setMwGlobals( 'wgWellFormedXml', true );
00067 
00068         $this->assertEquals(
00069             '<img />',
00070             Html::element( 'img', null, '' ),
00071             'Self-closing tag for short-tag elements (wgWellFormedXml = true)'
00072         );
00073     }
00074 
00075     public function dataXmlMimeType() {
00076         return array(
00077             // ( $mimetype, $isXmlMimeType )
00078             # HTML is not an XML MimeType
00079             array( 'text/html', false ),
00080             # XML is an XML MimeType
00081             array( 'text/xml', true ),
00082             array( 'application/xml', true ),
00083             # XHTML is an XML MimeType
00084             array( 'application/xhtml+xml', true ),
00085             # Make sure other +xml MimeTypes are supported
00086             # SVG is another random MimeType even though we don't use it
00087             array( 'image/svg+xml', true ),
00088             # Complete random other MimeTypes are not XML
00089             array( 'text/plain', false ),
00090         );
00091     }
00092 
00097     public function testXmlMimeType( $mimetype, $isXmlMimeType ) {
00098         $this->assertEquals( $isXmlMimeType, Html::isXmlMimeType( $mimetype ) );
00099     }
00100 
00104     public function testExpandAttributesSkipsNullAndFalse() {
00105 
00106         ### EMPTY ########
00107         $this->assertEmpty(
00108             Html::expandAttributes( array( 'foo' => null ) ),
00109             'skip keys with null value'
00110         );
00111         $this->assertEmpty(
00112             Html::expandAttributes( array( 'foo' => false ) ),
00113             'skip keys with false value'
00114         );
00115         $this->assertEquals(
00116             ' foo=""',
00117             Html::expandAttributes( array( 'foo' => '' ) ),
00118             'keep keys with an empty string'
00119         );
00120     }
00121 
00125     public function testExpandAttributesForBooleans() {
00126         $this->assertEquals(
00127             '',
00128             Html::expandAttributes( array( 'selected' => false ) ),
00129             'Boolean attributes do not generates output when value is false'
00130         );
00131         $this->assertEquals(
00132             '',
00133             Html::expandAttributes( array( 'selected' => null ) ),
00134             'Boolean attributes do not generates output when value is null'
00135         );
00136 
00137         $this->assertEquals(
00138             ' selected',
00139             Html::expandAttributes( array( 'selected' => true ) ),
00140             'Boolean attributes have no value when value is true'
00141         );
00142         $this->assertEquals(
00143             ' selected',
00144             Html::expandAttributes( array( 'selected' ) ),
00145             'Boolean attributes have no value when value is true (passed as numerical array)'
00146         );
00147 
00148         $this->setMwGlobals( 'wgWellFormedXml', true );
00149 
00150         $this->assertEquals(
00151             ' selected=""',
00152             Html::expandAttributes( array( 'selected' => true ) ),
00153             'Boolean attributes have empty string value when value is true (wgWellFormedXml)'
00154         );
00155     }
00156 
00160     public function testExpandAttributesForNumbers() {
00161         $this->assertEquals(
00162             ' value=1',
00163             Html::expandAttributes( array( 'value' => 1 ) ),
00164             'Integer value is cast to a string'
00165         );
00166         $this->assertEquals(
00167             ' value=1.1',
00168             Html::expandAttributes( array( 'value' => 1.1 ) ),
00169             'Float value is cast to a string'
00170         );
00171     }
00172 
00176     public function testExpandAttributesForObjects() {
00177         $this->assertEquals(
00178             ' value=stringValue',
00179             Html::expandAttributes( array( 'value' => new HtmlTestValue() ) ),
00180             'Object value is converted to a string'
00181         );
00182     }
00183 
00189     public function testExpandAttributesVariousExpansions() {
00190         ### NOT EMPTY ####
00191         $this->assertEquals(
00192             ' empty_string=""',
00193             Html::expandAttributes( array( 'empty_string' => '' ) ),
00194             'Empty string is always quoted'
00195         );
00196         $this->assertEquals(
00197             ' key=value',
00198             Html::expandAttributes( array( 'key' => 'value' ) ),
00199             'Simple string value needs no quotes'
00200         );
00201         $this->assertEquals(
00202             ' one=1',
00203             Html::expandAttributes( array( 'one' => 1 ) ),
00204             'Number 1 value needs no quotes'
00205         );
00206         $this->assertEquals(
00207             ' zero=0',
00208             Html::expandAttributes( array( 'zero' => 0 ) ),
00209             'Number 0 value needs no quotes'
00210         );
00211 
00212         $this->setMwGlobals( 'wgWellFormedXml', true );
00213 
00214         $this->assertEquals(
00215             ' empty_string=""',
00216             Html::expandAttributes( array( 'empty_string' => '' ) ),
00217             'Attribute values are always quoted (wgWellFormedXml): Empty string'
00218         );
00219         $this->assertEquals(
00220             ' key="value"',
00221             Html::expandAttributes( array( 'key' => 'value' ) ),
00222             'Attribute values are always quoted (wgWellFormedXml): Simple string'
00223         );
00224         $this->assertEquals(
00225             ' one="1"',
00226             Html::expandAttributes( array( 'one' => 1 ) ),
00227             'Attribute values are always quoted (wgWellFormedXml): Number 1'
00228         );
00229         $this->assertEquals(
00230             ' zero="0"',
00231             Html::expandAttributes( array( 'zero' => 0 ) ),
00232             'Attribute values are always quoted (wgWellFormedXml): Number 0'
00233         );
00234     }
00235 
00242     public function testExpandAttributesListValueAttributes() {
00243         ### STRING VALUES
00244         $this->assertEquals(
00245             ' class="redundant spaces here"',
00246             Html::expandAttributes( array( 'class' => ' redundant  spaces  here  ' ) ),
00247             'Normalization should strip redundant spaces'
00248         );
00249         $this->assertEquals(
00250             ' class="foo bar"',
00251             Html::expandAttributes( array( 'class' => 'foo bar foo bar bar' ) ),
00252             'Normalization should remove duplicates in string-lists'
00253         );
00254         ### "EMPTY" ARRAY VALUES
00255         $this->assertEquals(
00256             ' class=""',
00257             Html::expandAttributes( array( 'class' => array() ) ),
00258             'Value with an empty array'
00259         );
00260         $this->assertEquals(
00261             ' class=""',
00262             Html::expandAttributes( array( 'class' => array( null, '', ' ', '  ' ) ) ),
00263             'Array with null, empty string and spaces'
00264         );
00265         ### NON-EMPTY ARRAY VALUES
00266         $this->assertEquals(
00267             ' class="foo bar"',
00268             Html::expandAttributes( array( 'class' => array(
00269                 'foo',
00270                 'bar',
00271                 'foo',
00272                 'bar',
00273                 'bar',
00274             ) ) ),
00275             'Normalization should remove duplicates in the array'
00276         );
00277         $this->assertEquals(
00278             ' class="foo bar"',
00279             Html::expandAttributes( array( 'class' => array(
00280                 'foo bar',
00281                 'bar foo',
00282                 'foo',
00283                 'bar bar',
00284             ) ) ),
00285             'Normalization should remove duplicates in string-lists in the array'
00286         );
00287     }
00288 
00294     public function testExpandAttributesSpaceSeparatedAttributesWithBoolean() {
00295         $this->assertEquals(
00296             ' class="booltrue one"',
00297             Html::expandAttributes( array( 'class' => array(
00298                 'booltrue' => true,
00299                 'one' => 1,
00300 
00301                 # Method use isset() internally, make sure we do discard
00302                 # attributes values which have been assigned well known values
00303                 'emptystring' => '',
00304                 'boolfalse' => false,
00305                 'zero' => 0,
00306                 'null' => null,
00307             ) ) )
00308         );
00309     }
00310 
00319     public function testValueIsAuthoritativeInSpaceSeparatedAttributesArrays() {
00320         $this->assertEquals(
00321             ' class=""',
00322             Html::expandAttributes( array( 'class' => array(
00323                 'GREEN',
00324                 'GREEN' => false,
00325                 'GREEN',
00326             ) ) )
00327         );
00328     }
00329 
00334     public function testExpandAttributes_ArrayOnNonListValueAttribute_ThrowsException() {
00335         // Real-life test case found in the Popups extension (see Gerrit cf0fd64),
00336         // when used with an outdated BetaFeatures extension (see Gerrit deda1e7)
00337         Html::expandAttributes( array(
00338             'src' => array(
00339                 'ltr' => 'ltr.svg',
00340                 'rtl' => 'rtl.svg'
00341             )
00342         ) );
00343     }
00344 
00348     public function testNamespaceSelector() {
00349         $this->assertEquals(
00350             '<select id=namespace name=namespace>' . "\n" .
00351                 '<option value=0>(Main)</option>' . "\n" .
00352                 '<option value=1>Talk</option>' . "\n" .
00353                 '<option value=2>User</option>' . "\n" .
00354                 '<option value=3>User talk</option>' . "\n" .
00355                 '<option value=4>MyWiki</option>' . "\n" .
00356                 '<option value=5>MyWiki Talk</option>' . "\n" .
00357                 '<option value=6>File</option>' . "\n" .
00358                 '<option value=7>File talk</option>' . "\n" .
00359                 '<option value=8>MediaWiki</option>' . "\n" .
00360                 '<option value=9>MediaWiki talk</option>' . "\n" .
00361                 '<option value=10>Template</option>' . "\n" .
00362                 '<option value=11>Template talk</option>' . "\n" .
00363                 '<option value=14>Category</option>' . "\n" .
00364                 '<option value=15>Category talk</option>' . "\n" .
00365                 '<option value=100>Custom</option>' . "\n" .
00366                 '<option value=101>Custom talk</option>' . "\n" .
00367                 '</select>',
00368             Html::namespaceSelector(),
00369             'Basic namespace selector without custom options'
00370         );
00371 
00372         $this->assertEquals(
00373             '<label for=mw-test-namespace>Select a namespace:</label>&#160;' .
00374                 '<select id=mw-test-namespace name=wpNamespace>' . "\n" .
00375                 '<option value=all>all</option>' . "\n" .
00376                 '<option value=0>(Main)</option>' . "\n" .
00377                 '<option value=1>Talk</option>' . "\n" .
00378                 '<option value=2 selected>User</option>' . "\n" .
00379                 '<option value=3>User talk</option>' . "\n" .
00380                 '<option value=4>MyWiki</option>' . "\n" .
00381                 '<option value=5>MyWiki Talk</option>' . "\n" .
00382                 '<option value=6>File</option>' . "\n" .
00383                 '<option value=7>File talk</option>' . "\n" .
00384                 '<option value=8>MediaWiki</option>' . "\n" .
00385                 '<option value=9>MediaWiki talk</option>' . "\n" .
00386                 '<option value=10>Template</option>' . "\n" .
00387                 '<option value=11>Template talk</option>' . "\n" .
00388                 '<option value=14>Category</option>' . "\n" .
00389                 '<option value=15>Category talk</option>' . "\n" .
00390                 '<option value=100>Custom</option>' . "\n" .
00391                 '<option value=101>Custom talk</option>' . "\n" .
00392                 '</select>',
00393             Html::namespaceSelector(
00394                 array( 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ),
00395                 array( 'name' => 'wpNamespace', 'id' => 'mw-test-namespace' )
00396             ),
00397             'Basic namespace selector with custom values'
00398         );
00399 
00400         $this->assertEquals(
00401             '<label for=namespace>Select a namespace:</label>&#160;' .
00402                 '<select id=namespace name=namespace>' . "\n" .
00403                 '<option value=0>(Main)</option>' . "\n" .
00404                 '<option value=1>Talk</option>' . "\n" .
00405                 '<option value=2>User</option>' . "\n" .
00406                 '<option value=3>User talk</option>' . "\n" .
00407                 '<option value=4>MyWiki</option>' . "\n" .
00408                 '<option value=5>MyWiki Talk</option>' . "\n" .
00409                 '<option value=6>File</option>' . "\n" .
00410                 '<option value=7>File talk</option>' . "\n" .
00411                 '<option value=8>MediaWiki</option>' . "\n" .
00412                 '<option value=9>MediaWiki talk</option>' . "\n" .
00413                 '<option value=10>Template</option>' . "\n" .
00414                 '<option value=11>Template talk</option>' . "\n" .
00415                 '<option value=14>Category</option>' . "\n" .
00416                 '<option value=15>Category talk</option>' . "\n" .
00417                 '<option value=100>Custom</option>' . "\n" .
00418                 '<option value=101>Custom talk</option>' . "\n" .
00419                 '</select>',
00420             Html::namespaceSelector(
00421                 array( 'label' => 'Select a namespace:' )
00422             ),
00423             'Basic namespace selector with a custom label but no id attribtue for the <select>'
00424         );
00425     }
00426 
00427     public function testCanFilterOutNamespaces() {
00428         $this->assertEquals(
00429             '<select id=namespace name=namespace>' . "\n" .
00430                 '<option value=2>User</option>' . "\n" .
00431                 '<option value=4>MyWiki</option>' . "\n" .
00432                 '<option value=5>MyWiki Talk</option>' . "\n" .
00433                 '<option value=6>File</option>' . "\n" .
00434                 '<option value=7>File talk</option>' . "\n" .
00435                 '<option value=8>MediaWiki</option>' . "\n" .
00436                 '<option value=9>MediaWiki talk</option>' . "\n" .
00437                 '<option value=10>Template</option>' . "\n" .
00438                 '<option value=11>Template talk</option>' . "\n" .
00439                 '<option value=14>Category</option>' . "\n" .
00440                 '<option value=15>Category talk</option>' . "\n" .
00441                 '</select>',
00442             Html::namespaceSelector(
00443                 array( 'exclude' => array( 0, 1, 3, 100, 101 ) )
00444             ),
00445             'Namespace selector namespace filtering.'
00446         );
00447     }
00448 
00449     public function testCanDisableANamespaces() {
00450         $this->assertEquals(
00451             '<select id=namespace name=namespace>' . "\n" .
00452                 '<option disabled value=0>(Main)</option>' . "\n" .
00453                 '<option disabled value=1>Talk</option>' . "\n" .
00454                 '<option disabled value=2>User</option>' . "\n" .
00455                 '<option disabled value=3>User talk</option>' . "\n" .
00456                 '<option disabled value=4>MyWiki</option>' . "\n" .
00457                 '<option value=5>MyWiki Talk</option>' . "\n" .
00458                 '<option value=6>File</option>' . "\n" .
00459                 '<option value=7>File talk</option>' . "\n" .
00460                 '<option value=8>MediaWiki</option>' . "\n" .
00461                 '<option value=9>MediaWiki talk</option>' . "\n" .
00462                 '<option value=10>Template</option>' . "\n" .
00463                 '<option value=11>Template talk</option>' . "\n" .
00464                 '<option value=14>Category</option>' . "\n" .
00465                 '<option value=15>Category talk</option>' . "\n" .
00466                 '<option value=100>Custom</option>' . "\n" .
00467                 '<option value=101>Custom talk</option>' . "\n" .
00468                 '</select>',
00469             Html::namespaceSelector( array(
00470                 'disable' => array( 0, 1, 2, 3, 4 )
00471             ) ),
00472             'Namespace selector namespace disabling'
00473         );
00474     }
00475 
00480     public function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) {
00481         $this->assertEquals(
00482             '<input type=' . $HTML5InputType . '>',
00483             Html::element( 'input', array( 'type' => $HTML5InputType ) ),
00484             'In HTML5, HTML::element() should accept type="' . $HTML5InputType . '"'
00485         );
00486     }
00487 
00492     public static function provideHtml5InputTypes() {
00493         $types = array(
00494             'datetime',
00495             'datetime-local',
00496             'date',
00497             'month',
00498             'time',
00499             'week',
00500             'number',
00501             'range',
00502             'email',
00503             'url',
00504             'search',
00505             'tel',
00506             'color',
00507         );
00508         $cases = array();
00509         foreach ( $types as $type ) {
00510             $cases[] = array( $type );
00511         }
00512 
00513         return $cases;
00514     }
00515 
00521     public function testDropDefaults( $expected, $element, $attribs, $message = '' ) {
00522         $this->assertEquals( $expected, Html::element( $element, $attribs ), $message );
00523     }
00524 
00525     public static function provideElementsWithAttributesHavingDefaultValues() {
00526         # Use cases in a concise format:
00527         # <expected>, <element name>, <array of attributes> [, <message>]
00528         # Will be mapped to Html::element()
00529         $cases = array();
00530 
00531         ### Generic cases, match $attribDefault static array
00532         $cases[] = array( '<area>',
00533             'area', array( 'shape' => 'rect' )
00534         );
00535 
00536         $cases[] = array( '<button type=submit></button>',
00537             'button', array( 'formaction' => 'GET' )
00538         );
00539         $cases[] = array( '<button type=submit></button>',
00540             'button', array( 'formenctype' => 'application/x-www-form-urlencoded' )
00541         );
00542 
00543         $cases[] = array( '<canvas></canvas>',
00544             'canvas', array( 'height' => '150' )
00545         );
00546         $cases[] = array( '<canvas></canvas>',
00547             'canvas', array( 'width' => '300' )
00548         );
00549         # Also check with numeric values
00550         $cases[] = array( '<canvas></canvas>',
00551             'canvas', array( 'height' => 150 )
00552         );
00553         $cases[] = array( '<canvas></canvas>',
00554             'canvas', array( 'width' => 300 )
00555         );
00556 
00557         $cases[] = array( '<command>',
00558             'command', array( 'type' => 'command' )
00559         );
00560 
00561         $cases[] = array( '<form></form>',
00562             'form', array( 'action' => 'GET' )
00563         );
00564         $cases[] = array( '<form></form>',
00565             'form', array( 'autocomplete' => 'on' )
00566         );
00567         $cases[] = array( '<form></form>',
00568             'form', array( 'enctype' => 'application/x-www-form-urlencoded' )
00569         );
00570 
00571         $cases[] = array( '<input>',
00572             'input', array( 'formaction' => 'GET' )
00573         );
00574         $cases[] = array( '<input>',
00575             'input', array( 'type' => 'text' )
00576         );
00577 
00578         $cases[] = array( '<keygen>',
00579             'keygen', array( 'keytype' => 'rsa' )
00580         );
00581 
00582         $cases[] = array( '<link>',
00583             'link', array( 'media' => 'all' )
00584         );
00585 
00586         $cases[] = array( '<menu></menu>',
00587             'menu', array( 'type' => 'list' )
00588         );
00589 
00590         $cases[] = array( '<script></script>',
00591             'script', array( 'type' => 'text/javascript' )
00592         );
00593 
00594         $cases[] = array( '<style></style>',
00595             'style', array( 'media' => 'all' )
00596         );
00597         $cases[] = array( '<style></style>',
00598             'style', array( 'type' => 'text/css' )
00599         );
00600 
00601         $cases[] = array( '<textarea></textarea>',
00602             'textarea', array( 'wrap' => 'soft' )
00603         );
00604 
00605         ### SPECIFIC CASES
00606 
00607         # <link type="text/css">
00608         $cases[] = array( '<link>',
00609             'link', array( 'type' => 'text/css' )
00610         );
00611 
00612         # <input> specific handling
00613         $cases[] = array( '<input type=checkbox>',
00614             'input', array( 'type' => 'checkbox', 'value' => 'on' ),
00615             'Default value "on" is stripped of checkboxes',
00616         );
00617         $cases[] = array( '<input type=radio>',
00618             'input', array( 'type' => 'radio', 'value' => 'on' ),
00619             'Default value "on" is stripped of radio buttons',
00620         );
00621         $cases[] = array( '<input type=submit value=Submit>',
00622             'input', array( 'type' => 'submit', 'value' => 'Submit' ),
00623             'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
00624         );
00625         $cases[] = array( '<input type=color>',
00626             'input', array( 'type' => 'color', 'value' => '' ),
00627         );
00628         $cases[] = array( '<input type=range>',
00629             'input', array( 'type' => 'range', 'value' => '' ),
00630         );
00631 
00632         # <button> specific handling
00633         # see remarks on http://msdn.microsoft.com/en-us/library/ie/ms535211%28v=vs.85%29.aspx
00634         $cases[] = array( '<button type=submit></button>',
00635             'button', array( 'type' => 'submit' ),
00636             'According to standard the default type is "submit". '
00637                 . 'Depending on compatibility mode IE might use "button", instead.',
00638         );
00639 
00640         # <select> specifc handling
00641         $cases[] = array( '<select multiple></select>',
00642             'select', array( 'size' => '4', 'multiple' => true ),
00643         );
00644         # .. with numeric value
00645         $cases[] = array( '<select multiple></select>',
00646             'select', array( 'size' => 4, 'multiple' => true ),
00647         );
00648         $cases[] = array( '<select></select>',
00649             'select', array( 'size' => '1', 'multiple' => false ),
00650         );
00651         # .. with numeric value
00652         $cases[] = array( '<select></select>',
00653             'select', array( 'size' => 1, 'multiple' => false ),
00654         );
00655 
00656         # Passing an array as value
00657         $cases[] = array( '<a class="css-class-one css-class-two"></a>',
00658             'a', array( 'class' => array( 'css-class-one', 'css-class-two' ) ),
00659             "dropDefaults accepts values given as an array"
00660         );
00661 
00662         # FIXME: doDropDefault should remove defaults given in an array
00663         # Expected should be '<a></a>'
00664         $cases[] = array( '<a class=""></a>',
00665             'a', array( 'class' => array( '', '' ) ),
00666             "dropDefaults accepts values given as an array"
00667         );
00668 
00669         # Craft the Html elements
00670         $ret = array();
00671         foreach ( $cases as $case ) {
00672             $ret[] = array(
00673                 $case[0],
00674                 $case[1], $case[2],
00675                 isset( $case[3] ) ? $case[3] : ''
00676             );
00677         }
00678 
00679         return $ret;
00680     }
00681 
00685     public function testFormValidationBlacklist() {
00686         $this->assertEmpty(
00687             Html::expandAttributes( array(
00688                 'min' => 1,
00689                 'max' => 100,
00690                 'pattern' => 'abc',
00691                 'required' => true,
00692                 'step' => 2
00693             ) ),
00694             'Blacklist form validation attributes.'
00695         );
00696         $this->assertEquals(
00697             ' step=any',
00698             Html::expandAttributes(
00699                 array(
00700                     'min' => 1,
00701                     'max' => 100,
00702                     'pattern' => 'abc',
00703                     'required' => true,
00704                     'step' => 'any'
00705                 ),
00706                 'Allow special case "step=any".'
00707             )
00708         );
00709     }
00710 
00711     public function testWrapperInput() {
00712         $this->assertEquals(
00713             '<input type=radio value=testval name=testname>',
00714             Html::input( 'testname', 'testval', 'radio' ),
00715             'Input wrapper with type and value.'
00716         );
00717         $this->assertEquals(
00718             '<input name=testname class=mw-ui-input>',
00719             Html::input( 'testname' ),
00720             'Input wrapper with all default values.'
00721         );
00722     }
00723 
00724     public function testWrapperCheck() {
00725         $this->assertEquals(
00726             '<input type=checkbox value=1 name=testname>',
00727             Html::check( 'testname' ),
00728             'Checkbox wrapper unchecked.'
00729         );
00730         $this->assertEquals(
00731             '<input checked type=checkbox value=1 name=testname>',
00732             Html::check( 'testname', true ),
00733             'Checkbox wrapper checked.'
00734         );
00735         $this->assertEquals(
00736             '<input type=checkbox value=testval name=testname>',
00737             Html::check( 'testname', false, array( 'value' => 'testval' ) ),
00738             'Checkbox wrapper with a value override.'
00739         );
00740     }
00741 
00742     public function testWrapperRadio() {
00743         $this->assertEquals(
00744             '<input type=radio value=1 name=testname>',
00745             Html::radio( 'testname' ),
00746             'Radio wrapper unchecked.'
00747         );
00748         $this->assertEquals(
00749             '<input checked type=radio value=1 name=testname>',
00750             Html::radio( 'testname', true ),
00751             'Radio wrapper checked.'
00752         );
00753         $this->assertEquals(
00754             '<input type=radio value=testval name=testname>',
00755             Html::radio( 'testname', false, array( 'value' => 'testval' ) ),
00756             'Radio wrapper with a value override.'
00757         );
00758     }
00759 
00760     public function testWrapperLabel() {
00761         $this->assertEquals(
00762             '<label for=testid>testlabel</label>',
00763             Html::label( 'testlabel', 'testid' ),
00764             'Label wrapper'
00765         );
00766     }
00767 }
00768 
00769 class HtmlTestValue {
00770     function __toString() {
00771         return 'stringValue';
00772     }
00773 }