summaryrefslogtreecommitdiff
path: root/t/inc/Xml.t
blob: b7cef881adb8d9d00e365ab1474488cfe648391a (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
#!/usr/bin/env php
<?php

require 't/Test.php';

plan( 8 );

require_ok( 'includes/Sanitizer.php' );
require_ok( 'includes/Xml.php' );

#
# element
#

cmp_ok(
	Xml::element( 'element', null, null ),
	'==',
	'<element>',
	'Opening element with no attributes'
);

cmp_ok(
	Xml::element( 'element', null, '' ),
	'==',
	'<element />',
	'Terminated empty element'
);

cmp_ok(
	Xml::element( 'element', null, 'hello <there> you & you' ),
	'==',
	'<element>hello &lt;there&gt; you &amp; you</element>',
	'Element with no attributes and content that needs escaping'
);

cmp_ok(
	Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ),
	'==',
	'<element key="value" <>="&lt;&gt;">',
	'Element attributes, keys are not escaped'
);

#
# open/close element
#

cmp_ok(
	Xml::openElement( 'element', array( 'k' => 'v' ) ),
	'==',
	'<element k="v">',
	'openElement() shortcut'
);

cmp_ok( Xml::closeElement( 'element' ), '==', '</element>', 'closeElement() shortcut' );

/* vim: set filetype=php: */