Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 114 lines (101 sloc) 2.452 kb
720b9d9 @zyxist [Opt_2.1] Bugfixing day.
zyxist authored
1 #!/usr/bin/php
2 <?php
3 /**
4 * Because PHPUnit cannot run a particular case from the data provider,
5 * we provide our own utility that allows to run and study a single test
6 * case that uses the filesystem wrapper.
7 *
8 * This script runs the templates in the backward compatibility mode.
9 *
10 * Usage: run-bc.php /directory/something.txt
11 */
12
13 if($argc != 2 && $argc != 3)
14 {
15 die("Invalid call!\n");
16 }
17
18 define('CPL_DIR', './Cache/');
19 require('./Bootstrap.php');
20 $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
21
22 require('./Extra/TestFS.php');
23
24 if($argc == 3)
25 {
26 require('./Extra/'.$argv[2]);
27 }
28
29 class test
30 {
31 protected $tpl;
32
33 public function init()
34 {
35 $tpl = new Opt_Class;
36 $tpl->sourceDir = 'test://templates/';
37 $tpl->compileDir = CPL_DIR;
38 $tpl->compileMode = Opt_Class::CM_REBUILD;
39 $tpl->parser = Opt_Class::HTML_MODE;
40 $tpl->stripWhitespaces = false;
41 $tpl->prologRequired = true;
42 $tpl->backwardCompatibility = true;
43 $tpl->setup();
44 $this->tpl = $tpl;
45 } // end init();
46
47 public function run($test)
48 {
49 Extra_TestFS::loadFilesystem($test);
50 $view = new Opt_View('test.tpl');
51 if(file_exists('test://data.php'))
52 {
53 eval(file_get_contents('test://data.php'));
54 }
55
56 $out = new Opt_Output_Return;
57 $expected = file_get_contents('test://expected.txt');
58
59 if(strpos($expected, 'OUTPUT') === 0)
60 {
61 // This test shoud give correct results
62 try
63 {
64 $result = $out->render($view);
65 if($this->stripWs(trim(file_get_contents('test://result.txt'))) === ($o = $this->stripWs(trim($result))))
66 {
67 return true;
68 }
69 echo $result;
70 die('Invalid output: '.$o."\n");
71 }
72 catch(Opt_Exception $e)
73 {
74 die('Exception returned: #'.get_class($e).': '.$e->getMessage()."\n");
75 }
76 }
77 else
78 {
79 // This test should generate an exception
80 $expected = trim($expected);
81 try
82 {
83 $out->render($view);
84 }
85 catch(Opt_Exception $e)
86 {
87 if($expected != get_class($e))
88 {
89 die('Invalid exception returned: #'.get_class($e).', '.$expected." expected.\n");
90 }
91 return true;
92 }
93 die("Exception NOT returned, but should be: ".$expected."\n");
94 }
95 } // end run();
96
97 private function stripWs($text)
98 {
99 return str_replace(array("\r", "\n"),array('', ''), $text);
100 } // end stripws();
101 } // end test;
102
103 if(!file_exists($argv[1]))
104 {
105 die("The specified test does not exist!\n");
106 }
107
108 $test = new test;
109 $test->init();
110 if($test->run($argv[1]))
111 {
112 die("OK\n");
113 }
Something went wrong with that request. Please try again.