xref: /PHP-8.3/ext/xmlwriter/tests/010.phpt (revision ac18dd0d)
1--TEST--
2xmlwriter_start/end_attribute()
3--EXTENSIONS--
4xmlwriter
5--FILE--
6<?php
7
8$file = __DIR__.'/010.tmp';
9
10$xw = xmlwriter_open_uri($file);
11
12var_dump(xmlwriter_start_element($xw, "tag"));
13var_dump(xmlwriter_start_attribute($xw, "attr"));
14var_dump(xmlwriter_end_attribute($xw));
15
16try {
17    xmlwriter_start_attribute($xw, "-1");
18} catch (ValueError $e) {
19    echo $e->getMessage(), "\n";
20}
21
22var_dump(xmlwriter_end_attribute($xw));
23
24try {
25    xmlwriter_start_attribute($xw, "\"");
26} catch (ValueError $e) {
27     echo $e->getMessage(), "\n";
28}
29
30var_dump(xmlwriter_end_attribute($xw));
31var_dump(xmlwriter_end_element($xw));
32
33// Force to write and empty the buffer
34xmlwriter_flush($xw, empty: true);
35
36unset($xw);
37
38var_dump(file_get_contents($file));
39
40@unlink($file);
41
42echo "Done\n";
43?>
44--EXPECT--
45bool(true)
46bool(true)
47bool(true)
48xmlwriter_start_attribute(): Argument #2 ($name) must be a valid attribute name, "-1" given
49bool(false)
50xmlwriter_start_attribute(): Argument #2 ($name) must be a valid attribute name, """ given
51bool(false)
52bool(true)
53string(14) "<tag attr=""/>"
54Done
55