Merge "user: Allow "CAS update failed" exceptions to be normalised"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.html.test.js
1 ( function () {
2 QUnit.module( 'mediawiki.html' );
3
4 QUnit.test( 'escape', 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 );
12
13 assert.strictEqual(
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 } );
19
20 QUnit.test( 'element()', function ( assert ) {
21 assert.strictEqual(
22 mw.html.element(),
23 '<undefined/>',
24 'return valid html even without arguments'
25 );
26 } );
27
28 QUnit.test( 'element( tagName )', function ( assert ) {
29 assert.strictEqual( mw.html.element( 'div' ), '<div/>', 'DIV' );
30 } );
31
32 QUnit.test( 'element( tagName, attrs )', function ( assert ) {
33 assert.strictEqual( mw.html.element( 'div', {} ), '<div/>', 'DIV' );
34
35 assert.strictEqual(
36 mw.html.element(
37 'div', {
38 id: 'foobar'
39 }
40 ),
41 '<div id="foobar"/>',
42 'DIV with attribs'
43 );
44 } );
45
46 QUnit.test( 'element( tagName, attrs, content )', function ( assert ) {
47
48 assert.strictEqual( mw.html.element( 'div', {}, '' ), '<div></div>', 'DIV with empty attributes and content' );
49
50 assert.strictEqual( mw.html.element( 'p', {}, 12 ), '<p>12</p>', 'numbers as content cast to strings' );
51
52 assert.strictEqual( mw.html.element( 'p', { title: 12 }, '' ), '<p title="12"></p>', 'number as attribute value' );
53
54 assert.strictEqual(
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 );
65
66 assert.strictEqual(
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 );
77
78 assert.strictEqual(
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 );
90
91 assert.strictEqual(
92 mw.html.element( 'div', null, 'a' ),
93 '<div>a</div>',
94 'Skip attributes with null' );
95
96 assert.strictEqual(
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 } );
104
105 }() );