-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathgenerateTemplateParserTests.php
executable file
·64 lines (51 loc) · 1.48 KB
/
generateTemplateParserTests.php
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
57
58
59
60
61
62
63
64
#!/usr/bin/php
<?php
$dirpath = realpath(__DIR__ . '/../tests/Configurator/Helpers/data/TemplateParser/');
$void = ['Y' => 'hr', 'M' => '{local-name()}', 'N' => 'div'];
$empty = [
'Y' => ['', ''],
'M' => ['<xsl:apply-templates/>', '<applyTemplates/>'],
'N' => ['foo', '<output escape="text" type="literal">foo</output>']
];
$voidAttr = [
'Y' => ' void="yes"',
'M' => ' void="maybe"',
'N' => ''
];
$emptyAttr = [
'Y' => ' empty="yes"',
'M' => ' empty="maybe"',
'N' => ''
];
$i = 100;
foreach ($void as $iVoid => $elName)
{
foreach ($empty as $iEmpty => $pair)
{
list($xslContent, $xmlContent) = $pair;
$template = '<xsl:element name="' . $elName . '"><xsl:attribute name="id">foo</xsl:attribute>' . $xslContent . '</xsl:element>';
$xml =
'<template>
<element name="' . $elName . '" id="1"' . $voidAttr[$iVoid] . $emptyAttr[$iEmpty] . '>
<attribute name="id">
<output escape="attribute" type="literal">foo</output>
</attribute>
<closeTag id="1"/>';
// Content of void elements is removed in HTML mode
if ($iVoid !== 'Y' && $xmlContent !== '')
{
$xml .= "\n\t\t\t " . $xmlContent;
}
$xml .= '
</element>
</template>';
// Remove the extra indentation
$xml = str_replace("\n\t\t\t", "\n", $xml);
$template = str_replace("\n\t\t\t", "\n", $template);
// Save the result
file_put_contents($dirpath . '/' . $i . '.template', $template);
file_put_contents($dirpath . '/' . $i . '.xml', $xml);
++$i;
}
}
die("Done.\n");