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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
<?php
// For future use - we should convert the input output tester
// to simple test extension.
class InputOutputTester {
}
class TestBitSmartyFilter extends UnitTestCase {
var $filterTestDir;
var $smartyDir;
function TestBitSmartyFilter ()
{
// directory that contains test directories
$this->filterTestDir = KERNEL_PKG_PATH . '/test/smarty_filter_tests';
$this->smartyDir = KERNEL_PKG_PATH . 'smarty_bit';
}
function testPrePostFilters ()
{
global $gBitLanguage;
$gBitLanguage->mLanguage = 'sv';
$this->assertTrue (is_dir("$this->filterTestDir"), // Quite fatal
"$this->filterTestDir is not a directory", );
// echo "$this->filterTestDir<br />";
$filterTestDirHandle = opendir($this->filterTestDir);
while (false !== ($filterTestCase = readdir($filterTestDirHandle))) {
$filterTestCaseDir = $this->filterTestDir . '/' . $filterTestCase;
$this->assertTrue(is_dir ($filterTestCaseDir),
"$filterTestCaseDir is not a directory", );
// echo "$filterTestCaseDir<br />";
if (preg_match('/(.+)filter\.(.+)/', $filterTestCase, $matches)) {
// echo "$matches[0]<br />";
$filterType = $matches[1];
$filterBase = $matches[2];
$smartyFile =
$this->smartyDir . '/' . $filterType .'filter.' . $filterBase . '.php';
$filterName = 'smarty_' . $filterType . 'filter_' .$filterBase;
// echo "$smartyFile<br />";
// echo "$filterName<br />";
$this->assertTrue(file_exists ($smartyFile),
"Smarty filter $smartyFile is missing", );
include_once($smartyFile);
// echo "$filterTestCaseDir<br />";
$filterTestCaseDirHandle = opendir("$filterTestCaseDir");
while (false != ($inputFile = readdir($filterTestCaseDirHandle))) {
if (preg_match('/^(.+)\.input$/', $inputFile, $matches)) {
$baseName = $matches[1];
$outputFile = $filterTestCaseDir . '/' . $baseName . '.output';
$errorFile = $filterTestCaseDir . '/' . $baseName . '.error';
$inputFile = $filterTestCaseDir . '/' . $inputFile;
// echo "$inputFile<br />";
// echo "$outputFile<br />";
// echo "$errorFile<br />";
$this->assertTrue(file_exists ($inputFile),
(file_exists ($inputFile) ?
"" :
"Input file <strong>$inputFile</strong> " .
"is missing"), );
// remove error file if there is no error
if (file_exists($errorFile)) {
@unlink ($errorFile);
}
$input = file_get_contents($inputFile);
// $filterOutput = call_user_func ($filterName, $input, &$smarty);
$filterOutput = call_user_func_array ($filterName,
[$input, &$gBitSmarty], );
if (!file_exists($outputFile)) {
// Output file does not exist - Create error file
// echo "OUTPUT does not Exists<br />";
$this->assertTrue(file_exists ($outputFile),
(file_exists ($outputFile) ?
"" :
"Output file <strong>$outputFile</strong> " .
"is missing, " .
"<strong>$errorFile</strong> created."), );
// Error handling missing when writing to file,
// final code should be encapsulated in a function.
$outHandle = fopen ($errorFile, 'wb');
fwrite ($outHandle, $filterOutput, strlen ($filterOutput));
fclose($outHandle);
// echo "END OUTPUT does not Exists<br />";
// break;
}
else {
// echo "OUTPUT Exists<br />";
$output = file_get_contents($outputFile);
$compareResult = strcmp ($output, $filterOutput);
// print "$output <br />\n";
// print "$filterOutput <br />\n";
// print "$compareResult <br \>\n";
$this->assertTrue (0 == $compareResult,
(0 == $compareResult ?
"" :
"<strong>$inputFile</strong> did not match " .
"output, incorrect data stored in " .
"<strong>$errorFile</strong>"), );
if (0 != $compareResult) {
$outHandle = fopen ($errorFile, 'wb');
fwrite ($outHandle, $filterOutput, strlen ($filterOutput));
fclose($outHandle);
}
// echo "END OUTPUT Exists<br />";
}
}
}
}
}
}
}
?>
|