Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / qunit / suites / resources / mediawiki / mediawiki.html.test.js
blobb4028ecf5fc118b21e2f9da8146247077a6933fa
1 ( function ( mw ) {
2         QUnit.module( 'mediawiki.html' );
4         QUnit.test( 'escape', 2, function ( assert ) {
5                 assert.throws(
6                         function () {
7                                 mw.html.escape();
8                         },
9                         TypeError,
10                         'throw a TypeError if argument is not a string'
11                 );
13                 assert.equal(
14                         mw.html.escape( '<mw awesome="awesome" value=\'test\' />' ),
15                         '&lt;mw awesome=&quot;awesome&quot; value=&#039;test&#039; /&gt;',
16                         'Escape special characters to html entities'
17                 );
18         } );
20         QUnit.test( 'element()', 1, function ( assert ) {
21                 assert.equal(
22                         mw.html.element(),
23                         '<undefined/>',
24                         'return valid html even without arguments'
25                 );
26         } );
28         QUnit.test( 'element( tagName )', 1, function ( assert ) {
29                 assert.equal( mw.html.element( 'div' ), '<div/>', 'DIV' );
30         } );
32         QUnit.test( 'element( tagName, attrs )', 2, function ( assert ) {
33                 assert.equal( mw.html.element( 'div', {} ), '<div/>', 'DIV' );
35                 assert.equal(
36                         mw.html.element(
37                                 'div', {
38                                         id: 'foobar'
39                                 }
40                         ),
41                         '<div id="foobar"/>',
42                         'DIV with attribs'
43                 );
44         } );
46         QUnit.test( 'element( tagName, attrs, content )', 8, function ( assert ) {
48                 assert.equal( mw.html.element( 'div', {}, '' ), '<div></div>', 'DIV with empty attributes and content' );
50                 assert.equal( mw.html.element( 'p', {}, 12 ), '<p>12</p>', 'numbers as content cast to strings' );
52                 assert.equal( mw.html.element( 'p', { title: 12 }, '' ), '<p title="12"></p>', 'number as attribute value' );
54                 assert.equal(
55                         mw.html.element(
56                                 'div',
57                                 {},
58                                 new mw.html.Raw(
59                                         mw.html.element( 'img', { src: '<' } )
60                                 )
61                         ),
62                         '<div><img src="&lt;"/></div>',
63                         'unescaped content with mw.html.Raw'
64                 );
66                 assert.equal(
67                         mw.html.element(
68                                 'option',
69                                 {
70                                         selected: true
71                                 },
72                                 'Foo'
73                         ),
74                         '<option selected="selected">Foo</option>',
75                         'boolean true attribute value'
76                 );
78                 assert.equal(
79                         mw.html.element(
80                                 'option',
81                                 {
82                                         value: 'foo',
83                                         selected: false
84                                 },
85                                 'Foo'
86                         ),
87                         '<option value="foo">Foo</option>',
88                         'boolean false attribute value'
89                 );
91                 assert.equal(
92                         mw.html.element( 'div', null, 'a' ),
93                         '<div>a</div>',
94                         'Skip attributes with null' );
96                 assert.equal(
97                         mw.html.element( 'a', {
98                                 href: 'http://mediawiki.org/w/index.php?title=RL&action=history'
99                         }, 'a' ),
100                         '<a href="http://mediawiki.org/w/index.php?title=RL&amp;action=history">a</a>',
101                         'Andhor tag with attributes and content'
102                 );
103         } );
105 }( mediaWiki ) );