Project

Profile

Help

How to connect?
Download (11.2 KB) Statistics
| Branch: | Tag: | Revision:

he / latest9.6 / hec / samples / xslt30TestSuite.php @ 74569bc0

1
<?php 
2
/*error_reporting(E_ALL|E_STRICT);
3
ini_set('display_errors', 'on');*/
4
ini_set('max_execution_time', 300);
5
$root=pathinfo($_SERVER['SCRIPT_FILENAME']);
6
define ('BASE_FOLDER', basename($root['dirname']));
7
define ('SITE_ROOT',    realpath(dirname(__FILE__)));
8
define ('SITE_URL',    'http://'.$_SERVER['HTTP_HOST'].'/'.BASE_FOLDER);
9

    
10

    
11
echo 'BASE_FOLDER'. basename($root['dirname']);
12
echo '<br/>';
13
echo 'SITE_ROOT'.    realpath(dirname(__FILE__));
14
echo '<br/>';
15
echo 'SITE_URL'.    'http://'.$_SERVER['HTTP_HOST'].'/'.BASE_FOLDER;
16
echo '<br/>';
17

    
18

    
19
 $saved = getenv("LD_LIBRARY_PATH");        // save old value
20
 $newld = "/usr/local/jet9.0-pro-x86/lib/x86/shared";  // extra paths to add
21
 if ($saved) { $newld .= ":$saved"; }           // append old paths if any
22
 putenv("LD_LIBRARY_PATH=$newld");        // set new value
23

    
24
                        // mycommand is loaded using
25
                        // libs in the new path list
26
 putenv("LD_LIBRARY_PATH=$saved");  
27

    
28
 $saved = getenv("PATH");        // save old value
29
 $newld = "/usr/local/jet9.0-pro-x86/bin:/usr/local/jet9.0-pro-x86/profile1.7.0_40/jre";  // extra paths to add
30
 if ($saved) { $newld .= ":$saved"; }           // append old paths if any
31
putenv("PATH=$newld");        // set new value
32
 
33
                        // mycommand is loaded using
34
                        // libs in the new path list
35
 //putenv("PATH=$saved"); 
36
//phpinfo();
37

    
38

    
39

    
40
$path = "xslt30-test/";
41
$catalog = $path."catalog.xml";
42
$saxon_version = "";
43

    
44
$proc = new SaxonProcessor();
45
$start = microtime(true);
46
              $proc->setSourceFile("cat.xml");
47
                $proc->importStylesheetFile("test.xsl");
48
                $result = $proc->transformToValue();
49
 $end = microtime(true);
50

    
51

    
52
    echo "Time : " . ($end-$start) . "s\n";
