diff options
Diffstat (limited to 'maintenance/tests/XmlTest.php')
-rw-r--r-- | maintenance/tests/XmlTest.php | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/maintenance/tests/XmlTest.php b/maintenance/tests/XmlTest.php new file mode 100644 index 00000000..330e60c6 --- /dev/null +++ b/maintenance/tests/XmlTest.php @@ -0,0 +1,115 @@ +<?php + +class XmlTest extends PHPUnit_Framework_TestCase { + + function testElementOpen() { + $this->assertEquals( + '<element>', + Xml::element( 'element', null, null ), + 'Opening element with no attributes' + ); + } + + function testElementEmpty() { + $this->assertEquals( + '<element />', + Xml::element( 'element', null, '' ), + 'Terminated empty element' + ); + } + + function testElementEscaping() { + $this->assertEquals( + '<element>hello <there> you & you</element>', + Xml::element( 'element', null, 'hello <there> you & you' ), + 'Element with no attributes and content that needs escaping' + ); + } + + function testElementAttributes() { + $this->assertEquals( + '<element key="value" <>="<>">', + Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ), + 'Element attributes, keys are not escaped' + ); + } + + function testOpenElement() { + $this->assertEquals( + '<element k="v">', + Xml::openElement( 'element', array( 'k' => 'v' ) ), + 'openElement() shortcut' + ); + } + + function testCloseElement() { + $this->assertEquals( '</element>', Xml::closeElement( 'element' ), 'closeElement() shortcut' ); + } + + # + # textarea + # + function testTextareaNoContent() { + $this->assertEquals( + '<textarea name="name" id="name" cols="40" rows="5"></textarea>', + Xml::textarea( 'name', '' ), + 'textarea() with not content' + ); + } + + function testTextareaAttribs() { + $this->assertEquals( + '<textarea name="name" id="name" cols="20" rows="10"><txt></textarea>', + Xml::textarea( 'name', '<txt>', 20, 10 ), + 'textarea() with custom attribs' + ); + } + + # + # JS + # + function testEscapeJsStringSpecialChars() { + $this->assertEquals( + '\\\\\r\n', + Xml::escapeJsString( "\\\r\n" ), + 'escapeJsString() with special characters' + ); + } + + function testEncodeJsVarBoolean() { + $this->assertEquals( + 'true', + Xml::encodeJsVar( true ), + 'encodeJsVar() with boolean' + ); + } + + function testEncodeJsVarNull() { + $this->assertEquals( + 'null', + Xml::encodeJsVar( null ), + 'encodeJsVar() with null' + ); + } + + function testEncodeJsVarArray() { + $this->assertEquals( + '["a", 1]', + Xml::encodeJsVar( array( 'a', 1 ) ), + 'encodeJsVar() with array' + ); + $this->assertEquals( + '{"a": "a", "b": 1}', + Xml::encodeJsVar( array( 'a' => 'a', 'b' => 1 ) ), + 'encodeJsVar() with associative array' + ); + } + + function testEncodeJsVarObject() { + $this->assertEquals( + '{"a": "a", "b": 1}', + Xml::encodeJsVar( (object)array( 'a' => 'a', 'b' => 1 ) ), + 'encodeJsVar() with object' + ); + } +} |