This repository has been archived by the owner on May 8, 2021. It is now read-only.
/
TestFSBase.php
117 lines (109 loc) · 2.55 KB
/
TestFSBase.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
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
<?php
/**
* The structure for the tests that use TestFS.
*
* @author Tomasz "Zyx" Jędrzejewski
* @copyright Copyright (c) 2009 Invenzzia Group
* @license http://www.invenzzia.org/license/new-bsd New BSD License
*/
class Extra_TestFSBase extends Extra_Testcase
{
/**
* The main OPT object.
* @var Opt_Class
*/
protected $tpl;
/**
* Sets up everything.
*/
protected function setUp()
{
$tpl = new Opt_Class;
$tpl->sourceDir = 'test://templates/';
$tpl->compileDir = dirname(__FILE__).'/../Cache/';
$tpl->compileMode = Opt_Class::CM_REBUILD;
$tpl->stripWhitespaces = false;
$tpl->prologRequired = true;
$this->configure($tpl);
$tpl->setup();
$this->tpl = $tpl;
} // end setUp();
/**
* Allows to configure the main object.
* @param Opt_Class $tpl
*/
public function configure(Opt_Class $tpl)
{
/* null */
} // end configure();
/**
* Finalizes everything.
*/
protected function tearDown()
{
Opl_Registry::register('opt', null);
Opt_View::clear();
unset($this->tpl);
} // end tearDown();
/**
* Strips the certain white characters from the output in order to
* give more reliable comparisons.
*
* @param String $text Original text.
* @return String
*/
private function stripWs($text)
{
return str_replace(array("\r", "\n"),array('', ''), $text);
} // end stripws();
/**
* Checks the test using TestFS.
*
* @param String $test Test case path
* @return Boolean
*/
protected function _checkTest($test)
{
Extra_TestFS::loadFilesystem($test);
$view = new Opt_View('test.tpl');
if(file_exists('test://data.php'))
{
// $code = ;
// echo $code;
eval(file_get_contents('test://data.php'));
}
$out = new Opt_Output_Return;
$expected = file_get_contents('test://expected.txt');
if(strpos($expected, 'OUTPUT') === 0)
{
// This test shoud give correct results
try
{
$result = $out->render($view);
$this->assertEquals($this->stripWs(trim(file_get_contents('test://result.txt'))), $this->stripWs(trim($result)));
}
catch(Opt_Exception $e)
{
$this->fail('Exception returned: #'.get_class($e).': '.$e->getMessage());
}
}
else
{
// This test should generate an exception
$expected = trim($expected);
try
{
$out->render($view);
}
catch(Opt_Exception $e)
{
if($expected != get_class($e))
{
$this->fail('Invalid exception returned: #'.get_class($e).', '.$expected.' expected.');
}
return true;
}
$this->fail('Exception NOT returned, but should be: '.$expected);
}
} // end _checkTest();
} // end Extra_TestFSBase;