53
if($result == NULL) {
54
                      $errCount = $proc->getExceptionCount();
55
       echo $errCount;    
56
if($errCount>0){ 
57
                      echo 'Error: '.$proc->getErrorMessage(0)." code:".$proc->getErrorCode(0);        
58
                           }
59
    
60
   } else {
61
echo $result;
62
}
63
//$proc->clear();
64
//$proc->close();
65

    
66

    
67
function test_set_files ($catalog){ 
68
        
69
        $array = array();  
70
        $attName;
71
        $attFile;
72
        if (file_exists($catalog)) {
73
              $xml = simplexml_load_file($catalog);
74
              foreach ($xml->{'test-set'} as $value) {
75
//        echo "________________".$value->attributes()->name."_________".$value->attributes()->file;
76
        $attName = $value->attributes()->name;
77
        $attFile = $value->attributes()->file;
78
        $array["".$attName] = $attFile;        
79
      }        
80
      } else {
81
        exit('Failed to open '.$catalog);
82
      }
83
   return $array;
84
}
85

    
86
function check_dependency($xml){
87
        foreach ($xml->children() as $child)
88
        {
89
          $var1 = $child->getName();
90
          switch($var1) {
91
            case "feature":
92
                return false;
93
            case "spec":
94
                if(strpos($child->attributes()->{'value'},"XSLT30")!== false){
95
                        return false;                        
96
                }
97
          }
98
        }
99
        return true;
100
}
101

    
102
function parse_environment($xml, $path){
103
        $array = array();
104
              foreach ($xml->{'environment'} as $value) {
105
                $envName = $value->attributes()->name;
106
                $source = $value->{'source'};
107
                if($source->attributes()->file and !($source->attributes()->validation)) {
108
                //  echo $path.$source->attributes()->file." ";
109
                  $array["".$envName] = $path.$source->attributes()->file;
110
                }
111
                }
112
        echo "<br/>";
113
        echo "<br/>";
114
        return $array;
115
} 
116

    
117
function test_case($test_set) {
118
        $env;
119
        $xml;
120
        $test_path = pathinfo($test_set)['dirname']."/";
121
        echo $test_path;
122
        if (file_exists($test_set)) {
123
              $xml = simplexml_load_file($test_set);
124
          $env = parse_environment($xml, $test_path);
125
echo "<table border='1' style='width:60%'>
126
<tr>
127
  <th>Test Case Name </th>
128
  <th style='width:80%'>Result </th>
129
</tr>";
130

    
131
$check = check_dependency($xml->dependencies);
132
if($check){
133
          foreach($xml->{'test-case'} as $value){
134
                $testCaseName = $value->attributes()->name;
135
                echo "<tr><td>$testCaseName</td>";
136
                $result = run_test_case($value, $env, $test_path);
137
                echo "<td>".$result."</td>";
138
                echo "</tr>";
139
                 //$test = $value->{'test'}->{'stylesheet'};
140
                //echo "____test:".$test_path."tests".$test->attributes()->file;
141
          }
142
}else {
143
echo "<tr><td>No tests run</td><td></td></tr>";
144
}
145
echo "</table>";
146
                
147
      } else {
148
        exit('Failed to open '.$test_set);
149
      }        
150
}
151

    
152
function run_test_case($testcase, $env, $path){
153
        global $proc;
154
        $errorTest = FALSE;
155
        $t_env = $testcase->{'environment'};
156
        $testDirValue = new XdmValue(strval($path));
157
        $t_env_ref = $t_env->attributes()->ref;
158
        $checkDependency = check_dependency($testcase->dependencies);
159
        if($checkDependency){
160
                
161
                        $test = $path.$testcase->{'test'}->{'stylesheet'}->attributes()->file;
162
                        //echo $test;
163
                        if (file_exists($test)) {
164
                                try{
165
                                        if($t_env) {
166
                                        if($env[$t_env_ref.""]){
167
                                                $proc->clear();
168
                                                //error_log("before apply source:".$env[$t_env_ref.""]);
169
                                                //error_log("before apply stylesheet:".$test);
170
                                                $init_template = $testcase->{'test'}->{'initial-template'};
171
                                                if($init_template){
172
                                                        $proc->setProperty('it', strval($testcase->{'test'}->{'initial-template'}->attributes()->{'name'}));
173
                                                }
174
                                                $result = $proc->xsltApplyStylesheet($env[$t_env_ref.""], $test);
175
                                                if($result == NULL) {
176
                                                        echo 'Error: '.$proc->getErrorMessage(0)." code:".$proc->getErrorCode(0);                
177
                                                        $errCount = $proc->getExceptionCount();
178
                                                        $result= "";
179
                                                        if($errCount > 0 ){
180
                                                        $result= "<out>";
181
                                                          for ($i = 0; $i < $errCount; $i++) {
182
                                                             $errC = $proc->getErrorCode(intval(i));
183
                                                             if($errC != NULL) {
184
                                                               $result = $result.$errC." ";        
185
                                                             }
186
                                                          $result= $result."</out>";
187
                                                              $errorTest = TRUE;
188
                                                          }
189
                                                        }
190

    
191
                                                                                                        
192
                                                }
193

    
194
                                                $asserts= $testcase->{'result'};
195
                                                $xdmValue = $proc->parseString(strval($asserts->asXML()));
196
                                                /*if($testcase->attributes()->{'name'}=='import-0502b'){
197
                                                         echo "result:".$result;
198
                                                         echo "assert:".($asserts->asXML());
199
                                                        exit('import-0502b');                                        
200
                                                }*/
201
                                                if($xdmValue == NULL){
202
                                                        error_log("NULL FOUND IN ASSERT");
203
                                                        if($proc->getExceptionCount() > 0){
204
                                                                error_log(" assert exception: ".$proc->getErrorMessage(0));
205
                                                                return "NO ASSERTION".($asserts->asXML());
206
                                                        }
207

    
208
                                                }
209
                                                $proc->setParameter('', 'assertion', $xdmValue);
210
                                                error_log("before result : ");
211
                                                $resulti  = $proc->parseString(''.$result);
212
                                                if($resulti== NULL) {        
213
                                                        error_log(" assert exception: ".$proc->getErrorMessage(0));
214
                                                        return "NULL result";
215
                                                }                                                                        
216
                                                $proc->setParameter('', 'result', $resulti);
217
                                                $proc->setParameter('', 'testDir', $testDirValue);
218
                                                $proc->setProperty('it', 'main');
219
                                                $proc->exceptionClear();
220
                                                $outcome = $proc->xsltApplyStylesheet1("TestOutcome.xsl");
221
                                                $proc->clear();
222
                                                if($outcome==NULL){
223
                                                        error_log("Assert:".($asserts->asXML()));
224
                                                        echo "Assert:".($asserts->asXML());
225
                                                        echo "Assert:".($result);
226
                                                        $errCount = $proc->getExceptionCount();
227
                                                        error_log("Error Count".$errCount);
228
                                                        if($errCount > 0 ){
229

    
230
                                                        $result= "<out>";
231
                                                          for ($i = 0; $i < $errCount; $i++) {
232
                                                             $errC = $proc->getErrorMessage(intval(i));
233
                                                             if($errC != NULL) {
234
                                                               $result = $result.$errC." ";        
235
                                                             }
236
                                                              $errorTest = TRUE;
237
                                                          $result= $result."</out>";
238
                                                          }
239

    
240
                                                        echo "Error count: ".$errCount.", ". ($result);
241
                                                        }
242
                                                        return "false";                                                
243
                                                }
244
                                                if($errorTest){
245
                                                        return 'assert-Error: '.$outcome;                                                
246
                                                }
247
                                                $proc->clear();
248
                                                return $outcome;                                                
249
                                        }else {
250
                                                return         $t_env_ref." not found";                                
251
                                        }
252
                                        } else { 
253
                                                $proc->clear();
254
                                                $proc->exceptionClear();
255
                                                $init_template = $testcase->{'test'}->{'initial-template'};
256
                                                if($init_template){
257
                                                        $proc->setProperty('it', strval($testcase->{'test'}->{'initial-template'}->attributes()->{'name'}));
258
                                                }
259
                                                $result = $proc->transformToString($test);
260
                                                if($result == NULL) {
261
                                                        
262
                                                        $errCount = $proc->getExceptionCount();
263
                                                        $result= "";
264
                                                        if($errCount > 0 ){
265
                                                        $result= "<out>";
266
                                                          for ($i = 0; $i < $errCount; $i++) {
267
                                                             $errC = $proc->getErrorCode(intval(i));
268
                                                             if($errC != NULL) {
269
                                                               $result = $result.$errC." ";        
270
                                                             }
271
                                                          $result= $result."</out>";
272
                                                          }
273
                                                        }
274

    
275
                                                                                                        
276
                                                }
277
                                                $asserts= $testcase->{'result'};
278
                                                $xdmValue = $proc->parseString(''.$asserts->asXML());
279
                                                /*if($testcase->attributes()->{'name'}=='import-0502b'){
280
                                                         echo "result:".$result;
281
                                                         echo "assert:".($asserts->asXML());
282
                                                        exit('import-0502b');                                        
283
                                                }*/
284
                                                if($xdmValue == NULL){        
285
                                                                error_log(" assert exception: ".$proc->getErrorMessage(0));
286
                                                                return "NO ASSERTION";
287
                                                }                                        
288
                                                $proc->setParameter('', 'assertion', $xdmValue);
289
                                                $resulti  = $proc->parseString(''.$result);
290
                                                if($resulti== NULL) {
291
                                                        return "NULL result";                
292
                                                }
293
                                                $proc->setParameter('', 'result', $resulti);
294
                                                $proc->setParameter('', 'testDir',$testDirValue);
295
                                                $proc->setProperty('it', 'main');
296
                                                $outcome = $proc->transformToString("TestOutcome.xsl");
297
                                                $proc->clear();
298
                                                if($outcome==NULL){
299
                                                        echo "Assert:".($asserts->asXML());
300
                                                        $errCount = $proc->getExceptionCount();
301
                                                        if($errCount > 0 ){
302
                                                        $result= "<out>";
303
                                                          for ($i = 0; $i < $errCount; $i++) {
304
                                                             $errC = $proc->getErrorMessage(intval(i));
305
                                                             if($errC != NULL) {
306
                                                               $result = $result.$errC." ";        
307
                                                             }
308
                                                          $result= $result."</out>";
309
                                                          }
310

    
311
                                                        echo "Error count: ".$errCount.", ". ($result);
312
                                                        }
313
                                                        return "false";                                                
314
                                                }
315
                                                $proc->clear();
316
                                                if($outcome== FALSE){
317
                                                        $resulti = '|| Assertion: '.($asserts->asXML()).'|||| result: '.$resulti.' ||| ';
318
                                                        return 'assert-Error: '.$outcome;                                                
319
                                                }
320
                                                
321
                                                return $outcome.'';
322
                                        
323
                                        }
324
                                }catch(Exception $ex){
325
                                        return "Fail - error: ".$ex->getMessage();                        
326
                                }
327
                        return "Fail";                        
328
                        } else {
329
                                return $test." not found";                        
330
                        }                
331
                                                        
332
        }
333

    
334
        return "Not Run";
335
}
336

    
337

    
338
$saxon_version = $proc->version();
339
echo "<a name='top'></a>";
340
echo "<h1>W3 XSLT 3.0 Test Suite</h1>
341
<h4>(PHP Test Harness. Version: 1.0. Saxon c++ plugin, Saxon product version: $saxon_version)</h4>
342
<br/>";
343
$testFiles = test_set_files($catalog);
344
echo "<b>Test sets: ".count($testFiles)."<b/>";
345
echo "<table border='1'>
346
<tr>
347
  <th>Test Name </th>
