* Port tests from t/inc/
[mediawiki.git] / tests / XmlTest.php
blob330e60c677467c6cfc3776e774b2e1f9a8bdac61
1 <?php
3 class XmlTest extends PHPUnit_Framework_TestCase {
5 function testElementOpen() {
6 $this->assertEquals(
7 '<element>',
8 Xml::element( 'element', null, null ),
9 'Opening element with no attributes'
13 function testElementEmpty() {
14 $this->assertEquals(
15 '<element />',
16 Xml::element( 'element', null, '' ),
17 'Terminated empty element'
21 function testElementEscaping() {
22 $this->assertEquals(
23 '<element>hello &lt;there&gt; you &amp; you</element>',
24 Xml::element( 'element', null, 'hello <there> you & you' ),
25 'Element with no attributes and content that needs escaping'
29 function testElementAttributes() {
30 $this->assertEquals(
31 '<element key="value" <>="&lt;&gt;">',
32 Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ),
33 'Element attributes, keys are not escaped'
37 function testOpenElement() {
38 $this->assertEquals(
39 '<element k="v">',
40 Xml::openElement( 'element', array( 'k' => 'v' ) ),
41 'openElement() shortcut'
45 function testCloseElement() {
46 $this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' );
50 # textarea
52 function testTextareaNoContent() {
53 $this->assertEquals(
54 '<textarea name="name" id="name" cols="40" rows="5"></textarea>',
55 Xml::textarea( 'name', '' ),
56 'textarea() with not content'
60 function testTextareaAttribs() {
61 $this->assertEquals(
62 '<textarea name="name" id="name" cols="20" rows="10">&lt;txt&gt;</textarea>',
63 Xml::textarea( 'name', '<txt>', 20, 10 ),
64 'textarea() with custom attribs'
69 # JS
71 function testEscapeJsStringSpecialChars() {
72 $this->assertEquals(
73 '\\\\\r\n',
74 Xml::escapeJsString( "\\\r\n" ),
75 'escapeJsString() with special characters'
79 function testEncodeJsVarBoolean() {
80 $this->assertEquals(
81 'true',
82 Xml::encodeJsVar( true ),
83 'encodeJsVar() with boolean'
87 function testEncodeJsVarNull() {
88 $this->assertEquals(
89 'null',
90 Xml::encodeJsVar( null ),
91 'encodeJsVar() with null'
95 function testEncodeJsVarArray() {
96 $this->assertEquals(
97 '["a", 1]',
98 Xml::encodeJsVar( array( 'a', 1 ) ),
99 'encodeJsVar() with array'
101 $this->assertEquals(
102 '{"a": "a", "b": 1}',
103 Xml::encodeJsVar( array( 'a' => 'a', 'b' => 1 ) ),
104 'encodeJsVar() with associative array'
108 function testEncodeJsVarObject() {
109 $this->assertEquals(
110 '{"a": "a", "b": 1}',
111 Xml::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ),
112 'encodeJsVar() with object'