summaryrefslogtreecommitdiff
path: root/www/wiki/tests/qunit/suites/resources/mediawiki/mediawiki.html.test.js
blob: 16f8cf3b8ca140b3dc6bfa808b65b67e727b0fbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
( function ( mw ) {
	QUnit.module( 'mediawiki.html' );

	QUnit.test( 'escape', function ( assert ) {
		assert.throws(
			function () {
				mw.html.escape();
			},
			TypeError,
			'throw a TypeError if argument is not a string'
		);

		assert.equal(
			mw.html.escape( '<mw awesome="awesome" value=\'test\' />' ),
			'&lt;mw awesome=&quot;awesome&quot; value=&#039;test&#039; /&gt;',
			'Escape special characters to html entities'
		);
	} );

	QUnit.test( 'element()', function ( assert ) {
		assert.equal(
			mw.html.element(),
			'<undefined/>',
			'return valid html even without arguments'
		);
	} );

	QUnit.test( 'element( tagName )', function ( assert ) {
		assert.equal( mw.html.element( 'div' ), '<div/>', 'DIV' );
	} );

	QUnit.test( 'element( tagName, attrs )', function ( assert ) {
		assert.equal( mw.html.element( 'div', {} ), '<div/>', 'DIV' );

		assert.equal(
			mw.html.element(
				'div', {
					id: 'foobar'
				}
			),
			'<div id="foobar"/>',
			'DIV with attribs'
		);
	} );

	QUnit.test( 'element( tagName, attrs, content )', function ( assert ) {

		assert.equal( mw.html.element( 'div', {}, '' ), '<div></div>', 'DIV with empty attributes and content' );

		assert.equal( mw.html.element( 'p', {}, 12 ), '<p>12</p>', 'numbers as content cast to strings' );

		assert.equal( mw.html.element( 'p', { title: 12 }, '' ), '<p title="12"></p>', 'number as attribute value' );

		assert.equal(
			mw.html.element(
				'div',
				{},
				new mw.html.Raw(
					mw.html.element( 'img', { src: '<' } )
				)
			),
			'<div><img src="&lt;"/></div>',
			'unescaped content with mw.html.Raw'
		);

		assert.equal(
			mw.html.element(
				'option',
				{
					selected: true
				},
				'Foo'
			),
			'<option selected="selected">Foo</option>',
			'boolean true attribute value'
		);

		assert.equal(
			mw.html.element(
				'option',
				{
					value: 'foo',
					selected: false
				},
				'Foo'
			),
			'<option value="foo">Foo</option>',
			'boolean false attribute value'
		);

		assert.equal(
			mw.html.element( 'div', null, 'a' ),
			'<div>a</div>',
			'Skip attributes with null' );

		assert.equal(
			mw.html.element( 'a', {
				href: 'http://mediawiki.org/w/index.php?title=RL&action=history'
			}, 'a' ),
			'<a href="http://mediawiki.org/w/index.php?title=RL&amp;action=history">a</a>',
			'Andhor tag with attributes and content'
		);
	} );

}( mediaWiki ) );