348
  <th>File Name </th>
349
  <th> #Test cases </th>
350
</tr>";
351

    
352
foreach ($testFiles as $key => $test_set) {
353
 $testSet_xml = simplexml_load_file("xslt30-test/".$test_set);
354
echo "<tr>";
355
        echo "<td><a href='#".$key."'>".$key . "</a></td>";
356
        echo "<td>".$test_set."</td>";
357
        echo "<td>".count($testSet_xml->{'test-case'})."</td>";
358
echo "</tr>";
359
}
360
echo "</table>";
361

    
362
foreach ($testFiles as $key => $test_set) {
363
echo "<div style='width:70%'><h4><a name='".$key."'>".$key . "</a></h4></div><div style='width:30%;float:right'><a href='#top'>Back to top</a></div>";
364
//if($key == 'copy-of'){
365
 test_case("xslt30-test/".$test_set);}
366
//}
367
echo "<br/>";
368
//$test1 = $proc->xsltApplyStylesheet("cat.xml","test.xsl");
369

    
370
//$proc->xsltSaveResultToFile("cat.xml", "test.xsl", "output/output.html");
371
                $proc->setSourceFile("cat.xml");
372
                $proc->importStylesheetFile("test.xsl");
373
echo $proc->transformToString();
374
echo "This link is using Html: ";
375

    
376
$proc->close();
377

    
378
?>
(4-4/5)