summaryrefslogtreecommitdiff
path: root/ext/xmlwriter/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/xmlwriter/tests')
-rw-r--r--ext/xmlwriter/tests/006.phpt27
-rw-r--r--ext/xmlwriter/tests/007.phpt38
-rw-r--r--ext/xmlwriter/tests/008.phpt35
-rw-r--r--ext/xmlwriter/tests/009.phpt43
-rw-r--r--ext/xmlwriter/tests/OO_007.phpt39
-rw-r--r--ext/xmlwriter/tests/OO_008.phpt36
-rw-r--r--ext/xmlwriter/tests/OO_009.phpt44
7 files changed, 262 insertions, 0 deletions
diff --git a/ext/xmlwriter/tests/006.phpt b/ext/xmlwriter/tests/006.phpt
new file mode 100644
index 0000000..3b290ad
--- /dev/null
+++ b/ext/xmlwriter/tests/006.phpt
@@ -0,0 +1,27 @@
+--TEST--
+XMLWriter: libxml2 XML Writer, startDTD/writeElementNS
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("xmlwriter_start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$doc_dest = '001.xml';
+$xw = xmlwriter_open_uri($doc_dest);
+xmlwriter_start_dtd($xw, 'foo', NULL, 'urn:bar');
+xmlwriter_end_dtd($xw);
+xmlwriter_start_element($xw, 'foo');
+xmlwriter_write_element_ns($xw, 'foo', 'bar', 'urn:foo', 'dummy content');
+xmlwriter_end_element($xw);
+
+// Force to write and empty the buffer
+$output_bytes = xmlwriter_flush($xw, true);
+echo file_get_contents($doc_dest);
+unset($xw);
+unlink('001.xml');
+?>
+--EXPECT--
+<!DOCTYPE foo SYSTEM "urn:bar"><foo><foo:bar xmlns:foo="urn:foo">dummy content</foo:bar></foo>
diff --git a/ext/xmlwriter/tests/007.phpt b/ext/xmlwriter/tests/007.phpt
new file mode 100644
index 0000000..2e6ad3c
--- /dev/null
+++ b/ext/xmlwriter/tests/007.phpt
@@ -0,0 +1,38 @@
+--TEST--
+XMLWriter: libxml2 XML Writer, Elements & Attributes
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("xmlwriter_start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = xmlwriter_open_memory();
+xmlwriter_set_indent($xw, TRUE);
+xmlwriter_set_indent_string($xw, ' ');
+xmlwriter_start_document($xw, '1.0', "UTF-8");
+xmlwriter_start_element($xw, 'root');
+xmlwriter_start_element_ns($xw, 'ns1', 'child1', 'urn:ns1');
+xmlwriter_start_attribute_ns($xw, 'ns1', 'att1', 'urn:ns1');
+xmlwriter_text($xw, 'a&b');
+xmlwriter_end_attribute($xw);
+xmlwriter_write_attribute($xw, 'att2', "double\" single'");
+xmlwriter_start_attribute_ns($xw, 'ns1', 'att2', 'urn:ns1');
+xmlwriter_text($xw, "<>\"'&");
+xmlwriter_end_attribute($xw);
+xmlwriter_write_element($xw, 'chars', "special characters: <>\"'&");
+xmlwriter_end_element($xw);
+xmlwriter_end_document($xw);
+// Force to write and empty the buffer
+$output = xmlwriter_flush($xw, true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <ns1:child1 xmlns:ns1="urn:ns1" ns1:att1="a&amp;b" xmlns:ns1="urn:ns1" att2="double&quot; single'" ns1:att2="&lt;&gt;&quot;'&amp;" xmlns:ns1="urn:ns1">
+ <chars>special characters: &lt;&gt;&quot;'&amp;</chars>
+ </ns1:child1>
+</root>
diff --git a/ext/xmlwriter/tests/008.phpt b/ext/xmlwriter/tests/008.phpt
new file mode 100644
index 0000000..17e0eab
--- /dev/null
+++ b/ext/xmlwriter/tests/008.phpt
@@ -0,0 +1,35 @@
+--TEST--
+XMLWriter: libxml2 XML Writer DTD Element & Attlist
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("xmlwriter_start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = xmlwriter_open_memory();
+xmlwriter_set_indent($xw, TRUE);
+xmlwriter_start_document($xw, NULL, "UTF-8");
+xmlwriter_write_dtd_element($xw, 'sxe', '(elem1+, elem11, elem22*)');
+xmlwriter_write_dtd_attlist($xw, 'sxe', 'id CDATA #implied');
+xmlwriter_start_dtd_element($xw, 'elem1');
+xmlwriter_text($xw, 'elem2*');
+xmlwriter_end_dtd_element($xw);
+xmlwriter_start_dtd_attlist($xw, 'elem1');
+xmlwriter_text($xw, "attr1 CDATA #required\n");
+xmlwriter_text($xw, 'attr2 CDATA #implied');
+xmlwriter_end_dtd_attlist($xw);
+xmlwriter_end_document($xw);
+// Force to write and empty the buffer
+$output = xmlwriter_flush($xw, true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<!ELEMENT sxe (elem1+, elem11, elem22*)>
+<!ATTLIST sxe id CDATA #implied>
+<!ELEMENT elem1 elem2*>
+<!ATTLIST elem1 attr1 CDATA #required
+attr2 CDATA #implied>
diff --git a/ext/xmlwriter/tests/009.phpt b/ext/xmlwriter/tests/009.phpt
new file mode 100644
index 0000000..2322b7c
--- /dev/null
+++ b/ext/xmlwriter/tests/009.phpt
@@ -0,0 +1,43 @@
+--TEST--
+XMLWriter: PI, Comment, CDATA
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("xmlwriter_start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = xmlwriter_open_memory();
+xmlwriter_set_indent($xw, TRUE);
+xmlwriter_start_document($xw, NULL, "UTF-8");
+xmlwriter_start_element($xw, 'root');
+xmlwriter_write_attribute($xw, 'id', 'elem1');
+xmlwriter_start_element($xw, 'elem1');
+xmlwriter_write_attribute($xw, 'attr1', 'first');
+xmlwriter_write_comment($xw, 'start PI');
+xmlwriter_start_element($xw, 'pi');
+xmlwriter_write_pi($xw, 'php', 'echo "hello world"; ');
+xmlwriter_end_element($xw);
+xmlwriter_start_element($xw, 'cdata');
+xmlwriter_start_cdata($xw);
+xmlwriter_end_element($xw);
+xmlwriter_text($xw, '<>&"');
+xmlwriter_end_cdata($xw);
+xmlwriter_end_element($xw);
+xmlwriter_end_element($xw);
+xmlwriter_end_document($xw);
+// Force to write and empty the buffer
+$output = xmlwriter_flush($xw, true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<root id="elem1">
+ <elem1 attr1="first">
+ <!--start PI-->
+ <pi><?php echo "hello world"; ?></pi>
+ <cdata><![CDATA[<>&"]]></cdata>
+ </elem1>
+</root>
diff --git a/ext/xmlwriter/tests/OO_007.phpt b/ext/xmlwriter/tests/OO_007.phpt
new file mode 100644
index 0000000..119be93
--- /dev/null
+++ b/ext/xmlwriter/tests/OO_007.phpt
@@ -0,0 +1,39 @@
+--TEST--
+XMLWriter: libxml2 XML Writer, Elements & Attributes
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("$xw->start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = new XMLWriter();
+$xw->openMemory();
+$xw->setIndent(TRUE);
+$xw->setIndentString(' ');
+$xw->startDocument('1.0', "UTF-8");
+$xw->startElement('root');
+$xw->startElementNS('ns1', 'child1', 'urn:ns1');
+$xw->startAttributeNS('ns1', 'att1', 'urn:ns1');
+$xw->text('a&b');
+$xw->endAttribute();
+$xw->writeAttribute('att2', "double\" single'");
+$xw->startAttributeNS('ns1', 'att2', 'urn:ns1');
+$xw->text("<>\"'&");
+$xw->endAttribute();
+$xw->writeElement('chars', "special characters: <>\"'&");
+$xw->endElement();
+$xw->endDocument();
+// Force to write and empty the buffer
+$output = $xw->flush(true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<root>
+ <ns1:child1 xmlns:ns1="urn:ns1" ns1:att1="a&amp;b" xmlns:ns1="urn:ns1" att2="double&quot; single'" ns1:att2="&lt;&gt;&quot;'&amp;" xmlns:ns1="urn:ns1">
+ <chars>special characters: &lt;&gt;&quot;'&amp;</chars>
+ </ns1:child1>
+</root>
diff --git a/ext/xmlwriter/tests/OO_008.phpt b/ext/xmlwriter/tests/OO_008.phpt
new file mode 100644
index 0000000..ee55598
--- /dev/null
+++ b/ext/xmlwriter/tests/OO_008.phpt
@@ -0,0 +1,36 @@
+--TEST--
+XMLWriter: libxml2 XML Writer DTD Element & Attlist
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("$xw->start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = new XMLWriter();
+$xw->openMemory();
+$xw->setIndent(TRUE);
+$xw->startDocument(NULL, "UTF-8");
+$xw->writeDtdElement('sxe', '(elem1+, elem11, elem22*)');
+$xw->writeDtdAttlist('sxe', 'id CDATA #implied');
+$xw->startDtdElement('elem1');
+$xw->text('elem2*');
+$xw->endDtdElement();
+$xw->startDtdAttlist('elem1');
+$xw->text("attr1 CDATA #required\n");
+$xw->text('attr2 CDATA #implied');
+$xw->endDtdAttlist();
+$xw->endDocument();
+// Force to write and empty the buffer
+$output = $xw->flush(true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<!ELEMENT sxe (elem1+, elem11, elem22*)>
+<!ATTLIST sxe id CDATA #implied>
+<!ELEMENT elem1 elem2*>
+<!ATTLIST elem1 attr1 CDATA #required
+attr2 CDATA #implied>
diff --git a/ext/xmlwriter/tests/OO_009.phpt b/ext/xmlwriter/tests/OO_009.phpt
new file mode 100644
index 0000000..659cfc8
--- /dev/null
+++ b/ext/xmlwriter/tests/OO_009.phpt
@@ -0,0 +1,44 @@
+--TEST--
+XMLWriter: PI, Comment, CDATA
+--SKIPIF--
+<?php
+if (!extension_loaded("xmlwriter")) die("skip");
+if (!function_exists("$xw->start_comment")) die("skip: libxml2 2.6.7+ required");
+?>
+--FILE--
+<?php
+/* $Id$ */
+
+$xw = new XMLWriter();
+$xw->openMemory();
+$xw->setIndent(TRUE);
+$xw->startDocument("1.0", "UTF-8");
+$xw->startElement('root');
+$xw->writeAttribute('id', 'elem1');
+$xw->startElement('elem1');
+$xw->writeAttribute('attr1', 'first');
+$xw->writeComment('start PI');
+$xw->startElement('pi');
+$xw->writePi('php', 'echo "hello world"; ');
+$xw->endElement();
+$xw->startElement('cdata');
+$xw->startCdata();
+$xw->endElement();
+$xw->text('<>&"');
+$xw->endCdata();
+$xw->endElement();
+$xw->endElement();
+$xw->endDocument();
+// Force to write and empty the buffer
+$output = $xw->flush(true);
+print $output;
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<root id="elem1">
+ <elem1 attr1="first">
+ <!--start PI-->
+ <pi><?php echo "hello world"; ?></pi>
+ <cdata><![CDATA[<>&"]]></cdata>
+ </elem1>
+</root>