3 class XmlTest
extends MediaWikiTestCase
{
5 public function testExpandAttributes() {
6 $this->assertNull( Xml
::expandAttributes(null),
7 'Converting a null list of attributes'
9 $this->assertEquals( '', Xml
::expandAttributes( array() ),
10 'Converting an empty list of attributes'
14 public function testExpandAttributesException() {
15 $this->setExpectedException('MWException');
16 Xml
::expandAttributes('string');
19 function testElementOpen() {
22 Xml
::element( 'element', null, null ),
23 'Opening element with no attributes'
27 function testElementEmpty() {
30 Xml
::element( 'element', null, '' ),
31 'Terminated empty element'
35 function testElementInputCanHaveAValueOfZero() {
37 '<input name="name" value="0" />',
38 Xml
::input( 'name', false, 0 ),
39 'Input with a value of 0 (bug 23797)'
42 function testElementEscaping() {
44 '<element>hello <there> you & you</element>',
45 Xml
::element( 'element', null, 'hello <there> you & you' ),
46 'Element with no attributes and content that needs escaping'
50 public function testEscapeTagsOnly() {
51 $this->assertEquals( '"><', Xml
::escapeTagsOnly( '"><' ),
52 'replace " > and < with their HTML entitites'
56 function testElementAttributes() {
58 '<element key="value" <>="<>">',
59 Xml
::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ),
60 'Element attributes, keys are not escaped'
64 function testOpenElement() {
67 Xml
::openElement( 'element', array( 'k' => 'v' ) ),
68 'openElement() shortcut'
72 function testCloseElement() {
73 $this->assertEquals( '</element>', Xml
::closeElement( 'element' ), 'closeElement() shortcut' );
79 function testTextareaNoContent() {
81 '<textarea name="name" id="name" cols="40" rows="5"></textarea>',
82 Xml
::textarea( 'name', '' ),
83 'textarea() with not content'
87 function testTextareaAttribs() {
89 '<textarea name="name" id="name" cols="20" rows="10"><txt></textarea>',
90 Xml
::textarea( 'name', '<txt>', 20, 10 ),
91 'textarea() with custom attribs'
98 function testLabelCreation() {
100 '<label for="id">name</label>',
101 Xml
::label( 'name', 'id' ),
102 'label() with no attribs'
105 function testLabelAttributeCanOnlyBeClass() {
107 '<label for="id">name</label>',
108 Xml
::label( 'name', 'id', array( 'generated' => true ) ),
109 'label() can not be given a generated attribute'
112 '<label for="id" class="nice">name</label>',
113 Xml
::label( 'name', 'id', array( 'class' => 'nice' ) ),
114 'label() can get a class attribute'
117 '<label for="id" class="nice">name</label>',
118 Xml
::label( 'name', 'id', array(
121 'anotherattr' => 'value',
124 'label() skip all attributes but "class"'
131 function testEscapeJsStringSpecialChars() {
134 Xml
::escapeJsString( "\\\r\n" ),
135 'escapeJsString() with special characters'
139 function testEncodeJsVarBoolean() {
142 Xml
::encodeJsVar( true ),
143 'encodeJsVar() with boolean'
147 function testEncodeJsVarNull() {
150 Xml
::encodeJsVar( null ),
151 'encodeJsVar() with null'
155 function testEncodeJsVarArray() {
158 Xml
::encodeJsVar( array( 'a', 1 ) ),
159 'encodeJsVar() with array'
162 '{"a": "a", "b": 1}',
163 Xml
::encodeJsVar( array( 'a' => 'a', 'b' => 1 ) ),
164 'encodeJsVar() with associative array'
168 function testEncodeJsVarObject() {
170 '{"a": "a", "b": 1}',
171 Xml
::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ),
172 'encodeJsVar() with object'