@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | /** |
145 | 145 | * Accessor for default proxy host. |
146 | - * @return string Proxy URL. |
|
146 | + * @return boolean Proxy URL. |
|
147 | 147 | * @access public |
148 | 148 | */ |
149 | 149 | function getDefaultProxy() { |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Accessor for default proxy username. |
156 | - * @return string Proxy username for authentication. |
|
156 | + * @return boolean Proxy username for authentication. |
|
157 | 157 | * @access public |
158 | 158 | */ |
159 | 159 | function getDefaultProxyUsername() { |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | |
164 | 164 | /** |
165 | 165 | * Accessor for default proxy password. |
166 | - * @return string Proxy password for authentication. |
|
166 | + * @return boolean Proxy password for authentication. |
|
167 | 167 | * @access public |
168 | 168 | */ |
169 | 169 | function getDefaultProxyPassword() { |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | /** |
175 | 175 | * Accessor for global registry of options. |
176 | - * @return hash All stored values. |
|
176 | + * @return string All stored values. |
|
177 | 177 | * @access private |
178 | 178 | * @static |
179 | 179 | */ |
@@ -1,365 +1,365 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @version $Id: options.php 1532 2006-12-01 12:28:55Z xue $ |
|
6 | - */ |
|
2 | + /** |
|
3 | + * base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @version $Id: options.php 1532 2006-12-01 12:28:55Z xue $ |
|
6 | + */ |
|
7 | 7 | |
8 | - /** |
|
9 | - * Static global directives and options. |
|
10 | - * @package SimpleTest |
|
11 | - */ |
|
12 | - class SimpleTestOptions { |
|
8 | + /** |
|
9 | + * Static global directives and options. |
|
10 | + * @package SimpleTest |
|
11 | + */ |
|
12 | + class SimpleTestOptions { |
|
13 | 13 | |
14 | - /** |
|
15 | - * Reads the SimpleTest version from the release file. |
|
16 | - * @return string Version string. |
|
17 | - * @static |
|
18 | - * @access public |
|
19 | - */ |
|
20 | - static function getVersion() { |
|
21 | - $content = file(dirname(__FILE__) . '/VERSION'); |
|
22 | - return trim($content[0]); |
|
23 | - } |
|
14 | + /** |
|
15 | + * Reads the SimpleTest version from the release file. |
|
16 | + * @return string Version string. |
|
17 | + * @static |
|
18 | + * @access public |
|
19 | + */ |
|
20 | + static function getVersion() { |
|
21 | + $content = file(dirname(__FILE__) . '/VERSION'); |
|
22 | + return trim($content[0]); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Sets the name of a test case to ignore, usually |
|
27 | - * because the class is an abstract case that should |
|
28 | - * not be run. |
|
29 | - * @param string $class Add a class to ignore. |
|
30 | - * @static |
|
31 | - * @access public |
|
32 | - */ |
|
33 | - static function ignore($class) { |
|
34 | - $registry =SimpleTestOptions::_getRegistry(); |
|
35 | - $registry['IgnoreList'][] = strtolower($class); |
|
36 | - } |
|
25 | + /** |
|
26 | + * Sets the name of a test case to ignore, usually |
|
27 | + * because the class is an abstract case that should |
|
28 | + * not be run. |
|
29 | + * @param string $class Add a class to ignore. |
|
30 | + * @static |
|
31 | + * @access public |
|
32 | + */ |
|
33 | + static function ignore($class) { |
|
34 | + $registry =SimpleTestOptions::_getRegistry(); |
|
35 | + $registry['IgnoreList'][] = strtolower($class); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Test to see if a test case is in the ignore |
|
40 | - * list. |
|
41 | - * @param string $class Class name to test. |
|
42 | - * @return boolean True if should not be run. |
|
43 | - * @access public |
|
44 | - * @static |
|
45 | - */ |
|
46 | - static function isIgnored($class) { |
|
47 | - $registry =SimpleTestOptions::_getRegistry(); |
|
48 | - return in_array(strtolower($class), $registry['IgnoreList']); |
|
49 | - } |
|
38 | + /** |
|
39 | + * Test to see if a test case is in the ignore |
|
40 | + * list. |
|
41 | + * @param string $class Class name to test. |
|
42 | + * @return boolean True if should not be run. |
|
43 | + * @access public |
|
44 | + * @static |
|
45 | + */ |
|
46 | + static function isIgnored($class) { |
|
47 | + $registry =SimpleTestOptions::_getRegistry(); |
|
48 | + return in_array(strtolower($class), $registry['IgnoreList']); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * The base class name is settable here. This is the |
|
53 | - * class that a new stub will inherited from. |
|
54 | - * To modify the generated stubs simply extend the |
|
55 | - * SimpleStub class and set it's name |
|
56 | - * with this method before any stubs are generated. |
|
57 | - * @param string $stub_base Server stub class to use. |
|
58 | - * @static |
|
59 | - * @access public |
|
60 | - */ |
|
61 | - static function setStubBaseClass($stub_base) { |
|
62 | - $registry =SimpleTestOptions::_getRegistry(); |
|
63 | - $registry['StubBaseClass'] = $stub_base; |
|
64 | - } |
|
51 | + /** |
|
52 | + * The base class name is settable here. This is the |
|
53 | + * class that a new stub will inherited from. |
|
54 | + * To modify the generated stubs simply extend the |
|
55 | + * SimpleStub class and set it's name |
|
56 | + * with this method before any stubs are generated. |
|
57 | + * @param string $stub_base Server stub class to use. |
|
58 | + * @static |
|
59 | + * @access public |
|
60 | + */ |
|
61 | + static function setStubBaseClass($stub_base) { |
|
62 | + $registry =SimpleTestOptions::_getRegistry(); |
|
63 | + $registry['StubBaseClass'] = $stub_base; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Accessor for the currently set stub base class. |
|
68 | - * @return string Class name to inherit from. |
|
69 | - * @static |
|
70 | - * @access public |
|
71 | - */ |
|
72 | - static function getStubBaseClass() { |
|
73 | - $registry =SimpleTestOptions::_getRegistry(); |
|
74 | - return $registry['StubBaseClass']; |
|
75 | - } |
|
66 | + /** |
|
67 | + * Accessor for the currently set stub base class. |
|
68 | + * @return string Class name to inherit from. |
|
69 | + * @static |
|
70 | + * @access public |
|
71 | + */ |
|
72 | + static function getStubBaseClass() { |
|
73 | + $registry =SimpleTestOptions::_getRegistry(); |
|
74 | + return $registry['StubBaseClass']; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * The base class name is settable here. This is the |
|
79 | - * class that a new mock will inherited from. |
|
80 | - * To modify the generated mocks simply extend the |
|
81 | - * SimpleMock class and set it's name |
|
82 | - * with this method before any mocks are generated. |
|
83 | - * @param string $mock_base Mock base class to use. |
|
84 | - * @static |
|
85 | - * @access public |
|
86 | - */ |
|
87 | - static function setMockBaseClass($mock_base) { |
|
88 | - $registry =SimpleTestOptions::_getRegistry(); |
|
89 | - $registry['MockBaseClass'] = $mock_base; |
|
90 | - } |
|
77 | + /** |
|
78 | + * The base class name is settable here. This is the |
|
79 | + * class that a new mock will inherited from. |
|
80 | + * To modify the generated mocks simply extend the |
|
81 | + * SimpleMock class and set it's name |
|
82 | + * with this method before any mocks are generated. |
|
83 | + * @param string $mock_base Mock base class to use. |
|
84 | + * @static |
|
85 | + * @access public |
|
86 | + */ |
|
87 | + static function setMockBaseClass($mock_base) { |
|
88 | + $registry =SimpleTestOptions::_getRegistry(); |
|
89 | + $registry['MockBaseClass'] = $mock_base; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Accessor for the currently set mock base class. |
|
94 | - * @return string Class name to inherit from. |
|
95 | - * @static |
|
96 | - * @access public |
|
97 | - */ |
|
98 | - static function getMockBaseClass() { |
|
99 | - $registry =SimpleTestOptions::_getRegistry(); |
|
100 | - return $registry['MockBaseClass']; |
|
101 | - } |
|
92 | + /** |
|
93 | + * Accessor for the currently set mock base class. |
|
94 | + * @return string Class name to inherit from. |
|
95 | + * @static |
|
96 | + * @access public |
|
97 | + */ |
|
98 | + static function getMockBaseClass() { |
|
99 | + $registry =SimpleTestOptions::_getRegistry(); |
|
100 | + return $registry['MockBaseClass']; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Adds additional mock code. |
|
105 | - * @param string $code Extra code that can be added |
|
106 | - * to the partial mocks for |
|
107 | - * extra functionality. Useful |
|
108 | - * when a test tool has overridden |
|
109 | - * the mock base classes. |
|
110 | - * @access public |
|
111 | - */ |
|
112 | - static function addPartialMockCode($code = '') { |
|
113 | - $registry =SimpleTestOptions::_getRegistry(); |
|
114 | - $registry['AdditionalPartialMockCode'] = $code; |
|
115 | - } |
|
103 | + /** |
|
104 | + * Adds additional mock code. |
|
105 | + * @param string $code Extra code that can be added |
|
106 | + * to the partial mocks for |
|
107 | + * extra functionality. Useful |
|
108 | + * when a test tool has overridden |
|
109 | + * the mock base classes. |
|
110 | + * @access public |
|
111 | + */ |
|
112 | + static function addPartialMockCode($code = '') { |
|
113 | + $registry =SimpleTestOptions::_getRegistry(); |
|
114 | + $registry['AdditionalPartialMockCode'] = $code; |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Accessor for additional partial mock code. |
|
119 | - * @return string Extra code. |
|
120 | - * @access public |
|
121 | - */ |
|
122 | - function getPartialMockCode() { |
|
123 | - $registry =SimpleTestOptions::_getRegistry(); |
|
124 | - return $registry['AdditionalPartialMockCode']; |
|
125 | - } |
|
117 | + /** |
|
118 | + * Accessor for additional partial mock code. |
|
119 | + * @return string Extra code. |
|
120 | + * @access public |
|
121 | + */ |
|
122 | + function getPartialMockCode() { |
|
123 | + $registry =SimpleTestOptions::_getRegistry(); |
|
124 | + return $registry['AdditionalPartialMockCode']; |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Sets proxy to use on all requests for when |
|
129 | - * testing from behind a firewall. Set host |
|
130 | - * to false to disable. This will take effect |
|
131 | - * if there are no other proxy settings. |
|
132 | - * @param string $proxy Proxy host as URL. |
|
133 | - * @param string $username Proxy username for authentication. |
|
134 | - * @param string $password Proxy password for authentication. |
|
135 | - * @access public |
|
136 | - */ |
|
137 | - static function useProxy($proxy, $username = false, $password = false) { |
|
138 | - $registry =SimpleTestOptions::_getRegistry(); |
|
139 | - $registry['DefaultProxy'] = $proxy; |
|
140 | - $registry['DefaultProxyUsername'] = $username; |
|
141 | - $registry['DefaultProxyPassword'] = $password; |
|
142 | - } |
|
127 | + /** |
|
128 | + * Sets proxy to use on all requests for when |
|
129 | + * testing from behind a firewall. Set host |
|
130 | + * to false to disable. This will take effect |
|
131 | + * if there are no other proxy settings. |
|
132 | + * @param string $proxy Proxy host as URL. |
|
133 | + * @param string $username Proxy username for authentication. |
|
134 | + * @param string $password Proxy password for authentication. |
|
135 | + * @access public |
|
136 | + */ |
|
137 | + static function useProxy($proxy, $username = false, $password = false) { |
|
138 | + $registry =SimpleTestOptions::_getRegistry(); |
|
139 | + $registry['DefaultProxy'] = $proxy; |
|
140 | + $registry['DefaultProxyUsername'] = $username; |
|
141 | + $registry['DefaultProxyPassword'] = $password; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Accessor for default proxy host. |
|
146 | - * @return string Proxy URL. |
|
147 | - * @access public |
|
148 | - */ |
|
149 | - function getDefaultProxy() { |
|
150 | - $registry =SimpleTestOptions::_getRegistry(); |
|
151 | - return $registry['DefaultProxy']; |
|
152 | - } |
|
144 | + /** |
|
145 | + * Accessor for default proxy host. |
|
146 | + * @return string Proxy URL. |
|
147 | + * @access public |
|
148 | + */ |
|
149 | + function getDefaultProxy() { |
|
150 | + $registry =SimpleTestOptions::_getRegistry(); |
|
151 | + return $registry['DefaultProxy']; |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * Accessor for default proxy username. |
|
156 | - * @return string Proxy username for authentication. |
|
157 | - * @access public |
|
158 | - */ |
|
159 | - function getDefaultProxyUsername() { |
|
160 | - $registry =SimpleTestOptions::_getRegistry(); |
|
161 | - return $registry['DefaultProxyUsername']; |
|
162 | - } |
|
154 | + /** |
|
155 | + * Accessor for default proxy username. |
|
156 | + * @return string Proxy username for authentication. |
|
157 | + * @access public |
|
158 | + */ |
|
159 | + function getDefaultProxyUsername() { |
|
160 | + $registry =SimpleTestOptions::_getRegistry(); |
|
161 | + return $registry['DefaultProxyUsername']; |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Accessor for default proxy password. |
|
166 | - * @return string Proxy password for authentication. |
|
167 | - * @access public |
|
168 | - */ |
|
169 | - function getDefaultProxyPassword() { |
|
170 | - $registry =SimpleTestOptions::_getRegistry(); |
|
171 | - return $registry['DefaultProxyPassword']; |
|
172 | - } |
|
164 | + /** |
|
165 | + * Accessor for default proxy password. |
|
166 | + * @return string Proxy password for authentication. |
|
167 | + * @access public |
|
168 | + */ |
|
169 | + function getDefaultProxyPassword() { |
|
170 | + $registry =SimpleTestOptions::_getRegistry(); |
|
171 | + return $registry['DefaultProxyPassword']; |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Accessor for global registry of options. |
|
176 | - * @return hash All stored values. |
|
177 | - * @access private |
|
178 | - * @static |
|
179 | - */ |
|
180 | - static function _getRegistry() { |
|
181 | - static $registry = false; |
|
182 | - if (! $registry) { |
|
183 | - $registry = SimpleTestOptions::_getDefaults(); |
|
184 | - } |
|
185 | - return $registry; |
|
186 | - } |
|
174 | + /** |
|
175 | + * Accessor for global registry of options. |
|
176 | + * @return hash All stored values. |
|
177 | + * @access private |
|
178 | + * @static |
|
179 | + */ |
|
180 | + static function _getRegistry() { |
|
181 | + static $registry = false; |
|
182 | + if (! $registry) { |
|
183 | + $registry = SimpleTestOptions::_getDefaults(); |
|
184 | + } |
|
185 | + return $registry; |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Constant default values. |
|
190 | - * @return hash All registry defaults. |
|
191 | - * @access private |
|
192 | - * @static |
|
193 | - */ |
|
194 | - static function _getDefaults() { |
|
195 | - return array( |
|
196 | - 'StubBaseClass' => 'SimpleStub', |
|
197 | - 'MockBaseClass' => 'SimpleMock', |
|
198 | - 'IgnoreList' => array(), |
|
199 | - 'AdditionalPartialMockCode' => '', |
|
200 | - 'DefaultProxy' => false, |
|
201 | - 'DefaultProxyUsername' => false, |
|
202 | - 'DefaultProxyPassword' => false); |
|
203 | - } |
|
204 | - } |
|
188 | + /** |
|
189 | + * Constant default values. |
|
190 | + * @return hash All registry defaults. |
|
191 | + * @access private |
|
192 | + * @static |
|
193 | + */ |
|
194 | + static function _getDefaults() { |
|
195 | + return array( |
|
196 | + 'StubBaseClass' => 'SimpleStub', |
|
197 | + 'MockBaseClass' => 'SimpleMock', |
|
198 | + 'IgnoreList' => array(), |
|
199 | + 'AdditionalPartialMockCode' => '', |
|
200 | + 'DefaultProxy' => false, |
|
201 | + 'DefaultProxyUsername' => false, |
|
202 | + 'DefaultProxyPassword' => false); |
|
203 | + } |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * Static methods for compatibility between different |
|
208 | - * PHP versions. |
|
209 | - * @package SimpleTest |
|
210 | - */ |
|
211 | - class SimpleTestCompatibility { |
|
206 | + /** |
|
207 | + * Static methods for compatibility between different |
|
208 | + * PHP versions. |
|
209 | + * @package SimpleTest |
|
210 | + */ |
|
211 | + class SimpleTestCompatibility { |
|
212 | 212 | |
213 | - /** |
|
214 | - * Identity test. Drops back to equality + types for PHP5 |
|
215 | - * objects as the === operator counts as the |
|
216 | - * stronger reference constraint. |
|
217 | - * @param mixed $first Test subject. |
|
218 | - * @param mixed $second Comparison object. |
|
219 | - * @access public |
|
220 | - * @static |
|
221 | - */ |
|
222 | - static function isIdentical($first, $second) { |
|
223 | - if ($first != $second) { |
|
224 | - return false; |
|
225 | - } |
|
226 | - if (version_compare(phpversion(), '5') >= 0) { |
|
227 | - return SimpleTestCompatibility::_isIdenticalType($first, $second); |
|
228 | - } |
|
229 | - return ($first === $second); |
|
230 | - } |
|
213 | + /** |
|
214 | + * Identity test. Drops back to equality + types for PHP5 |
|
215 | + * objects as the === operator counts as the |
|
216 | + * stronger reference constraint. |
|
217 | + * @param mixed $first Test subject. |
|
218 | + * @param mixed $second Comparison object. |
|
219 | + * @access public |
|
220 | + * @static |
|
221 | + */ |
|
222 | + static function isIdentical($first, $second) { |
|
223 | + if ($first != $second) { |
|
224 | + return false; |
|
225 | + } |
|
226 | + if (version_compare(phpversion(), '5') >= 0) { |
|
227 | + return SimpleTestCompatibility::_isIdenticalType($first, $second); |
|
228 | + } |
|
229 | + return ($first === $second); |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * Recursive type test. |
|
234 | - * @param mixed $first Test subject. |
|
235 | - * @param mixed $second Comparison object. |
|
236 | - * @access private |
|
237 | - * @static |
|
238 | - */ |
|
239 | - static function _isIdenticalType($first, $second) { |
|
240 | - if (gettype($first) != gettype($second)) { |
|
241 | - return false; |
|
242 | - } |
|
243 | - if (is_object($first) && is_object($second)) { |
|
244 | - if (get_class($first) != get_class($second)) { |
|
245 | - return false; |
|
246 | - } |
|
247 | - return SimpleTestCompatibility::_isArrayOfIdenticalTypes( |
|
248 | - get_object_vars($first), |
|
249 | - get_object_vars($second)); |
|
250 | - } |
|
251 | - if (is_array($first) && is_array($second)) { |
|
252 | - return SimpleTestCompatibility::_isArrayOfIdenticalTypes($first, $second); |
|
253 | - } |
|
254 | - return true; |
|
255 | - } |
|
232 | + /** |
|
233 | + * Recursive type test. |
|
234 | + * @param mixed $first Test subject. |
|
235 | + * @param mixed $second Comparison object. |
|
236 | + * @access private |
|
237 | + * @static |
|
238 | + */ |
|
239 | + static function _isIdenticalType($first, $second) { |
|
240 | + if (gettype($first) != gettype($second)) { |
|
241 | + return false; |
|
242 | + } |
|
243 | + if (is_object($first) && is_object($second)) { |
|
244 | + if (get_class($first) != get_class($second)) { |
|
245 | + return false; |
|
246 | + } |
|
247 | + return SimpleTestCompatibility::_isArrayOfIdenticalTypes( |
|
248 | + get_object_vars($first), |
|
249 | + get_object_vars($second)); |
|
250 | + } |
|
251 | + if (is_array($first) && is_array($second)) { |
|
252 | + return SimpleTestCompatibility::_isArrayOfIdenticalTypes($first, $second); |
|
253 | + } |
|
254 | + return true; |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Recursive type test for each element of an array. |
|
259 | - * @param mixed $first Test subject. |
|
260 | - * @param mixed $second Comparison object. |
|
261 | - * @access private |
|
262 | - * @static |
|
263 | - */ |
|
264 | - static function _isArrayOfIdenticalTypes($first, $second) { |
|
265 | - if (array_keys($first) != array_keys($second)) { |
|
266 | - return false; |
|
267 | - } |
|
268 | - foreach (array_keys($first) as $key) { |
|
269 | - $is_identical = SimpleTestCompatibility::_isIdenticalType( |
|
270 | - $first[$key], |
|
271 | - $second[$key]); |
|
272 | - if (! $is_identical) { |
|
273 | - return false; |
|
274 | - } |
|
275 | - } |
|
276 | - return true; |
|
277 | - } |
|
257 | + /** |
|
258 | + * Recursive type test for each element of an array. |
|
259 | + * @param mixed $first Test subject. |
|
260 | + * @param mixed $second Comparison object. |
|
261 | + * @access private |
|
262 | + * @static |
|
263 | + */ |
|
264 | + static function _isArrayOfIdenticalTypes($first, $second) { |
|
265 | + if (array_keys($first) != array_keys($second)) { |
|
266 | + return false; |
|
267 | + } |
|
268 | + foreach (array_keys($first) as $key) { |
|
269 | + $is_identical = SimpleTestCompatibility::_isIdenticalType( |
|
270 | + $first[$key], |
|
271 | + $second[$key]); |
|
272 | + if (! $is_identical) { |
|
273 | + return false; |
|
274 | + } |
|
275 | + } |
|
276 | + return true; |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * Test for two variables being aliases. |
|
281 | - * @param mixed $first Test subject. |
|
282 | - * @param mixed $second Comparison object. |
|
283 | - * @access public |
|
284 | - * @static |
|
285 | - */ |
|
286 | - static function isReference($first, $second) { |
|
287 | - if (version_compare(phpversion(), '5', '>=') |
|
288 | - && is_object($first)) { |
|
289 | - return ($first === $second); |
|
290 | - } |
|
291 | - $temp = $first; |
|
292 | - $first = uniqid("test"); |
|
293 | - $is_ref = ($first === $second); |
|
294 | - $first = $temp; |
|
295 | - return $is_ref; |
|
296 | - } |
|
279 | + /** |
|
280 | + * Test for two variables being aliases. |
|
281 | + * @param mixed $first Test subject. |
|
282 | + * @param mixed $second Comparison object. |
|
283 | + * @access public |
|
284 | + * @static |
|
285 | + */ |
|
286 | + static function isReference($first, $second) { |
|
287 | + if (version_compare(phpversion(), '5', '>=') |
|
288 | + && is_object($first)) { |
|
289 | + return ($first === $second); |
|
290 | + } |
|
291 | + $temp = $first; |
|
292 | + $first = uniqid("test"); |
|
293 | + $is_ref = ($first === $second); |
|
294 | + $first = $temp; |
|
295 | + return $is_ref; |
|
296 | + } |
|
297 | 297 | |
298 | - /** |
|
299 | - * Test to see if an object is a member of a |
|
300 | - * class hiearchy. |
|
301 | - * @param object $object Object to test. |
|
302 | - * @param string $class Root name of hiearchy. |
|
303 | - * @access public |
|
304 | - * @static |
|
305 | - */ |
|
306 | - static function isA($object, $class) { |
|
307 | - if (version_compare(phpversion(), '5') >= 0) { |
|
308 | - if (! class_exists($class, false)) { |
|
309 | - return false; |
|
310 | - } |
|
311 | - eval("\$is_a = \$object instanceof $class;"); |
|
312 | - return $is_a; |
|
313 | - } |
|
314 | - if (function_exists('is_a')) { |
|
315 | - return is_a($object, $class); |
|
316 | - } |
|
317 | - return ((strtolower($class) == get_class($object)) |
|
318 | - or (is_subclass_of($object, $class))); |
|
319 | - } |
|
298 | + /** |
|
299 | + * Test to see if an object is a member of a |
|
300 | + * class hiearchy. |
|
301 | + * @param object $object Object to test. |
|
302 | + * @param string $class Root name of hiearchy. |
|
303 | + * @access public |
|
304 | + * @static |
|
305 | + */ |
|
306 | + static function isA($object, $class) { |
|
307 | + if (version_compare(phpversion(), '5') >= 0) { |
|
308 | + if (! class_exists($class, false)) { |
|
309 | + return false; |
|
310 | + } |
|
311 | + eval("\$is_a = \$object instanceof $class;"); |
|
312 | + return $is_a; |
|
313 | + } |
|
314 | + if (function_exists('is_a')) { |
|
315 | + return is_a($object, $class); |
|
316 | + } |
|
317 | + return ((strtolower($class) == get_class($object)) |
|
318 | + or (is_subclass_of($object, $class))); |
|
319 | + } |
|
320 | 320 | |
321 | - /** |
|
322 | - * Autoload safe version of class_exists(). |
|
323 | - * @param string $class Name of class to look for. |
|
324 | - * @return boolean True if class is defined. |
|
325 | - * @access public |
|
326 | - * @static |
|
327 | - */ |
|
328 | - static function classExists($class) { |
|
329 | - if (version_compare(phpversion(), '5') >= 0) { |
|
330 | - return class_exists($class, false); |
|
331 | - } else { |
|
332 | - return class_exists($class); |
|
333 | - } |
|
334 | - } |
|
321 | + /** |
|
322 | + * Autoload safe version of class_exists(). |
|
323 | + * @param string $class Name of class to look for. |
|
324 | + * @return boolean True if class is defined. |
|
325 | + * @access public |
|
326 | + * @static |
|
327 | + */ |
|
328 | + static function classExists($class) { |
|
329 | + if (version_compare(phpversion(), '5') >= 0) { |
|
330 | + return class_exists($class, false); |
|
331 | + } else { |
|
332 | + return class_exists($class); |
|
333 | + } |
|
334 | + } |
|
335 | 335 | |
336 | - /** |
|
337 | - * Sets a socket timeout for each chunk. |
|
338 | - * @param resource $handle Socket handle. |
|
339 | - * @param integer $timeout Limit in seconds. |
|
340 | - * @access public |
|
341 | - * @static |
|
342 | - */ |
|
343 | - static function setTimeout($handle, $timeout) { |
|
344 | - if (function_exists('stream_set_timeout')) { |
|
345 | - stream_set_timeout($handle, $timeout, 0); |
|
346 | - } elseif (function_exists('socket_set_timeout')) { |
|
347 | - socket_set_timeout($handle, $timeout, 0); |
|
348 | - } elseif (function_exists('set_socket_timeout')) { |
|
349 | - set_socket_timeout($handle, $timeout, 0); |
|
350 | - } |
|
351 | - } |
|
336 | + /** |
|
337 | + * Sets a socket timeout for each chunk. |
|
338 | + * @param resource $handle Socket handle. |
|
339 | + * @param integer $timeout Limit in seconds. |
|
340 | + * @access public |
|
341 | + * @static |
|
342 | + */ |
|
343 | + static function setTimeout($handle, $timeout) { |
|
344 | + if (function_exists('stream_set_timeout')) { |
|
345 | + stream_set_timeout($handle, $timeout, 0); |
|
346 | + } elseif (function_exists('socket_set_timeout')) { |
|
347 | + socket_set_timeout($handle, $timeout, 0); |
|
348 | + } elseif (function_exists('set_socket_timeout')) { |
|
349 | + set_socket_timeout($handle, $timeout, 0); |
|
350 | + } |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * Gets the current stack trace topmost first. |
|
355 | - * @return array List of stack frames. |
|
356 | - * @access public |
|
357 | - * @static |
|
358 | - */ |
|
359 | - static function getStackTrace() { |
|
360 | - if (function_exists('debug_backtrace')) { |
|
361 | - return array_reverse(debug_backtrace()); |
|
362 | - } |
|
363 | - return array(); |
|
364 | - } |
|
365 | - } |
|
353 | + /** |
|
354 | + * Gets the current stack trace topmost first. |
|
355 | + * @return array List of stack frames. |
|
356 | + * @access public |
|
357 | + * @static |
|
358 | + */ |
|
359 | + static function getStackTrace() { |
|
360 | + if (function_exists('debug_backtrace')) { |
|
361 | + return array_reverse(debug_backtrace()); |
|
362 | + } |
|
363 | + return array(); |
|
364 | + } |
|
365 | + } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @access public |
32 | 32 | */ |
33 | 33 | static function ignore($class) { |
34 | - $registry =SimpleTestOptions::_getRegistry(); |
|
34 | + $registry = SimpleTestOptions::_getRegistry(); |
|
35 | 35 | $registry['IgnoreList'][] = strtolower($class); |
36 | 36 | } |
37 | 37 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @static |
45 | 45 | */ |
46 | 46 | static function isIgnored($class) { |
47 | - $registry =SimpleTestOptions::_getRegistry(); |
|
47 | + $registry = SimpleTestOptions::_getRegistry(); |
|
48 | 48 | return in_array(strtolower($class), $registry['IgnoreList']); |
49 | 49 | } |
50 | 50 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @access public |
60 | 60 | */ |
61 | 61 | static function setStubBaseClass($stub_base) { |
62 | - $registry =SimpleTestOptions::_getRegistry(); |
|
62 | + $registry = SimpleTestOptions::_getRegistry(); |
|
63 | 63 | $registry['StubBaseClass'] = $stub_base; |
64 | 64 | } |
65 | 65 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @access public |
71 | 71 | */ |
72 | 72 | static function getStubBaseClass() { |
73 | - $registry =SimpleTestOptions::_getRegistry(); |
|
73 | + $registry = SimpleTestOptions::_getRegistry(); |
|
74 | 74 | return $registry['StubBaseClass']; |
75 | 75 | } |
76 | 76 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @access public |
86 | 86 | */ |
87 | 87 | static function setMockBaseClass($mock_base) { |
88 | - $registry =SimpleTestOptions::_getRegistry(); |
|
88 | + $registry = SimpleTestOptions::_getRegistry(); |
|
89 | 89 | $registry['MockBaseClass'] = $mock_base; |
90 | 90 | } |
91 | 91 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @access public |
97 | 97 | */ |
98 | 98 | static function getMockBaseClass() { |
99 | - $registry =SimpleTestOptions::_getRegistry(); |
|
99 | + $registry = SimpleTestOptions::_getRegistry(); |
|
100 | 100 | return $registry['MockBaseClass']; |
101 | 101 | } |
102 | 102 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @access public |
111 | 111 | */ |
112 | 112 | static function addPartialMockCode($code = '') { |
113 | - $registry =SimpleTestOptions::_getRegistry(); |
|
113 | + $registry = SimpleTestOptions::_getRegistry(); |
|
114 | 114 | $registry['AdditionalPartialMockCode'] = $code; |
115 | 115 | } |
116 | 116 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * @access public |
121 | 121 | */ |
122 | 122 | function getPartialMockCode() { |
123 | - $registry =SimpleTestOptions::_getRegistry(); |
|
123 | + $registry = SimpleTestOptions::_getRegistry(); |
|
124 | 124 | return $registry['AdditionalPartialMockCode']; |
125 | 125 | } |
126 | 126 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @access public |
136 | 136 | */ |
137 | 137 | static function useProxy($proxy, $username = false, $password = false) { |
138 | - $registry =SimpleTestOptions::_getRegistry(); |
|
138 | + $registry = SimpleTestOptions::_getRegistry(); |
|
139 | 139 | $registry['DefaultProxy'] = $proxy; |
140 | 140 | $registry['DefaultProxyUsername'] = $username; |
141 | 141 | $registry['DefaultProxyPassword'] = $password; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * @access public |
148 | 148 | */ |
149 | 149 | function getDefaultProxy() { |
150 | - $registry =SimpleTestOptions::_getRegistry(); |
|
150 | + $registry = SimpleTestOptions::_getRegistry(); |
|
151 | 151 | return $registry['DefaultProxy']; |
152 | 152 | } |
153 | 153 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @access public |
158 | 158 | */ |
159 | 159 | function getDefaultProxyUsername() { |
160 | - $registry =SimpleTestOptions::_getRegistry(); |
|
160 | + $registry = SimpleTestOptions::_getRegistry(); |
|
161 | 161 | return $registry['DefaultProxyUsername']; |
162 | 162 | } |
163 | 163 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @access public |
168 | 168 | */ |
169 | 169 | function getDefaultProxyPassword() { |
170 | - $registry =SimpleTestOptions::_getRegistry(); |
|
170 | + $registry = SimpleTestOptions::_getRegistry(); |
|
171 | 171 | return $registry['DefaultProxyPassword']; |
172 | 172 | } |
173 | 173 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | static function _getRegistry() { |
181 | 181 | static $registry = false; |
182 | - if (! $registry) { |
|
182 | + if (!$registry) { |
|
183 | 183 | $registry = SimpleTestOptions::_getDefaults(); |
184 | 184 | } |
185 | 185 | return $registry; |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | $is_identical = SimpleTestCompatibility::_isIdenticalType( |
270 | 270 | $first[$key], |
271 | 271 | $second[$key]); |
272 | - if (! $is_identical) { |
|
272 | + if (!$is_identical) { |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | } |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | */ |
306 | 306 | static function isA($object, $class) { |
307 | 307 | if (version_compare(phpversion(), '5') >= 0) { |
308 | - if (! class_exists($class, false)) { |
|
308 | + if (!class_exists($class, false)) { |
|
309 | 309 | return false; |
310 | 310 | } |
311 | 311 | eval("\$is_a = \$object instanceof $class;"); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | /** |
144 | 144 | * Reads the raw content and send events |
145 | 145 | * into the page to be built. |
146 | - * @param $response SimpleHttpResponse Fetched response. |
|
146 | + * @param SimpleHttpResponse $response SimpleHttpResponse Fetched response. |
|
147 | 147 | * @return SimplePage Newly parsed page. |
148 | 148 | * @access public |
149 | 149 | */ |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | |
169 | 169 | /** |
170 | 170 | * Creates the parser used with the builder. |
171 | - * @param $listener SimpleSaxListener Target of parser. |
|
172 | - * @return SimpleSaxParser Parser to generate |
|
171 | + * @param SimplePageBuilder $listener SimpleSaxListener Target of parser. |
|
172 | + * @return SimpleHtmlSaxParser Parser to generate |
|
173 | 173 | * events for the builder. |
174 | 174 | * @access protected |
175 | 175 | */ |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | |
404 | 404 | /** |
405 | 405 | * Original request as bytes sent down the wire. |
406 | - * @return mixed Sent content. |
|
406 | + * @return string|false Sent content. |
|
407 | 407 | * @access public |
408 | 408 | */ |
409 | 409 | function getRequest() { |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | |
413 | 413 | /** |
414 | 414 | * Accessor for raw text of page. |
415 | - * @return string Raw unparsed content. |
|
415 | + * @return boolean Raw unparsed content. |
|
416 | 416 | * @access public |
417 | 417 | */ |
418 | 418 | function getRaw() { |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | /** |
645 | 645 | * Opens a frameset. A frameset may contain nested |
646 | 646 | * frameset tags. |
647 | - * @param SimpleFramesetTag $tag Tag to accept. |
|
647 | + * @param SimpleTag $tag Tag to accept. |
|
648 | 648 | * @access public |
649 | 649 | */ |
650 | 650 | function acceptFramesetStart($tag) { |
@@ -1,974 +1,974 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * Base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage WebTester |
|
6 | - * @version $Id: page.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | - */ |
|
8 | - |
|
9 | - /**#@+ |
|
2 | + /** |
|
3 | + * Base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage WebTester |
|
6 | + * @version $Id: page.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | + */ |
|
8 | + |
|
9 | + /**#@+ |
|
10 | 10 | * include other SimpleTest class files |
11 | 11 | */ |
12 | - require_once(dirname(__FILE__) . '/http.php'); |
|
13 | - require_once(dirname(__FILE__) . '/parser.php'); |
|
14 | - require_once(dirname(__FILE__) . '/tag.php'); |
|
15 | - require_once(dirname(__FILE__) . '/form.php'); |
|
16 | - require_once(dirname(__FILE__) . '/selector.php'); |
|
17 | - /**#@-*/ |
|
18 | - |
|
19 | - /** |
|
20 | - * Creates tags and widgets given HTML tag |
|
21 | - * attributes. |
|
12 | + require_once(dirname(__FILE__) . '/http.php'); |
|
13 | + require_once(dirname(__FILE__) . '/parser.php'); |
|
14 | + require_once(dirname(__FILE__) . '/tag.php'); |
|
15 | + require_once(dirname(__FILE__) . '/form.php'); |
|
16 | + require_once(dirname(__FILE__) . '/selector.php'); |
|
17 | + /**#@-*/ |
|
18 | + |
|
19 | + /** |
|
20 | + * Creates tags and widgets given HTML tag |
|
21 | + * attributes. |
|
22 | 22 | * @package SimpleTest |
23 | 23 | * @subpackage WebTester |
24 | - */ |
|
25 | - class SimpleTagBuilder { |
|
26 | - |
|
27 | - /** |
|
28 | - * Factory for the tag objects. Creates the |
|
29 | - * appropriate tag object for the incoming tag name |
|
30 | - * and attributes. |
|
31 | - * @param string $name HTML tag name. |
|
32 | - * @param hash $attributes Element attributes. |
|
33 | - * @return SimpleTag Tag object. |
|
34 | - * @access public |
|
35 | - */ |
|
36 | - function createTag($name, $attributes) { |
|
37 | - static $map = array( |
|
38 | - 'a' => 'SimpleAnchorTag', |
|
39 | - 'title' => 'SimpleTitleTag', |
|
40 | - 'button' => 'SimpleButtonTag', |
|
41 | - 'textarea' => 'SimpleTextAreaTag', |
|
42 | - 'option' => 'SimpleOptionTag', |
|
43 | - 'label' => 'SimpleLabelTag', |
|
44 | - 'form' => 'SimpleFormTag', |
|
45 | - 'frame' => 'SimpleFrameTag'); |
|
46 | - $attributes = $this->_keysToLowerCase($attributes); |
|
47 | - if (array_key_exists($name, $map)) { |
|
48 | - $tag_class = $map[$name]; |
|
49 | - return new $tag_class($attributes); |
|
50 | - } elseif ($name == 'select') { |
|
51 | - return $this->_createSelectionTag($attributes); |
|
52 | - } elseif ($name == 'input') { |
|
53 | - return $this->_createInputTag($attributes); |
|
54 | - } |
|
55 | - return new SimpleTag($name, $attributes); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Factory for selection fields. |
|
60 | - * @param hash $attributes Element attributes. |
|
61 | - * @return SimpleTag Tag object. |
|
62 | - * @access protected |
|
63 | - */ |
|
64 | - function _createSelectionTag($attributes) { |
|
65 | - if (isset($attributes['multiple'])) { |
|
66 | - return new MultipleSelectionTag($attributes); |
|
67 | - } |
|
68 | - return new SimpleSelectionTag($attributes); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Factory for input tags. |
|
73 | - * @param hash $attributes Element attributes. |
|
74 | - * @return SimpleTag Tag object. |
|
75 | - * @access protected |
|
76 | - */ |
|
77 | - function _createInputTag($attributes) { |
|
78 | - if (! isset($attributes['type'])) { |
|
79 | - return new SimpleTextTag($attributes); |
|
80 | - } |
|
81 | - $type = strtolower(trim($attributes['type'])); |
|
82 | - $map = array( |
|
83 | - 'submit' => 'SimpleSubmitTag', |
|
84 | - 'image' => 'SimpleImageSubmitTag', |
|
85 | - 'checkbox' => 'SimpleCheckboxTag', |
|
86 | - 'radio' => 'SimpleRadioButtonTag', |
|
87 | - 'text' => 'SimpleTextTag', |
|
88 | - 'hidden' => 'SimpleTextTag', |
|
89 | - 'password' => 'SimpleTextTag', |
|
90 | - 'file' => 'SimpleUploadTag'); |
|
91 | - if (array_key_exists($type, $map)) { |
|
92 | - $tag_class = $map[$type]; |
|
93 | - return new $tag_class($attributes); |
|
94 | - } |
|
95 | - return false; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Make the keys lower case for case insensitive look-ups. |
|
100 | - * @param hash $map Hash to convert. |
|
101 | - * @return hash Unchanged values, but keys lower case. |
|
102 | - * @access private |
|
103 | - */ |
|
104 | - function _keysToLowerCase($map) { |
|
105 | - $lower = array(); |
|
106 | - foreach ($map as $key => $value) { |
|
107 | - $lower[strtolower($key)] = $value; |
|
108 | - } |
|
109 | - return $lower; |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * SAX event handler. Maintains a list of |
|
115 | - * open tags and dispatches them as they close. |
|
24 | + */ |
|
25 | + class SimpleTagBuilder { |
|
26 | + |
|
27 | + /** |
|
28 | + * Factory for the tag objects. Creates the |
|
29 | + * appropriate tag object for the incoming tag name |
|
30 | + * and attributes. |
|
31 | + * @param string $name HTML tag name. |
|
32 | + * @param hash $attributes Element attributes. |
|
33 | + * @return SimpleTag Tag object. |
|
34 | + * @access public |
|
35 | + */ |
|
36 | + function createTag($name, $attributes) { |
|
37 | + static $map = array( |
|
38 | + 'a' => 'SimpleAnchorTag', |
|
39 | + 'title' => 'SimpleTitleTag', |
|
40 | + 'button' => 'SimpleButtonTag', |
|
41 | + 'textarea' => 'SimpleTextAreaTag', |
|
42 | + 'option' => 'SimpleOptionTag', |
|
43 | + 'label' => 'SimpleLabelTag', |
|
44 | + 'form' => 'SimpleFormTag', |
|
45 | + 'frame' => 'SimpleFrameTag'); |
|
46 | + $attributes = $this->_keysToLowerCase($attributes); |
|
47 | + if (array_key_exists($name, $map)) { |
|
48 | + $tag_class = $map[$name]; |
|
49 | + return new $tag_class($attributes); |
|
50 | + } elseif ($name == 'select') { |
|
51 | + return $this->_createSelectionTag($attributes); |
|
52 | + } elseif ($name == 'input') { |
|
53 | + return $this->_createInputTag($attributes); |
|
54 | + } |
|
55 | + return new SimpleTag($name, $attributes); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Factory for selection fields. |
|
60 | + * @param hash $attributes Element attributes. |
|
61 | + * @return SimpleTag Tag object. |
|
62 | + * @access protected |
|
63 | + */ |
|
64 | + function _createSelectionTag($attributes) { |
|
65 | + if (isset($attributes['multiple'])) { |
|
66 | + return new MultipleSelectionTag($attributes); |
|
67 | + } |
|
68 | + return new SimpleSelectionTag($attributes); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Factory for input tags. |
|
73 | + * @param hash $attributes Element attributes. |
|
74 | + * @return SimpleTag Tag object. |
|
75 | + * @access protected |
|
76 | + */ |
|
77 | + function _createInputTag($attributes) { |
|
78 | + if (! isset($attributes['type'])) { |
|
79 | + return new SimpleTextTag($attributes); |
|
80 | + } |
|
81 | + $type = strtolower(trim($attributes['type'])); |
|
82 | + $map = array( |
|
83 | + 'submit' => 'SimpleSubmitTag', |
|
84 | + 'image' => 'SimpleImageSubmitTag', |
|
85 | + 'checkbox' => 'SimpleCheckboxTag', |
|
86 | + 'radio' => 'SimpleRadioButtonTag', |
|
87 | + 'text' => 'SimpleTextTag', |
|
88 | + 'hidden' => 'SimpleTextTag', |
|
89 | + 'password' => 'SimpleTextTag', |
|
90 | + 'file' => 'SimpleUploadTag'); |
|
91 | + if (array_key_exists($type, $map)) { |
|
92 | + $tag_class = $map[$type]; |
|
93 | + return new $tag_class($attributes); |
|
94 | + } |
|
95 | + return false; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Make the keys lower case for case insensitive look-ups. |
|
100 | + * @param hash $map Hash to convert. |
|
101 | + * @return hash Unchanged values, but keys lower case. |
|
102 | + * @access private |
|
103 | + */ |
|
104 | + function _keysToLowerCase($map) { |
|
105 | + $lower = array(); |
|
106 | + foreach ($map as $key => $value) { |
|
107 | + $lower[strtolower($key)] = $value; |
|
108 | + } |
|
109 | + return $lower; |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * SAX event handler. Maintains a list of |
|
115 | + * open tags and dispatches them as they close. |
|
116 | 116 | * @package SimpleTest |
117 | 117 | * @subpackage WebTester |
118 | - */ |
|
119 | - class SimplePageBuilder extends SimpleSaxListener { |
|
120 | - protected $_tags; |
|
121 | - protected $_page; |
|
122 | - protected $_private_content_tag; |
|
123 | - |
|
124 | - /** |
|
125 | - * Sets the builder up empty. |
|
126 | - * @access public |
|
127 | - */ |
|
128 | - function SimplePageBuilder() { |
|
129 | - $this->SimpleSaxListener(); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Frees up any references so as to allow the PHP garbage |
|
134 | - * collection from unset() to work. |
|
135 | - * @access public |
|
136 | - */ |
|
137 | - function free() { |
|
138 | - unset($this->_tags); |
|
139 | - unset($this->_page); |
|
140 | - unset($this->_private_content_tags); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Reads the raw content and send events |
|
145 | - * into the page to be built. |
|
146 | - * @param $response SimpleHttpResponse Fetched response. |
|
147 | - * @return SimplePage Newly parsed page. |
|
148 | - * @access public |
|
149 | - */ |
|
150 | - function &parse($response) { |
|
151 | - $this->_tags = array(); |
|
152 | - $this->_page = $this->_createPage($response); |
|
153 | - $parser = $this->_createParser($this); |
|
154 | - $parser->parse($response->getContent()); |
|
155 | - $this->_page->acceptPageEnd(); |
|
156 | - return $this->_page; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Creates an empty page. |
|
161 | - * @return SimplePage New unparsed page. |
|
162 | - * @access protected |
|
163 | - */ |
|
164 | - function &_createPage($response) { |
|
165 | - $page = new SimplePage($response); |
|
166 | - return $page; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Creates the parser used with the builder. |
|
171 | - * @param $listener SimpleSaxListener Target of parser. |
|
172 | - * @return SimpleSaxParser Parser to generate |
|
173 | - * events for the builder. |
|
174 | - * @access protected |
|
175 | - */ |
|
176 | - function &_createParser($listener) { |
|
177 | - $parser = new SimpleHtmlSaxParser($listener); |
|
178 | - return $parser; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Start of element event. Opens a new tag. |
|
183 | - * @param string $name Element name. |
|
184 | - * @param hash $attributes Attributes without content |
|
185 | - * are marked as true. |
|
186 | - * @return boolean False on parse error. |
|
187 | - * @access public |
|
188 | - */ |
|
189 | - function startElement($name, $attributes) { |
|
190 | - $factory = new SimpleTagBuilder(); |
|
191 | - $tag = $factory->createTag($name, $attributes); |
|
192 | - if (! $tag) { |
|
193 | - return true; |
|
194 | - } |
|
195 | - if ($tag->getTagName() == 'label') { |
|
196 | - $this->_page->acceptLabelStart($tag); |
|
197 | - $this->_openTag($tag); |
|
198 | - return true; |
|
199 | - } |
|
200 | - if ($tag->getTagName() == 'form') { |
|
201 | - $this->_page->acceptFormStart($tag); |
|
202 | - return true; |
|
203 | - } |
|
204 | - if ($tag->getTagName() == 'frameset') { |
|
205 | - $this->_page->acceptFramesetStart($tag); |
|
206 | - return true; |
|
207 | - } |
|
208 | - if ($tag->getTagName() == 'frame') { |
|
209 | - $this->_page->acceptFrame($tag); |
|
210 | - return true; |
|
211 | - } |
|
212 | - if ($tag->isPrivateContent() && ! isset($this->_private_content_tag)) { |
|
213 | - $this->_private_content_tag = $tag; |
|
214 | - } |
|
215 | - if ($tag->expectEndTag()) { |
|
216 | - $this->_openTag($tag); |
|
217 | - return true; |
|
218 | - } |
|
219 | - $this->_page->acceptTag($tag); |
|
220 | - return true; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * End of element event. |
|
225 | - * @param string $name Element name. |
|
226 | - * @return boolean False on parse error. |
|
227 | - * @access public |
|
228 | - */ |
|
229 | - function endElement($name) { |
|
230 | - if ($name == 'label') { |
|
231 | - $this->_page->acceptLabelEnd(); |
|
232 | - return true; |
|
233 | - } |
|
234 | - if ($name == 'form') { |
|
235 | - $this->_page->acceptFormEnd(); |
|
236 | - return true; |
|
237 | - } |
|
238 | - if ($name == 'frameset') { |
|
239 | - $this->_page->acceptFramesetEnd(); |
|
240 | - return true; |
|
241 | - } |
|
242 | - if ($this->_hasNamedTagOnOpenTagStack($name)) { |
|
243 | - $tag = array_pop($this->_tags[$name]); |
|
244 | - if ($tag->isPrivateContent() && $this->_private_content_tag->getTagName() == $name) { |
|
245 | - unset($this->_private_content_tag); |
|
246 | - } |
|
247 | - $this->_addContentTagToOpenTags($tag); |
|
248 | - $this->_page->acceptTag($tag); |
|
249 | - return true; |
|
250 | - } |
|
251 | - return true; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Test to see if there are any open tags awaiting |
|
256 | - * closure that match the tag name. |
|
257 | - * @param string $name Element name. |
|
258 | - * @return boolean True if any are still open. |
|
259 | - * @access private |
|
260 | - */ |
|
261 | - function _hasNamedTagOnOpenTagStack($name) { |
|
262 | - return isset($this->_tags[$name]) && (count($this->_tags[$name]) > 0); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Unparsed, but relevant data. The data is added |
|
267 | - * to every open tag. |
|
268 | - * @param string $text May include unparsed tags. |
|
269 | - * @return boolean False on parse error. |
|
270 | - * @access public |
|
271 | - */ |
|
272 | - function addContent($text) { |
|
273 | - if (isset($this->_private_content_tag)) { |
|
274 | - $this->_private_content_tag->addContent($text); |
|
275 | - } else { |
|
276 | - $this->_addContentToAllOpenTags($text); |
|
277 | - } |
|
278 | - return true; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Any content fills all currently open tags unless it |
|
283 | - * is part of an option tag. |
|
284 | - * @param string $text May include unparsed tags. |
|
285 | - * @access private |
|
286 | - */ |
|
287 | - function _addContentToAllOpenTags($text) { |
|
288 | - foreach (array_keys($this->_tags) as $name) { |
|
289 | - for ($i = 0, $count = count($this->_tags[$name]); $i < $count; $i++) { |
|
290 | - $this->_tags[$name][$i]->addContent($text); |
|
291 | - } |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Parsed data in tag form. The parsed tag is added |
|
297 | - * to every open tag. Used for adding options to select |
|
298 | - * fields only. |
|
299 | - * @param SimpleTag $tag Option tags only. |
|
300 | - * @access private |
|
301 | - */ |
|
302 | - function _addContentTagToOpenTags($tag) { |
|
303 | - if ($tag->getTagName() != 'option') { |
|
304 | - return; |
|
305 | - } |
|
306 | - foreach (array_keys($this->_tags) as $name) { |
|
307 | - for ($i = 0, $count = count($this->_tags[$name]); $i < $count; $i++) { |
|
308 | - $this->_tags[$name][$i]->addTag($tag); |
|
309 | - } |
|
310 | - } |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Opens a tag for receiving content. Multiple tags |
|
315 | - * will be receiving input at the same time. |
|
316 | - * @param SimpleTag $tag New content tag. |
|
317 | - * @access private |
|
318 | - */ |
|
319 | - function _openTag($tag) { |
|
320 | - $name = $tag->getTagName(); |
|
321 | - if (! in_array($name, array_keys($this->_tags))) { |
|
322 | - $this->_tags[$name] = array(); |
|
323 | - } |
|
324 | - $this->_tags[$name][] = $tag; |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * A wrapper for a web page. |
|
118 | + */ |
|
119 | + class SimplePageBuilder extends SimpleSaxListener { |
|
120 | + protected $_tags; |
|
121 | + protected $_page; |
|
122 | + protected $_private_content_tag; |
|
123 | + |
|
124 | + /** |
|
125 | + * Sets the builder up empty. |
|
126 | + * @access public |
|
127 | + */ |
|
128 | + function SimplePageBuilder() { |
|
129 | + $this->SimpleSaxListener(); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Frees up any references so as to allow the PHP garbage |
|
134 | + * collection from unset() to work. |
|
135 | + * @access public |
|
136 | + */ |
|
137 | + function free() { |
|
138 | + unset($this->_tags); |
|
139 | + unset($this->_page); |
|
140 | + unset($this->_private_content_tags); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Reads the raw content and send events |
|
145 | + * into the page to be built. |
|
146 | + * @param $response SimpleHttpResponse Fetched response. |
|
147 | + * @return SimplePage Newly parsed page. |
|
148 | + * @access public |
|
149 | + */ |
|
150 | + function &parse($response) { |
|
151 | + $this->_tags = array(); |
|
152 | + $this->_page = $this->_createPage($response); |
|
153 | + $parser = $this->_createParser($this); |
|
154 | + $parser->parse($response->getContent()); |
|
155 | + $this->_page->acceptPageEnd(); |
|
156 | + return $this->_page; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Creates an empty page. |
|
161 | + * @return SimplePage New unparsed page. |
|
162 | + * @access protected |
|
163 | + */ |
|
164 | + function &_createPage($response) { |
|
165 | + $page = new SimplePage($response); |
|
166 | + return $page; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Creates the parser used with the builder. |
|
171 | + * @param $listener SimpleSaxListener Target of parser. |
|
172 | + * @return SimpleSaxParser Parser to generate |
|
173 | + * events for the builder. |
|
174 | + * @access protected |
|
175 | + */ |
|
176 | + function &_createParser($listener) { |
|
177 | + $parser = new SimpleHtmlSaxParser($listener); |
|
178 | + return $parser; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Start of element event. Opens a new tag. |
|
183 | + * @param string $name Element name. |
|
184 | + * @param hash $attributes Attributes without content |
|
185 | + * are marked as true. |
|
186 | + * @return boolean False on parse error. |
|
187 | + * @access public |
|
188 | + */ |
|
189 | + function startElement($name, $attributes) { |
|
190 | + $factory = new SimpleTagBuilder(); |
|
191 | + $tag = $factory->createTag($name, $attributes); |
|
192 | + if (! $tag) { |
|
193 | + return true; |
|
194 | + } |
|
195 | + if ($tag->getTagName() == 'label') { |
|
196 | + $this->_page->acceptLabelStart($tag); |
|
197 | + $this->_openTag($tag); |
|
198 | + return true; |
|
199 | + } |
|
200 | + if ($tag->getTagName() == 'form') { |
|
201 | + $this->_page->acceptFormStart($tag); |
|
202 | + return true; |
|
203 | + } |
|
204 | + if ($tag->getTagName() == 'frameset') { |
|
205 | + $this->_page->acceptFramesetStart($tag); |
|
206 | + return true; |
|
207 | + } |
|
208 | + if ($tag->getTagName() == 'frame') { |
|
209 | + $this->_page->acceptFrame($tag); |
|
210 | + return true; |
|
211 | + } |
|
212 | + if ($tag->isPrivateContent() && ! isset($this->_private_content_tag)) { |
|
213 | + $this->_private_content_tag = $tag; |
|
214 | + } |
|
215 | + if ($tag->expectEndTag()) { |
|
216 | + $this->_openTag($tag); |
|
217 | + return true; |
|
218 | + } |
|
219 | + $this->_page->acceptTag($tag); |
|
220 | + return true; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * End of element event. |
|
225 | + * @param string $name Element name. |
|
226 | + * @return boolean False on parse error. |
|
227 | + * @access public |
|
228 | + */ |
|
229 | + function endElement($name) { |
|
230 | + if ($name == 'label') { |
|
231 | + $this->_page->acceptLabelEnd(); |
|
232 | + return true; |
|
233 | + } |
|
234 | + if ($name == 'form') { |
|
235 | + $this->_page->acceptFormEnd(); |
|
236 | + return true; |
|
237 | + } |
|
238 | + if ($name == 'frameset') { |
|
239 | + $this->_page->acceptFramesetEnd(); |
|
240 | + return true; |
|
241 | + } |
|
242 | + if ($this->_hasNamedTagOnOpenTagStack($name)) { |
|
243 | + $tag = array_pop($this->_tags[$name]); |
|
244 | + if ($tag->isPrivateContent() && $this->_private_content_tag->getTagName() == $name) { |
|
245 | + unset($this->_private_content_tag); |
|
246 | + } |
|
247 | + $this->_addContentTagToOpenTags($tag); |
|
248 | + $this->_page->acceptTag($tag); |
|
249 | + return true; |
|
250 | + } |
|
251 | + return true; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Test to see if there are any open tags awaiting |
|
256 | + * closure that match the tag name. |
|
257 | + * @param string $name Element name. |
|
258 | + * @return boolean True if any are still open. |
|
259 | + * @access private |
|
260 | + */ |
|
261 | + function _hasNamedTagOnOpenTagStack($name) { |
|
262 | + return isset($this->_tags[$name]) && (count($this->_tags[$name]) > 0); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Unparsed, but relevant data. The data is added |
|
267 | + * to every open tag. |
|
268 | + * @param string $text May include unparsed tags. |
|
269 | + * @return boolean False on parse error. |
|
270 | + * @access public |
|
271 | + */ |
|
272 | + function addContent($text) { |
|
273 | + if (isset($this->_private_content_tag)) { |
|
274 | + $this->_private_content_tag->addContent($text); |
|
275 | + } else { |
|
276 | + $this->_addContentToAllOpenTags($text); |
|
277 | + } |
|
278 | + return true; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Any content fills all currently open tags unless it |
|
283 | + * is part of an option tag. |
|
284 | + * @param string $text May include unparsed tags. |
|
285 | + * @access private |
|
286 | + */ |
|
287 | + function _addContentToAllOpenTags($text) { |
|
288 | + foreach (array_keys($this->_tags) as $name) { |
|
289 | + for ($i = 0, $count = count($this->_tags[$name]); $i < $count; $i++) { |
|
290 | + $this->_tags[$name][$i]->addContent($text); |
|
291 | + } |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Parsed data in tag form. The parsed tag is added |
|
297 | + * to every open tag. Used for adding options to select |
|
298 | + * fields only. |
|
299 | + * @param SimpleTag $tag Option tags only. |
|
300 | + * @access private |
|
301 | + */ |
|
302 | + function _addContentTagToOpenTags($tag) { |
|
303 | + if ($tag->getTagName() != 'option') { |
|
304 | + return; |
|
305 | + } |
|
306 | + foreach (array_keys($this->_tags) as $name) { |
|
307 | + for ($i = 0, $count = count($this->_tags[$name]); $i < $count; $i++) { |
|
308 | + $this->_tags[$name][$i]->addTag($tag); |
|
309 | + } |
|
310 | + } |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Opens a tag for receiving content. Multiple tags |
|
315 | + * will be receiving input at the same time. |
|
316 | + * @param SimpleTag $tag New content tag. |
|
317 | + * @access private |
|
318 | + */ |
|
319 | + function _openTag($tag) { |
|
320 | + $name = $tag->getTagName(); |
|
321 | + if (! in_array($name, array_keys($this->_tags))) { |
|
322 | + $this->_tags[$name] = array(); |
|
323 | + } |
|
324 | + $this->_tags[$name][] = $tag; |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * A wrapper for a web page. |
|
330 | 330 | * @package SimpleTest |
331 | 331 | * @subpackage WebTester |
332 | - */ |
|
333 | - class SimplePage { |
|
334 | - protected $_links; |
|
335 | - protected $_title; |
|
336 | - protected $_last_widget; |
|
337 | - protected $_label; |
|
338 | - protected $_left_over_labels; |
|
339 | - protected $_open_forms; |
|
340 | - protected $_complete_forms; |
|
341 | - protected $_frameset; |
|
342 | - protected $_frames; |
|
343 | - protected $_frameset_nesting_level; |
|
344 | - protected $_transport_error; |
|
345 | - protected $_raw; |
|
346 | - protected $_text; |
|
347 | - protected $_sent; |
|
348 | - protected $_headers; |
|
349 | - protected $_method; |
|
350 | - protected $_url; |
|
351 | - protected $_request_data; |
|
352 | - |
|
353 | - /** |
|
354 | - * Parses a page ready to access it's contents. |
|
355 | - * @param SimpleHttpResponse $response Result of HTTP fetch. |
|
356 | - * @access public |
|
357 | - */ |
|
358 | - function SimplePage($response = false) { |
|
359 | - $this->_links = array(); |
|
360 | - $this->_title = false; |
|
361 | - $this->_left_over_labels = array(); |
|
362 | - $this->_open_forms = array(); |
|
363 | - $this->_complete_forms = array(); |
|
364 | - $this->_frameset = false; |
|
365 | - $this->_frames = array(); |
|
366 | - $this->_frameset_nesting_level = 0; |
|
367 | - $this->_text = false; |
|
368 | - if ($response) { |
|
369 | - $this->_extractResponse($response); |
|
370 | - } else { |
|
371 | - $this->_noResponse(); |
|
372 | - } |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Extracts all of the response information. |
|
377 | - * @param SimpleHttpResponse $response Response being parsed. |
|
378 | - * @access private |
|
379 | - */ |
|
380 | - function _extractResponse($response) { |
|
381 | - $this->_transport_error = $response->getError(); |
|
382 | - $this->_raw = $response->getContent(); |
|
383 | - $this->_sent = $response->getSent(); |
|
384 | - $this->_headers = $response->getHeaders(); |
|
385 | - $this->_method = $response->getMethod(); |
|
386 | - $this->_url = $response->getUrl(); |
|
387 | - $this->_request_data = $response->getRequestData(); |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Sets up a missing response. |
|
392 | - * @access private |
|
393 | - */ |
|
394 | - function _noResponse() { |
|
395 | - $this->_transport_error = 'No page fetched yet'; |
|
396 | - $this->_raw = false; |
|
397 | - $this->_sent = false; |
|
398 | - $this->_headers = false; |
|
399 | - $this->_method = 'GET'; |
|
400 | - $this->_url = false; |
|
401 | - $this->_request_data = false; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Original request as bytes sent down the wire. |
|
406 | - * @return mixed Sent content. |
|
407 | - * @access public |
|
408 | - */ |
|
409 | - function getRequest() { |
|
410 | - return $this->_sent; |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * Accessor for raw text of page. |
|
415 | - * @return string Raw unparsed content. |
|
416 | - * @access public |
|
417 | - */ |
|
418 | - function getRaw() { |
|
419 | - return $this->_raw; |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Accessor for plain text of page as a text browser |
|
424 | - * would see it. |
|
425 | - * @return string Plain text of page. |
|
426 | - * @access public |
|
427 | - */ |
|
428 | - function getText() { |
|
429 | - if (! $this->_text) { |
|
430 | - $this->_text = SimpleHtmlSaxParser::normalise($this->_raw); |
|
431 | - } |
|
432 | - return $this->_text; |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * Accessor for raw headers of page. |
|
437 | - * @return string Header block as text. |
|
438 | - * @access public |
|
439 | - */ |
|
440 | - function getHeaders() { |
|
441 | - if ($this->_headers) { |
|
442 | - return $this->_headers->getRaw(); |
|
443 | - } |
|
444 | - return false; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Original request method. |
|
449 | - * @return string GET, POST or HEAD. |
|
450 | - * @access public |
|
451 | - */ |
|
452 | - function getMethod() { |
|
453 | - return $this->_method; |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Original resource name. |
|
458 | - * @return SimpleUrl Current url. |
|
459 | - * @access public |
|
460 | - */ |
|
461 | - function getUrl() { |
|
462 | - return $this->_url; |
|
463 | - } |
|
464 | - |
|
465 | - /** |
|
466 | - * Original request data. |
|
467 | - * @return mixed Sent content. |
|
468 | - * @access public |
|
469 | - */ |
|
470 | - function getRequestData() { |
|
471 | - return $this->_request_data; |
|
472 | - } |
|
473 | - |
|
474 | - /** |
|
475 | - * Accessor for last error. |
|
476 | - * @return string Error from last response. |
|
477 | - * @access public |
|
478 | - */ |
|
479 | - function getTransportError() { |
|
480 | - return $this->_transport_error; |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Accessor for current MIME type. |
|
485 | - * @return string MIME type as string; e.g. 'text/html' |
|
486 | - * @access public |
|
487 | - */ |
|
488 | - function getMimeType() { |
|
489 | - if ($this->_headers) { |
|
490 | - return $this->_headers->getMimeType(); |
|
491 | - } |
|
492 | - return false; |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * Accessor for HTTP response code. |
|
497 | - * @return integer HTTP response code received. |
|
498 | - * @access public |
|
499 | - */ |
|
500 | - function getResponseCode() { |
|
501 | - if ($this->_headers) { |
|
502 | - return $this->_headers->getResponseCode(); |
|
503 | - } |
|
504 | - return false; |
|
505 | - } |
|
506 | - |
|
507 | - /** |
|
508 | - * Accessor for last Authentication type. Only valid |
|
509 | - * straight after a challenge (401). |
|
510 | - * @return string Description of challenge type. |
|
511 | - * @access public |
|
512 | - */ |
|
513 | - function getAuthentication() { |
|
514 | - if ($this->_headers) { |
|
515 | - return $this->_headers->getAuthentication(); |
|
516 | - } |
|
517 | - return false; |
|
518 | - } |
|
519 | - |
|
520 | - /** |
|
521 | - * Accessor for last Authentication realm. Only valid |
|
522 | - * straight after a challenge (401). |
|
523 | - * @return string Name of security realm. |
|
524 | - * @access public |
|
525 | - */ |
|
526 | - function getRealm() { |
|
527 | - if ($this->_headers) { |
|
528 | - return $this->_headers->getRealm(); |
|
529 | - } |
|
530 | - return false; |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Accessor for current frame focus. Will be |
|
535 | - * false as no frames. |
|
536 | - * @return array Always empty. |
|
537 | - * @access public |
|
538 | - */ |
|
539 | - function getFrameFocus() { |
|
540 | - return array(); |
|
541 | - } |
|
542 | - |
|
543 | - /** |
|
544 | - * Sets the focus by index. The integer index starts from 1. |
|
545 | - * @param integer $choice Chosen frame. |
|
546 | - * @return boolean Always false. |
|
547 | - * @access public |
|
548 | - */ |
|
549 | - function setFrameFocusByIndex($choice) { |
|
550 | - return false; |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Sets the focus by name. Always fails for a leaf page. |
|
555 | - * @param string $name Chosen frame. |
|
556 | - * @return boolean False as no frames. |
|
557 | - * @access public |
|
558 | - */ |
|
559 | - function setFrameFocus($name) { |
|
560 | - return false; |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Clears the frame focus. Does nothing for a leaf page. |
|
565 | - * @access public |
|
566 | - */ |
|
567 | - function clearFrameFocus() { |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Adds a tag to the page. |
|
572 | - * @param SimpleTag $tag Tag to accept. |
|
573 | - * @access public |
|
574 | - */ |
|
575 | - function acceptTag($tag) { |
|
576 | - if ($tag->getTagName() == "a") { |
|
577 | - $this->_addLink($tag); |
|
578 | - } elseif ($tag->getTagName() == "title") { |
|
579 | - $this->_setTitle($tag); |
|
580 | - } elseif ($this->_isFormElement($tag->getTagName())) { |
|
581 | - for ($i = 0; $i < count($this->_open_forms); $i++) { |
|
582 | - $this->_open_forms[$i]->addWidget($tag); |
|
583 | - } |
|
584 | - $this->_last_widget = $tag; |
|
585 | - } |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Opens a label for a described widget. |
|
590 | - * @param SimpleFormTag $tag Tag to accept. |
|
591 | - * @access public |
|
592 | - */ |
|
593 | - function acceptLabelStart($tag) { |
|
594 | - $this->_label = $tag; |
|
595 | - unset($this->_last_widget); |
|
596 | - } |
|
597 | - |
|
598 | - /** |
|
599 | - * Closes the most recently opened label. |
|
600 | - * @access public |
|
601 | - */ |
|
602 | - function acceptLabelEnd() { |
|
603 | - if (isset($this->_label)) { |
|
604 | - if (isset($this->_last_widget)) { |
|
605 | - $this->_last_widget->setLabel($this->_label->getText()); |
|
606 | - unset($this->_last_widget); |
|
607 | - } else { |
|
608 | - $this->_left_over_labels[] = SimpleTestCompatibility::copy($this->_label); |
|
609 | - } |
|
610 | - unset($this->_label); |
|
611 | - } |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Tests to see if a tag is a possible form |
|
616 | - * element. |
|
617 | - * @param string $name HTML element name. |
|
618 | - * @return boolean True if form element. |
|
619 | - * @access private |
|
620 | - */ |
|
621 | - function _isFormElement($name) { |
|
622 | - return in_array($name, array('input', 'button', 'textarea', 'select')); |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Opens a form. New widgets go here. |
|
627 | - * @param SimpleFormTag $tag Tag to accept. |
|
628 | - * @access public |
|
629 | - */ |
|
630 | - function acceptFormStart($tag) { |
|
631 | - $this->_open_forms[] = new SimpleForm($tag, $this->getUrl()); |
|
632 | - } |
|
633 | - |
|
634 | - /** |
|
635 | - * Closes the most recently opened form. |
|
636 | - * @access public |
|
637 | - */ |
|
638 | - function acceptFormEnd() { |
|
639 | - if (count($this->_open_forms)) { |
|
640 | - $this->_complete_forms[] = array_pop($this->_open_forms); |
|
641 | - } |
|
642 | - } |
|
643 | - |
|
644 | - /** |
|
645 | - * Opens a frameset. A frameset may contain nested |
|
646 | - * frameset tags. |
|
647 | - * @param SimpleFramesetTag $tag Tag to accept. |
|
648 | - * @access public |
|
649 | - */ |
|
650 | - function acceptFramesetStart($tag) { |
|
651 | - if (! $this->_isLoadingFrames()) { |
|
652 | - $this->_frameset = $tag; |
|
653 | - } |
|
654 | - $this->_frameset_nesting_level++; |
|
655 | - } |
|
656 | - |
|
657 | - /** |
|
658 | - * Closes the most recently opened frameset. |
|
659 | - * @access public |
|
660 | - */ |
|
661 | - function acceptFramesetEnd() { |
|
662 | - if ($this->_isLoadingFrames()) { |
|
663 | - $this->_frameset_nesting_level--; |
|
664 | - } |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * Takes a single frame tag and stashes it in |
|
669 | - * the current frame set. |
|
670 | - * @param SimpleFrameTag $tag Tag to accept. |
|
671 | - * @access public |
|
672 | - */ |
|
673 | - function acceptFrame($tag) { |
|
674 | - if ($this->_isLoadingFrames()) { |
|
675 | - if ($tag->getAttribute('src')) { |
|
676 | - $this->_frames[] = $tag; |
|
677 | - } |
|
678 | - } |
|
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * Test to see if in the middle of reading |
|
683 | - * a frameset. |
|
684 | - * @return boolean True if inframeset. |
|
685 | - * @access private |
|
686 | - */ |
|
687 | - function _isLoadingFrames() { |
|
688 | - if (! $this->_frameset) { |
|
689 | - return false; |
|
690 | - } |
|
691 | - return ($this->_frameset_nesting_level > 0); |
|
692 | - } |
|
693 | - |
|
694 | - /** |
|
695 | - * Test to see if link is an absolute one. |
|
696 | - * @param string $url Url to test. |
|
697 | - * @return boolean True if absolute. |
|
698 | - * @access protected |
|
699 | - */ |
|
700 | - function _linkIsAbsolute($url) { |
|
701 | - $parsed = new SimpleUrl($url); |
|
702 | - return (boolean)($parsed->getScheme() && $parsed->getHost()); |
|
703 | - } |
|
704 | - |
|
705 | - /** |
|
706 | - * Adds a link to the page. |
|
707 | - * @param SimpleAnchorTag $tag Link to accept. |
|
708 | - * @access protected |
|
709 | - */ |
|
710 | - function _addLink($tag) { |
|
711 | - $this->_links[] = $tag; |
|
712 | - } |
|
713 | - |
|
714 | - /** |
|
715 | - * Marker for end of complete page. Any work in |
|
716 | - * progress can now be closed. |
|
717 | - * @access public |
|
718 | - */ |
|
719 | - function acceptPageEnd() { |
|
720 | - while (count($this->_open_forms)) { |
|
721 | - $this->_complete_forms[] = array_pop($this->_open_forms); |
|
722 | - } |
|
723 | - foreach ($this->_left_over_labels as $label) { |
|
724 | - for ($i = 0, $count = count($this->_complete_forms); $i < $count; $i++) { |
|
725 | - $this->_complete_forms[$i]->attachLabelBySelector( |
|
726 | - new SimpleById($label->getFor()), |
|
727 | - $label->getText()); |
|
728 | - } |
|
729 | - } |
|
730 | - } |
|
731 | - |
|
732 | - /** |
|
733 | - * Test for the presence of a frameset. |
|
734 | - * @return boolean True if frameset. |
|
735 | - * @access public |
|
736 | - */ |
|
737 | - function hasFrames() { |
|
738 | - return (boolean)$this->_frameset; |
|
739 | - } |
|
740 | - |
|
741 | - /** |
|
742 | - * Accessor for frame name and source URL for every frame that |
|
743 | - * will need to be loaded. Immediate children only. |
|
744 | - * @return boolean/array False if no frameset or |
|
745 | - * otherwise a hash of frame URLs. |
|
746 | - * The key is either a numerical |
|
747 | - * base one index or the name attribute. |
|
748 | - * @access public |
|
749 | - */ |
|
750 | - function getFrameset() { |
|
751 | - if (! $this->_frameset) { |
|
752 | - return false; |
|
753 | - } |
|
754 | - $urls = array(); |
|
755 | - for ($i = 0; $i < count($this->_frames); $i++) { |
|
756 | - $name = $this->_frames[$i]->getAttribute('name'); |
|
757 | - $url = new SimpleUrl($this->_frames[$i]->getAttribute('src')); |
|
758 | - $urls[$name ? $name : $i + 1] = $url->makeAbsolute($this->getUrl()); |
|
759 | - } |
|
760 | - return $urls; |
|
761 | - } |
|
762 | - |
|
763 | - /** |
|
764 | - * Fetches a list of loaded frames. |
|
765 | - * @return array/string Just the URL for a single page. |
|
766 | - * @access public |
|
767 | - */ |
|
768 | - function getFrames() { |
|
769 | - $url = $this->getUrl(); |
|
770 | - return $url->asString(); |
|
771 | - } |
|
772 | - |
|
773 | - /** |
|
774 | - * Accessor for a list of all fixed links. |
|
775 | - * @return array List of urls with scheme of |
|
776 | - * http or https and hostname. |
|
777 | - * @access public |
|
778 | - */ |
|
779 | - function getAbsoluteUrls() { |
|
780 | - $all = array(); |
|
781 | - foreach ($this->_links as $link) { |
|
782 | - if ($this->_linkIsAbsolute($link->getHref())) { |
|
783 | - $all[] = $link->getHref(); |
|
784 | - } |
|
785 | - } |
|
786 | - return $all; |
|
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * Accessor for a list of all relative links. |
|
791 | - * @return array List of urls without hostname. |
|
792 | - * @access public |
|
793 | - */ |
|
794 | - function getRelativeUrls() { |
|
795 | - $all = array(); |
|
796 | - foreach ($this->_links as $link) { |
|
797 | - if (! $this->_linkIsAbsolute($link->getHref())) { |
|
798 | - $all[] = $link->getHref(); |
|
799 | - } |
|
800 | - } |
|
801 | - return $all; |
|
802 | - } |
|
803 | - |
|
804 | - /** |
|
805 | - * Accessor for URLs by the link label. Label will match |
|
806 | - * regardess of whitespace issues and case. |
|
807 | - * @param string $label Text of link. |
|
808 | - * @return array List of links with that label. |
|
809 | - * @access public |
|
810 | - */ |
|
811 | - function getUrlsByLabel($label) { |
|
812 | - $matches = array(); |
|
813 | - foreach ($this->_links as $link) { |
|
814 | - if ($link->getText() == $label) { |
|
815 | - $matches[] = $this->_getUrlFromLink($link); |
|
816 | - } |
|
817 | - } |
|
818 | - return $matches; |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * Accessor for a URL by the id attribute. |
|
823 | - * @param string $id Id attribute of link. |
|
824 | - * @return SimpleUrl URL with that id of false if none. |
|
825 | - * @access public |
|
826 | - */ |
|
827 | - function getUrlById($id) { |
|
828 | - foreach ($this->_links as $link) { |
|
829 | - if ($link->getAttribute('id') === (string)$id) { |
|
830 | - return $this->_getUrlFromLink($link); |
|
831 | - } |
|
832 | - } |
|
833 | - return false; |
|
834 | - } |
|
835 | - |
|
836 | - /** |
|
837 | - * Converts a link into a target URL. |
|
838 | - * @param SimpleAnchor $link Parsed link. |
|
839 | - * @return SimpleUrl URL with frame target if any. |
|
840 | - * @access private |
|
841 | - */ |
|
842 | - function _getUrlFromLink($link) { |
|
843 | - $url = $this->_makeAbsolute($link->getHref()); |
|
844 | - if ($link->getAttribute('target')) { |
|
845 | - $url->setTarget($link->getAttribute('target')); |
|
846 | - } |
|
847 | - return $url; |
|
848 | - } |
|
849 | - |
|
850 | - /** |
|
851 | - * Expands expandomatic URLs into fully qualified |
|
852 | - * URLs. |
|
853 | - * @param SimpleUrl $url Relative URL. |
|
854 | - * @return SimpleUrl Absolute URL. |
|
855 | - * @access protected |
|
856 | - */ |
|
857 | - function _makeAbsolute($url) { |
|
858 | - if (! is_object($url)) { |
|
859 | - $url = new SimpleUrl($url); |
|
860 | - } |
|
861 | - return $url->makeAbsolute($this->getUrl()); |
|
862 | - } |
|
863 | - |
|
864 | - /** |
|
865 | - * Sets the title tag contents. |
|
866 | - * @param SimpleTitleTag $tag Title of page. |
|
867 | - * @access protected |
|
868 | - */ |
|
869 | - function _setTitle($tag) { |
|
870 | - $this->_title = $tag; |
|
871 | - } |
|
872 | - |
|
873 | - /** |
|
874 | - * Accessor for parsed title. |
|
875 | - * @return string Title or false if no title is present. |
|
876 | - * @access public |
|
877 | - */ |
|
878 | - function getTitle() { |
|
879 | - if ($this->_title) { |
|
880 | - return $this->_title->getText(); |
|
881 | - } |
|
882 | - return false; |
|
883 | - } |
|
884 | - |
|
885 | - /** |
|
886 | - * Finds a held form by button label. Will only |
|
887 | - * search correctly built forms. |
|
888 | - * @param SimpleSelector $selector Button finder. |
|
889 | - * @return SimpleForm Form object containing |
|
890 | - * the button. |
|
891 | - * @access public |
|
892 | - */ |
|
893 | - function &getFormBySubmit($selector) { |
|
894 | - for ($i = 0; $i < count($this->_complete_forms); $i++) { |
|
895 | - if ($this->_complete_forms[$i]->hasSubmit($selector)) { |
|
896 | - return $this->_complete_forms[$i]; |
|
897 | - } |
|
898 | - } |
|
899 | - $null = null; |
|
900 | - return $null; |
|
901 | - } |
|
902 | - |
|
903 | - /** |
|
904 | - * Finds a held form by image using a selector. |
|
905 | - * Will only search correctly built forms. |
|
906 | - * @param SimpleSelector $selector Image finder. |
|
907 | - * @return SimpleForm Form object containing |
|
908 | - * the image. |
|
909 | - * @access public |
|
910 | - */ |
|
911 | - function &getFormByImage($selector) { |
|
912 | - for ($i = 0; $i < count($this->_complete_forms); $i++) { |
|
913 | - if ($this->_complete_forms[$i]->hasImage($selector)) { |
|
914 | - return $this->_complete_forms[$i]; |
|
915 | - } |
|
916 | - } |
|
917 | - $null = null; |
|
918 | - return $null; |
|
919 | - } |
|
920 | - |
|
921 | - /** |
|
922 | - * Finds a held form by the form ID. A way of |
|
923 | - * identifying a specific form when we have control |
|
924 | - * of the HTML code. |
|
925 | - * @param string $id Form label. |
|
926 | - * @return SimpleForm Form object containing the matching ID. |
|
927 | - * @access public |
|
928 | - */ |
|
929 | - function &getFormById($id) { |
|
930 | - for ($i = 0; $i < count($this->_complete_forms); $i++) { |
|
931 | - if ($this->_complete_forms[$i]->getId() == $id) { |
|
932 | - return $this->_complete_forms[$i]; |
|
933 | - } |
|
934 | - } |
|
935 | - $null = null; |
|
936 | - return $null; |
|
937 | - } |
|
938 | - |
|
939 | - /** |
|
940 | - * Sets a field on each form in which the field is |
|
941 | - * available. |
|
942 | - * @param SimpleSelector $selector Field finder. |
|
943 | - * @param string $value Value to set field to. |
|
944 | - * @return boolean True if value is valid. |
|
945 | - * @access public |
|
946 | - */ |
|
947 | - function setField($selector, $value) { |
|
948 | - $is_set = false; |
|
949 | - for ($i = 0; $i < count($this->_complete_forms); $i++) { |
|
950 | - if ($this->_complete_forms[$i]->setField($selector, $value)) { |
|
951 | - $is_set = true; |
|
952 | - } |
|
953 | - } |
|
954 | - return $is_set; |
|
955 | - } |
|
956 | - |
|
957 | - /** |
|
958 | - * Accessor for a form element value within a page. |
|
959 | - * @param SimpleSelector $selector Field finder. |
|
960 | - * @return string/boolean A string if the field is |
|
961 | - * present, false if unchecked |
|
962 | - * and null if missing. |
|
963 | - * @access public |
|
964 | - */ |
|
965 | - function getField($selector) { |
|
966 | - for ($i = 0; $i < count($this->_complete_forms); $i++) { |
|
967 | - $value = $this->_complete_forms[$i]->getValue($selector); |
|
968 | - if (isset($value)) { |
|
969 | - return $value; |
|
970 | - } |
|
971 | - } |
|
972 | - return null; |
|
973 | - } |
|
974 | - } |
|
332 | + */ |
|
333 | + class SimplePage { |
|
334 | + protected $_links; |
|
335 | + protected $_title; |
|
336 | + protected $_last_widget; |
|
337 | + protected $_label; |
|
338 | + protected $_left_over_labels; |
|
339 | + protected $_open_forms; |
|
340 | + protected $_complete_forms; |
|
341 | + protected $_frameset; |
|
342 | + protected $_frames; |
|
343 | + protected $_frameset_nesting_level; |
|
344 | + protected $_transport_error; |
|
345 | + protected $_raw; |
|
346 | + protected $_text; |
|
347 | + protected $_sent; |
|
348 | + protected $_headers; |
|
349 | + protected $_method; |
|
350 | + protected $_url; |
|
351 | + protected $_request_data; |
|
352 | + |
|
353 | + /** |
|
354 | + * Parses a page ready to access it's contents. |
|
355 | + * @param SimpleHttpResponse $response Result of HTTP fetch. |
|
356 | + * @access public |
|
357 | + */ |
|
358 | + function SimplePage($response = false) { |
|
359 | + $this->_links = array(); |
|
360 | + $this->_title = false; |
|
361 | + $this->_left_over_labels = array(); |
|
362 | + $this->_open_forms = array(); |
|
363 | + $this->_complete_forms = array(); |
|
364 | + $this->_frameset = false; |
|
365 | + $this->_frames = array(); |
|
366 | + $this->_frameset_nesting_level = 0; |
|
367 | + $this->_text = false; |
|
368 | + if ($response) { |
|
369 | + $this->_extractResponse($response); |
|
370 | + } else { |
|
371 | + $this->_noResponse(); |
|
372 | + } |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Extracts all of the response information. |
|
377 | + * @param SimpleHttpResponse $response Response being parsed. |
|
378 | + * @access private |
|
379 | + */ |
|
380 | + function _extractResponse($response) { |
|
381 | + $this->_transport_error = $response->getError(); |
|
382 | + $this->_raw = $response->getContent(); |
|
383 | + $this->_sent = $response->getSent(); |
|
384 | + $this->_headers = $response->getHeaders(); |
|
385 | + $this->_method = $response->getMethod(); |
|
386 | + $this->_url = $response->getUrl(); |
|
387 | + $this->_request_data = $response->getRequestData(); |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Sets up a missing response. |
|
392 | + * @access private |
|
393 | + */ |
|
394 | + function _noResponse() { |
|
395 | + $this->_transport_error = 'No page fetched yet'; |
|
396 | + $this->_raw = false; |
|
397 | + $this->_sent = false; |
|
398 | + $this->_headers = false; |
|
399 | + $this->_method = 'GET'; |
|
400 | + $this->_url = false; |
|
401 | + $this->_request_data = false; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Original request as bytes sent down the wire. |
|
406 | + * @return mixed Sent content. |
|
407 | + * @access public |
|
408 | + */ |
|
409 | + function getRequest() { |
|
410 | + return $this->_sent; |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * Accessor for raw text of page. |
|
415 | + * @return string Raw unparsed content. |
|
416 | + * @access public |
|
417 | + */ |
|
418 | + function getRaw() { |
|
419 | + return $this->_raw; |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Accessor for plain text of page as a text browser |
|
424 | + * would see it. |
|
425 | + * @return string Plain text of page. |
|
426 | + * @access public |
|
427 | + */ |
|
428 | + function getText() { |
|
429 | + if (! $this->_text) { |
|
430 | + $this->_text = SimpleHtmlSaxParser::normalise($this->_raw); |
|
431 | + } |
|
432 | + return $this->_text; |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * Accessor for raw headers of page. |
|
437 | + * @return string Header block as text. |
|
438 | + * @access public |
|
439 | + */ |
|
440 | + function getHeaders() { |
|
441 | + if ($this->_headers) { |
|
442 | + return $this->_headers->getRaw(); |
|
443 | + } |
|
444 | + return false; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Original request method. |
|
449 | + * @return string GET, POST or HEAD. |
|
450 | + * @access public |
|
451 | + */ |
|
452 | + function getMethod() { |
|
453 | + return $this->_method; |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Original resource name. |
|
458 | + * @return SimpleUrl Current url. |
|
459 | + * @access public |
|
460 | + */ |
|
461 | + function getUrl() { |
|
462 | + return $this->_url; |
|
463 | + } |
|
464 | + |
|
465 | + /** |
|
466 | + * Original request data. |
|
467 | + * @return mixed Sent content. |
|
468 | + * @access public |
|
469 | + */ |
|
470 | + function getRequestData() { |
|
471 | + return $this->_request_data; |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * Accessor for last error. |
|
476 | + * @return string Error from last response. |
|
477 | + * @access public |
|
478 | + */ |
|
479 | + function getTransportError() { |
|
480 | + return $this->_transport_error; |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Accessor for current MIME type. |
|
485 | + * @return string MIME type as string; e.g. 'text/html' |
|
486 | + * @access public |
|
487 | + */ |
|
488 | + function getMimeType() { |
|
489 | + if ($this->_headers) { |
|
490 | + return $this->_headers->getMimeType(); |
|
491 | + } |
|
492 | + return false; |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Accessor for HTTP response code. |
|
497 | + * @return integer HTTP response code received. |
|
498 | + * @access public |
|
499 | + */ |
|
500 | + function getResponseCode() { |
|
501 | + if ($this->_headers) { |
|
502 | + return $this->_headers->getResponseCode(); |
|
503 | + } |
|
504 | + return false; |
|
505 | + } |
|
506 | + |
|
507 | + /** |
|
508 | + * Accessor for last Authentication type. Only valid |
|
509 | + * straight after a challenge (401). |
|
510 | + * @return string Description of challenge type. |
|
511 | + * @access public |
|
512 | + */ |
|
513 | + function getAuthentication() { |
|
514 | + if ($this->_headers) { |
|
515 | + return $this->_headers->getAuthentication(); |
|
516 | + } |
|
517 | + return false; |
|
518 | + } |
|
519 | + |
|
520 | + /** |
|
521 | + * Accessor for last Authentication realm. Only valid |
|
522 | + * straight after a challenge (401). |
|
523 | + * @return string Name of security realm. |
|
524 | + * @access public |
|
525 | + */ |
|
526 | + function getRealm() { |
|
527 | + if ($this->_headers) { |
|
528 | + return $this->_headers->getRealm(); |
|
529 | + } |
|
530 | + return false; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Accessor for current frame focus. Will be |
|
535 | + * false as no frames. |
|
536 | + * @return array Always empty. |
|
537 | + * @access public |
|
538 | + */ |
|
539 | + function getFrameFocus() { |
|
540 | + return array(); |
|
541 | + } |
|
542 | + |
|
543 | + /** |
|
544 | + * Sets the focus by index. The integer index starts from 1. |
|
545 | + * @param integer $choice Chosen frame. |
|
546 | + * @return boolean Always false. |
|
547 | + * @access public |
|
548 | + */ |
|
549 | + function setFrameFocusByIndex($choice) { |
|
550 | + return false; |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Sets the focus by name. Always fails for a leaf page. |
|
555 | + * @param string $name Chosen frame. |
|
556 | + * @return boolean False as no frames. |
|
557 | + * @access public |
|
558 | + */ |
|
559 | + function setFrameFocus($name) { |
|
560 | + return false; |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Clears the frame focus. Does nothing for a leaf page. |
|
565 | + * @access public |
|
566 | + */ |
|
567 | + function clearFrameFocus() { |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * Adds a tag to the page. |
|
572 | + * @param SimpleTag $tag Tag to accept. |
|
573 | + * @access public |
|
574 | + */ |
|
575 | + function acceptTag($tag) { |
|
576 | + if ($tag->getTagName() == "a") { |
|
577 | + $this->_addLink($tag); |
|
578 | + } elseif ($tag->getTagName() == "title") { |
|
579 | + $this->_setTitle($tag); |
|
580 | + } elseif ($this->_isFormElement($tag->getTagName())) { |
|
581 | + for ($i = 0; $i < count($this->_open_forms); $i++) { |
|
582 | + $this->_open_forms[$i]->addWidget($tag); |
|
583 | + } |
|
584 | + $this->_last_widget = $tag; |
|
585 | + } |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Opens a label for a described widget. |
|
590 | + * @param SimpleFormTag $tag Tag to accept. |
|
591 | + * @access public |
|
592 | + */ |
|
593 | + function acceptLabelStart($tag) { |
|
594 | + $this->_label = $tag; |
|
595 | + unset($this->_last_widget); |
|
596 | + } |
|
597 | + |
|
598 | + /** |
|
599 | + * Closes the most recently opened label. |
|
600 | + * @access public |
|
601 | + */ |
|
602 | + function acceptLabelEnd() { |
|
603 | + if (isset($this->_label)) { |
|
604 | + if (isset($this->_last_widget)) { |
|
605 | + $this->_last_widget->setLabel($this->_label->getText()); |
|
606 | + unset($this->_last_widget); |
|
607 | + } else { |
|
608 | + $this->_left_over_labels[] = SimpleTestCompatibility::copy($this->_label); |
|
609 | + } |
|
610 | + unset($this->_label); |
|
611 | + } |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Tests to see if a tag is a possible form |
|
616 | + * element. |
|
617 | + * @param string $name HTML element name. |
|
618 | + * @return boolean True if form element. |
|
619 | + * @access private |
|
620 | + */ |
|
621 | + function _isFormElement($name) { |
|
622 | + return in_array($name, array('input', 'button', 'textarea', 'select')); |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * Opens a form. New widgets go here. |
|
627 | + * @param SimpleFormTag $tag Tag to accept. |
|
628 | + * @access public |
|
629 | + */ |
|
630 | + function acceptFormStart($tag) { |
|
631 | + $this->_open_forms[] = new SimpleForm($tag, $this->getUrl()); |
|
632 | + } |
|
633 | + |
|
634 | + /** |
|
635 | + * Closes the most recently opened form. |
|
636 | + * @access public |
|
637 | + */ |
|
638 | + function acceptFormEnd() { |
|
639 | + if (count($this->_open_forms)) { |
|
640 | + $this->_complete_forms[] = array_pop($this->_open_forms); |
|
641 | + } |
|
642 | + } |
|
643 | + |
|
644 | + /** |
|
645 | + * Opens a frameset. A frameset may contain nested |
|
646 | + * frameset tags. |
|
647 | + * @param SimpleFramesetTag $tag Tag to accept. |
|
648 | + * @access public |
|
649 | + */ |
|
650 | + function acceptFramesetStart($tag) { |
|
651 | + if (! $this->_isLoadingFrames()) { |
|
652 | + $this->_frameset = $tag; |
|
653 | + } |
|
654 | + $this->_frameset_nesting_level++; |
|
655 | + } |
|
656 | + |
|
657 | + /** |
|
658 | + * Closes the most recently opened frameset. |
|
659 | + * @access public |
|
660 | + */ |
|
661 | + function acceptFramesetEnd() { |
|
662 | + if ($this->_isLoadingFrames()) { |
|
663 | + $this->_frameset_nesting_level--; |
|
664 | + } |
|
665 | + } |
|
666 | + |
|
667 | + /** |
|
668 | + * Takes a single frame tag and stashes it in |
|
669 | + * the current frame set. |
|
670 | + * @param SimpleFrameTag $tag Tag to accept. |
|
671 | + * @access public |
|
672 | + */ |
|
673 | + function acceptFrame($tag) { |
|
674 | + if ($this->_isLoadingFrames()) { |
|
675 | + if ($tag->getAttribute('src')) { |
|
676 | + $this->_frames[] = $tag; |
|
677 | + } |
|
678 | + } |
|
679 | + } |
|
680 | + |
|
681 | + /** |
|
682 | + * Test to see if in the middle of reading |
|
683 | + * a frameset. |
|
684 | + * @return boolean True if inframeset. |
|
685 | + * @access private |
|
686 | + */ |
|
687 | + function _isLoadingFrames() { |
|
688 | + if (! $this->_frameset) { |
|
689 | + return false; |
|
690 | + } |
|
691 | + return ($this->_frameset_nesting_level > 0); |
|
692 | + } |
|
693 | + |
|
694 | + /** |
|
695 | + * Test to see if link is an absolute one. |
|
696 | + * @param string $url Url to test. |
|
697 | + * @return boolean True if absolute. |
|
698 | + * @access protected |
|
699 | + */ |
|
700 | + function _linkIsAbsolute($url) { |
|
701 | + $parsed = new SimpleUrl($url); |
|
702 | + return (boolean)($parsed->getScheme() && $parsed->getHost()); |
|
703 | + } |
|
704 | + |
|
705 | + /** |
|
706 | + * Adds a link to the page. |
|
707 | + * @param SimpleAnchorTag $tag Link to accept. |
|
708 | + * @access protected |
|
709 | + */ |
|
710 | + function _addLink($tag) { |
|
711 | + $this->_links[] = $tag; |
|
712 | + } |
|
713 | + |
|
714 | + /** |
|
715 | + * Marker for end of complete page. Any work in |
|
716 | + * progress can now be closed. |
|
717 | + * @access public |
|
718 | + */ |
|
719 | + function acceptPageEnd() { |
|
720 | + while (count($this->_open_forms)) { |
|
721 | + $this->_complete_forms[] = array_pop($this->_open_forms); |
|
722 | + } |
|
723 | + foreach ($this->_left_over_labels as $label) { |
|
724 | + for ($i = 0, $count = count($this->_complete_forms); $i < $count; $i++) { |
|
725 | + $this->_complete_forms[$i]->attachLabelBySelector( |
|
726 | + new SimpleById($label->getFor()), |
|
727 | + $label->getText()); |
|
728 | + } |
|
729 | + } |
|
730 | + } |
|
731 | + |
|
732 | + /** |
|
733 | + * Test for the presence of a frameset. |
|
734 | + * @return boolean True if frameset. |
|
735 | + * @access public |
|
736 | + */ |
|
737 | + function hasFrames() { |
|
738 | + return (boolean)$this->_frameset; |
|
739 | + } |
|
740 | + |
|
741 | + /** |
|
742 | + * Accessor for frame name and source URL for every frame that |
|
743 | + * will need to be loaded. Immediate children only. |
|
744 | + * @return boolean/array False if no frameset or |
|
745 | + * otherwise a hash of frame URLs. |
|
746 | + * The key is either a numerical |
|
747 | + * base one index or the name attribute. |
|
748 | + * @access public |
|
749 | + */ |
|
750 | + function getFrameset() { |
|
751 | + if (! $this->_frameset) { |
|
752 | + return false; |
|
753 | + } |
|
754 | + $urls = array(); |
|
755 | + for ($i = 0; $i < count($this->_frames); $i++) { |
|
756 | + $name = $this->_frames[$i]->getAttribute('name'); |
|
757 | + $url = new SimpleUrl($this->_frames[$i]->getAttribute('src')); |
|
758 | + $urls[$name ? $name : $i + 1] = $url->makeAbsolute($this->getUrl()); |
|
759 | + } |
|
760 | + return $urls; |
|
761 | + } |
|
762 | + |
|
763 | + /** |
|
764 | + * Fetches a list of loaded frames. |
|
765 | + * @return array/string Just the URL for a single page. |
|
766 | + * @access public |
|
767 | + */ |
|
768 | + function getFrames() { |
|
769 | + $url = $this->getUrl(); |
|
770 | + return $url->asString(); |
|
771 | + } |
|
772 | + |
|
773 | + /** |
|
774 | + * Accessor for a list of all fixed links. |
|
775 | + * @return array List of urls with scheme of |
|
776 | + * http or https and hostname. |
|
777 | + * @access public |
|
778 | + */ |
|
779 | + function getAbsoluteUrls() { |
|
780 | + $all = array(); |
|
781 | + foreach ($this->_links as $link) { |
|
782 | + if ($this->_linkIsAbsolute($link->getHref())) { |
|
783 | + $all[] = $link->getHref(); |
|
784 | + } |
|
785 | + } |
|
786 | + return $all; |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * Accessor for a list of all relative links. |
|
791 | + * @return array List of urls without hostname. |
|
792 | + * @access public |
|
793 | + */ |
|
794 | + function getRelativeUrls() { |
|
795 | + $all = array(); |
|
796 | + foreach ($this->_links as $link) { |
|
797 | + if (! $this->_linkIsAbsolute($link->getHref())) { |
|
798 | + $all[] = $link->getHref(); |
|
799 | + } |
|
800 | + } |
|
801 | + return $all; |
|
802 | + } |
|
803 | + |
|
804 | + /** |
|
805 | + * Accessor for URLs by the link label. Label will match |
|
806 | + * regardess of whitespace issues and case. |
|
807 | + * @param string $label Text of link. |
|
808 | + * @return array List of links with that label. |
|
809 | + * @access public |
|
810 | + */ |
|
811 | + function getUrlsByLabel($label) { |
|
812 | + $matches = array(); |
|
813 | + foreach ($this->_links as $link) { |
|
814 | + if ($link->getText() == $label) { |
|
815 | + $matches[] = $this->_getUrlFromLink($link); |
|
816 | + } |
|
817 | + } |
|
818 | + return $matches; |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * Accessor for a URL by the id attribute. |
|
823 | + * @param string $id Id attribute of link. |
|
824 | + * @return SimpleUrl URL with that id of false if none. |
|
825 | + * @access public |
|
826 | + */ |
|
827 | + function getUrlById($id) { |
|
828 | + foreach ($this->_links as $link) { |
|
829 | + if ($link->getAttribute('id') === (string)$id) { |
|
830 | + return $this->_getUrlFromLink($link); |
|
831 | + } |
|
832 | + } |
|
833 | + return false; |
|
834 | + } |
|
835 | + |
|
836 | + /** |
|
837 | + * Converts a link into a target URL. |
|
838 | + * @param SimpleAnchor $link Parsed link. |
|
839 | + * @return SimpleUrl URL with frame target if any. |
|
840 | + * @access private |
|
841 | + */ |
|
842 | + function _getUrlFromLink($link) { |
|
843 | + $url = $this->_makeAbsolute($link->getHref()); |
|
844 | + if ($link->getAttribute('target')) { |
|
845 | + $url->setTarget($link->getAttribute('target')); |
|
846 | + } |
|
847 | + return $url; |
|
848 | + } |
|
849 | + |
|
850 | + /** |
|
851 | + * Expands expandomatic URLs into fully qualified |
|
852 | + * URLs. |
|
853 | + * @param SimpleUrl $url Relative URL. |
|
854 | + * @return SimpleUrl Absolute URL. |
|
855 | + * @access protected |
|
856 | + */ |
|
857 | + function _makeAbsolute($url) { |
|
858 | + if (! is_object($url)) { |
|
859 | + $url = new SimpleUrl($url); |
|
860 | + } |
|
861 | + return $url->makeAbsolute($this->getUrl()); |
|
862 | + } |
|
863 | + |
|
864 | + /** |
|
865 | + * Sets the title tag contents. |
|
866 | + * @param SimpleTitleTag $tag Title of page. |
|
867 | + * @access protected |
|
868 | + */ |
|
869 | + function _setTitle($tag) { |
|
870 | + $this->_title = $tag; |
|
871 | + } |
|
872 | + |
|
873 | + /** |
|
874 | + * Accessor for parsed title. |
|
875 | + * @return string Title or false if no title is present. |
|
876 | + * @access public |
|
877 | + */ |
|
878 | + function getTitle() { |
|
879 | + if ($this->_title) { |
|
880 | + return $this->_title->getText(); |
|
881 | + } |
|
882 | + return false; |
|
883 | + } |
|
884 | + |
|
885 | + /** |
|
886 | + * Finds a held form by button label. Will only |
|
887 | + * search correctly built forms. |
|
888 | + * @param SimpleSelector $selector Button finder. |
|
889 | + * @return SimpleForm Form object containing |
|
890 | + * the button. |
|
891 | + * @access public |
|
892 | + */ |
|
893 | + function &getFormBySubmit($selector) { |
|
894 | + for ($i = 0; $i < count($this->_complete_forms); $i++) { |
|
895 | + if ($this->_complete_forms[$i]->hasSubmit($selector)) { |
|
896 | + return $this->_complete_forms[$i]; |
|
897 | + } |
|
898 | + } |
|
899 | + $null = null; |
|
900 | + return $null; |
|
901 | + } |
|
902 | + |
|
903 | + /** |
|
904 | + * Finds a held form by image using a selector. |
|
905 | + * Will only search correctly built forms. |
|
906 | + * @param SimpleSelector $selector Image finder. |
|
907 | + * @return SimpleForm Form object containing |
|
908 | + * the image. |
|
909 | + * @access public |
|
910 | + */ |
|
911 | + function &getFormByImage($selector) { |
|
912 | + for ($i = 0; $i < count($this->_complete_forms); $i++) { |
|
913 | + if ($this->_complete_forms[$i]->hasImage($selector)) { |
|
914 | + return $this->_complete_forms[$i]; |
|
915 | + } |
|
916 | + } |
|
917 | + $null = null; |
|
918 | + return $null; |
|
919 | + } |
|
920 | + |
|
921 | + /** |
|
922 | + * Finds a held form by the form ID. A way of |
|
923 | + * identifying a specific form when we have control |
|
924 | + * of the HTML code. |
|
925 | + * @param string $id Form label. |
|
926 | + * @return SimpleForm Form object containing the matching ID. |
|
927 | + * @access public |
|
928 | + */ |
|
929 | + function &getFormById($id) { |
|
930 | + for ($i = 0; $i < count($this->_complete_forms); $i++) { |
|
931 | + if ($this->_complete_forms[$i]->getId() == $id) { |
|
932 | + return $this->_complete_forms[$i]; |
|
933 | + } |
|
934 | + } |
|
935 | + $null = null; |
|
936 | + return $null; |
|
937 | + } |
|
938 | + |
|
939 | + /** |
|
940 | + * Sets a field on each form in which the field is |
|
941 | + * available. |
|
942 | + * @param SimpleSelector $selector Field finder. |
|
943 | + * @param string $value Value to set field to. |
|
944 | + * @return boolean True if value is valid. |
|
945 | + * @access public |
|
946 | + */ |
|
947 | + function setField($selector, $value) { |
|
948 | + $is_set = false; |
|
949 | + for ($i = 0; $i < count($this->_complete_forms); $i++) { |
|
950 | + if ($this->_complete_forms[$i]->setField($selector, $value)) { |
|
951 | + $is_set = true; |
|
952 | + } |
|
953 | + } |
|
954 | + return $is_set; |
|
955 | + } |
|
956 | + |
|
957 | + /** |
|
958 | + * Accessor for a form element value within a page. |
|
959 | + * @param SimpleSelector $selector Field finder. |
|
960 | + * @return string/boolean A string if the field is |
|
961 | + * present, false if unchecked |
|
962 | + * and null if missing. |
|
963 | + * @access public |
|
964 | + */ |
|
965 | + function getField($selector) { |
|
966 | + for ($i = 0; $i < count($this->_complete_forms); $i++) { |
|
967 | + $value = $this->_complete_forms[$i]->getValue($selector); |
|
968 | + if (isset($value)) { |
|
969 | + return $value; |
|
970 | + } |
|
971 | + } |
|
972 | + return null; |
|
973 | + } |
|
974 | + } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @access protected |
76 | 76 | */ |
77 | 77 | function _createInputTag($attributes) { |
78 | - if (! isset($attributes['type'])) { |
|
78 | + if (!isset($attributes['type'])) { |
|
79 | 79 | return new SimpleTextTag($attributes); |
80 | 80 | } |
81 | 81 | $type = strtolower(trim($attributes['type'])); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | function startElement($name, $attributes) { |
190 | 190 | $factory = new SimpleTagBuilder(); |
191 | 191 | $tag = $factory->createTag($name, $attributes); |
192 | - if (! $tag) { |
|
192 | + if (!$tag) { |
|
193 | 193 | return true; |
194 | 194 | } |
195 | 195 | if ($tag->getTagName() == 'label') { |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | $this->_page->acceptFrame($tag); |
210 | 210 | return true; |
211 | 211 | } |
212 | - if ($tag->isPrivateContent() && ! isset($this->_private_content_tag)) { |
|
212 | + if ($tag->isPrivateContent() && !isset($this->_private_content_tag)) { |
|
213 | 213 | $this->_private_content_tag = $tag; |
214 | 214 | } |
215 | 215 | if ($tag->expectEndTag()) { |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | */ |
319 | 319 | function _openTag($tag) { |
320 | 320 | $name = $tag->getTagName(); |
321 | - if (! in_array($name, array_keys($this->_tags))) { |
|
321 | + if (!in_array($name, array_keys($this->_tags))) { |
|
322 | 322 | $this->_tags[$name] = array(); |
323 | 323 | } |
324 | 324 | $this->_tags[$name][] = $tag; |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @access public |
427 | 427 | */ |
428 | 428 | function getText() { |
429 | - if (! $this->_text) { |
|
429 | + if (!$this->_text) { |
|
430 | 430 | $this->_text = SimpleHtmlSaxParser::normalise($this->_raw); |
431 | 431 | } |
432 | 432 | return $this->_text; |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | * @access public |
649 | 649 | */ |
650 | 650 | function acceptFramesetStart($tag) { |
651 | - if (! $this->_isLoadingFrames()) { |
|
651 | + if (!$this->_isLoadingFrames()) { |
|
652 | 652 | $this->_frameset = $tag; |
653 | 653 | } |
654 | 654 | $this->_frameset_nesting_level++; |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | * @access private |
686 | 686 | */ |
687 | 687 | function _isLoadingFrames() { |
688 | - if (! $this->_frameset) { |
|
688 | + if (!$this->_frameset) { |
|
689 | 689 | return false; |
690 | 690 | } |
691 | 691 | return ($this->_frameset_nesting_level > 0); |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | */ |
700 | 700 | function _linkIsAbsolute($url) { |
701 | 701 | $parsed = new SimpleUrl($url); |
702 | - return (boolean)($parsed->getScheme() && $parsed->getHost()); |
|
702 | + return (boolean) ($parsed->getScheme() && $parsed->getHost()); |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | /** |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | * @access public |
736 | 736 | */ |
737 | 737 | function hasFrames() { |
738 | - return (boolean)$this->_frameset; |
|
738 | + return (boolean) $this->_frameset; |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | /** |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | * @access public |
749 | 749 | */ |
750 | 750 | function getFrameset() { |
751 | - if (! $this->_frameset) { |
|
751 | + if (!$this->_frameset) { |
|
752 | 752 | return false; |
753 | 753 | } |
754 | 754 | $urls = array(); |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | function getRelativeUrls() { |
795 | 795 | $all = array(); |
796 | 796 | foreach ($this->_links as $link) { |
797 | - if (! $this->_linkIsAbsolute($link->getHref())) { |
|
797 | + if (!$this->_linkIsAbsolute($link->getHref())) { |
|
798 | 798 | $all[] = $link->getHref(); |
799 | 799 | } |
800 | 800 | } |
@@ -826,7 +826,7 @@ discard block |
||
826 | 826 | */ |
827 | 827 | function getUrlById($id) { |
828 | 828 | foreach ($this->_links as $link) { |
829 | - if ($link->getAttribute('id') === (string)$id) { |
|
829 | + if ($link->getAttribute('id') === (string) $id) { |
|
830 | 830 | return $this->_getUrlFromLink($link); |
831 | 831 | } |
832 | 832 | } |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | * @access protected |
856 | 856 | */ |
857 | 857 | function _makeAbsolute($url) { |
858 | - if (! is_object($url)) { |
|
858 | + if (!is_object($url)) { |
|
859 | 859 | $url = new SimpleUrl($url); |
860 | 860 | } |
861 | 861 | return $url->makeAbsolute($this->getUrl()); |
@@ -98,8 +98,6 @@ discard block |
||
98 | 98 | * regular expression separated with the |
99 | 99 | * "or" operator. Caches the regex. |
100 | 100 | * Will automatically escape (, ) and / tokens. |
101 | - * @param array $patterns List of patterns in order. |
|
102 | - * @access private |
|
103 | 101 | */ |
104 | 102 | function _getCompoundedRegex() { |
105 | 103 | if ($this->_regex == null) { |
@@ -476,7 +474,7 @@ discard block |
||
476 | 474 | |
477 | 475 | /** |
478 | 476 | * List of parsed tags. Others are ignored. |
479 | - * @return array List of searched for tags. |
|
477 | + * @return string[] List of searched for tags. |
|
480 | 478 | * @access private |
481 | 479 | */ |
482 | 480 | function _getParsedTags() { |
@@ -581,7 +579,7 @@ discard block |
||
581 | 579 | |
582 | 580 | /** |
583 | 581 | * Sets up the matching lexer. Starts in 'text' mode. |
584 | - * @param SimpleSaxParser $parser Event generator, usually $self. |
|
582 | + * @param SimpleHtmlSaxParser $parser Event generator, usually $self. |
|
585 | 583 | * @return SimpleLexer Lexer suitable for this parser. |
586 | 584 | * @access public |
587 | 585 | * @static |
@@ -599,7 +597,7 @@ discard block |
||
599 | 597 | * name is converted to lower case. |
600 | 598 | * @param string $token Incoming characters. |
601 | 599 | * @param integer $event Lexer event type. |
602 | - * @return boolean False if parse error. |
|
600 | + * @return boolean|null False if parse error. |
|
603 | 601 | * @access public |
604 | 602 | */ |
605 | 603 | function acceptStartToken($token, $event) { |
@@ -627,7 +625,7 @@ discard block |
||
627 | 625 | * The element name is converted to lower case. |
628 | 626 | * @param string $token Incoming characters. |
629 | 627 | * @param integer $event Lexer event type. |
630 | - * @return boolean False if parse error. |
|
628 | + * @return boolean|null False if parse error. |
|
631 | 629 | * @access public |
632 | 630 | */ |
633 | 631 | function acceptEndToken($token, $event) { |
@@ -660,7 +658,7 @@ discard block |
||
660 | 658 | * A character entity. |
661 | 659 | * @param string $token Incoming characters. |
662 | 660 | * @param integer $event Lexer event type. |
663 | - * @return boolean False if parse error. |
|
661 | + * @return boolean|null False if parse error. |
|
664 | 662 | * @access public |
665 | 663 | */ |
666 | 664 | function acceptEntityToken($token, $event) { |
@@ -671,7 +669,7 @@ discard block |
||
671 | 669 | * important. |
672 | 670 | * @param string $token Incoming characters. |
673 | 671 | * @param integer $event Lexer event type. |
674 | - * @return boolean False if parse error. |
|
672 | + * @return boolean|null False if parse error. |
|
675 | 673 | * @access public |
676 | 674 | */ |
677 | 675 | function acceptTextToken($token, $event) { |
@@ -746,7 +744,7 @@ discard block |
||
746 | 744 | * @param hash $attributes Name value pairs. |
747 | 745 | * Attributes without content |
748 | 746 | * are marked as true. |
749 | - * @return boolean False on parse error. |
|
747 | + * @return boolean|null False on parse error. |
|
750 | 748 | * @access public |
751 | 749 | */ |
752 | 750 | function startElement($name, $attributes) { |
@@ -755,7 +753,7 @@ discard block |
||
755 | 753 | /** |
756 | 754 | * End of element event. |
757 | 755 | * @param string $name Element name. |
758 | - * @return boolean False on parse error. |
|
756 | + * @return boolean|null False on parse error. |
|
759 | 757 | * @access public |
760 | 758 | */ |
761 | 759 | function endElement($name) { |
@@ -764,7 +762,7 @@ discard block |
||
764 | 762 | /** |
765 | 763 | * Unparsed, but relevant data. |
766 | 764 | * @param string $text May include unparsed tags. |
767 | - * @return boolean False on parse error. |
|
765 | + * @return boolean|null False on parse error. |
|
768 | 766 | * @access public |
769 | 767 | */ |
770 | 768 | function addContent($text) { |
@@ -1,772 +1,772 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage MockObjects |
|
6 | - * @version $Id: parser.php 1532 2006-12-01 12:28:55Z xue $ |
|
7 | - */ |
|
8 | - |
|
9 | - /**#@+ |
|
2 | + /** |
|
3 | + * base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage MockObjects |
|
6 | + * @version $Id: parser.php 1532 2006-12-01 12:28:55Z xue $ |
|
7 | + */ |
|
8 | + |
|
9 | + /**#@+ |
|
10 | 10 | * Lexer mode stack constants |
11 | 11 | */ |
12 | - if (! defined('LEXER_ENTER')) { |
|
13 | - define('LEXER_ENTER', 1); |
|
14 | - } |
|
15 | - if (! defined('LEXER_MATCHED')) { |
|
16 | - define('LEXER_MATCHED', 2); |
|
17 | - } |
|
18 | - if (! defined('LEXER_UNMATCHED')) { |
|
19 | - define('LEXER_UNMATCHED', 3); |
|
20 | - } |
|
21 | - if (! defined('LEXER_EXIT')) { |
|
22 | - define('LEXER_EXIT', 4); |
|
23 | - } |
|
24 | - if (! defined('LEXER_SPECIAL')) { |
|
25 | - define('LEXER_SPECIAL', 5); |
|
26 | - } |
|
27 | - /**#@-*/ |
|
28 | - |
|
29 | - /** |
|
30 | - * Compounded regular expression. Any of |
|
31 | - * the contained patterns could match and |
|
32 | - * when one does, it's label is returned. |
|
12 | + if (! defined('LEXER_ENTER')) { |
|
13 | + define('LEXER_ENTER', 1); |
|
14 | + } |
|
15 | + if (! defined('LEXER_MATCHED')) { |
|
16 | + define('LEXER_MATCHED', 2); |
|
17 | + } |
|
18 | + if (! defined('LEXER_UNMATCHED')) { |
|
19 | + define('LEXER_UNMATCHED', 3); |
|
20 | + } |
|
21 | + if (! defined('LEXER_EXIT')) { |
|
22 | + define('LEXER_EXIT', 4); |
|
23 | + } |
|
24 | + if (! defined('LEXER_SPECIAL')) { |
|
25 | + define('LEXER_SPECIAL', 5); |
|
26 | + } |
|
27 | + /**#@-*/ |
|
28 | + |
|
29 | + /** |
|
30 | + * Compounded regular expression. Any of |
|
31 | + * the contained patterns could match and |
|
32 | + * when one does, it's label is returned. |
|
33 | 33 | * @package SimpleTest |
34 | 34 | * @subpackage WebTester |
35 | - */ |
|
36 | - class ParallelRegex { |
|
37 | - protected $_patterns; |
|
38 | - protected $_labels; |
|
39 | - protected $_regex; |
|
40 | - protected $_case; |
|
41 | - |
|
42 | - /** |
|
43 | - * Constructor. Starts with no patterns. |
|
44 | - * @param boolean $case True for case sensitive, false |
|
45 | - * for insensitive. |
|
46 | - * @access public |
|
47 | - */ |
|
48 | - function ParallelRegex($case) { |
|
49 | - $this->_case = $case; |
|
50 | - $this->_patterns = array(); |
|
51 | - $this->_labels = array(); |
|
52 | - $this->_regex = null; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Adds a pattern with an optional label. |
|
57 | - * @param string $pattern Perl style regex, but ( and ) |
|
58 | - * lose the usual meaning. |
|
59 | - * @param string $label Label of regex to be returned |
|
60 | - * on a match. |
|
61 | - * @access public |
|
62 | - */ |
|
63 | - function addPattern($pattern, $label = true) { |
|
64 | - $count = count($this->_patterns); |
|
65 | - $this->_patterns[$count] = $pattern; |
|
66 | - $this->_labels[$count] = $label; |
|
67 | - $this->_regex = null; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Attempts to match all patterns at once against |
|
72 | - * a string. |
|
73 | - * @param string $subject String to match against. |
|
74 | - * @param string $match First matched portion of |
|
75 | - * subject. |
|
76 | - * @return boolean True on success. |
|
77 | - * @access public |
|
78 | - */ |
|
79 | - function match($subject, $match) { |
|
80 | - if (count($this->_patterns) == 0) { |
|
81 | - return false; |
|
82 | - } |
|
83 | - if (! preg_match($this->_getCompoundedRegex(), $subject, $matches)) { |
|
84 | - $match = ''; |
|
85 | - return false; |
|
86 | - } |
|
87 | - $match = $matches[0]; |
|
88 | - for ($i = 1; $i < count($matches); $i++) { |
|
89 | - if ($matches[$i]) { |
|
90 | - return $this->_labels[$i - 1]; |
|
91 | - } |
|
92 | - } |
|
93 | - return true; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Compounds the patterns into a single |
|
98 | - * regular expression separated with the |
|
99 | - * "or" operator. Caches the regex. |
|
100 | - * Will automatically escape (, ) and / tokens. |
|
101 | - * @param array $patterns List of patterns in order. |
|
102 | - * @access private |
|
103 | - */ |
|
104 | - function _getCompoundedRegex() { |
|
105 | - if ($this->_regex == null) { |
|
106 | - for ($i = 0, $count = count($this->_patterns); $i < $count; $i++) { |
|
107 | - $this->_patterns[$i] = '(' . str_replace( |
|
108 | - array('/', '(', ')'), |
|
109 | - array('\/', '\(', '\)'), |
|
110 | - $this->_patterns[$i]) . ')'; |
|
111 | - } |
|
112 | - $this->_regex = "/" . implode("|", $this->_patterns) . "/" . $this->_getPerlMatchingFlags(); |
|
113 | - } |
|
114 | - return $this->_regex; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Accessor for perl regex mode flags to use. |
|
119 | - * @return string Perl regex flags. |
|
120 | - * @access private |
|
121 | - */ |
|
122 | - function _getPerlMatchingFlags() { |
|
123 | - return ($this->_case ? "msS" : "msSi"); |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * States for a stack machine. |
|
35 | + */ |
|
36 | + class ParallelRegex { |
|
37 | + protected $_patterns; |
|
38 | + protected $_labels; |
|
39 | + protected $_regex; |
|
40 | + protected $_case; |
|
41 | + |
|
42 | + /** |
|
43 | + * Constructor. Starts with no patterns. |
|
44 | + * @param boolean $case True for case sensitive, false |
|
45 | + * for insensitive. |
|
46 | + * @access public |
|
47 | + */ |
|
48 | + function ParallelRegex($case) { |
|
49 | + $this->_case = $case; |
|
50 | + $this->_patterns = array(); |
|
51 | + $this->_labels = array(); |
|
52 | + $this->_regex = null; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Adds a pattern with an optional label. |
|
57 | + * @param string $pattern Perl style regex, but ( and ) |
|
58 | + * lose the usual meaning. |
|
59 | + * @param string $label Label of regex to be returned |
|
60 | + * on a match. |
|
61 | + * @access public |
|
62 | + */ |
|
63 | + function addPattern($pattern, $label = true) { |
|
64 | + $count = count($this->_patterns); |
|
65 | + $this->_patterns[$count] = $pattern; |
|
66 | + $this->_labels[$count] = $label; |
|
67 | + $this->_regex = null; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Attempts to match all patterns at once against |
|
72 | + * a string. |
|
73 | + * @param string $subject String to match against. |
|
74 | + * @param string $match First matched portion of |
|
75 | + * subject. |
|
76 | + * @return boolean True on success. |
|
77 | + * @access public |
|
78 | + */ |
|
79 | + function match($subject, $match) { |
|
80 | + if (count($this->_patterns) == 0) { |
|
81 | + return false; |
|
82 | + } |
|
83 | + if (! preg_match($this->_getCompoundedRegex(), $subject, $matches)) { |
|
84 | + $match = ''; |
|
85 | + return false; |
|
86 | + } |
|
87 | + $match = $matches[0]; |
|
88 | + for ($i = 1; $i < count($matches); $i++) { |
|
89 | + if ($matches[$i]) { |
|
90 | + return $this->_labels[$i - 1]; |
|
91 | + } |
|
92 | + } |
|
93 | + return true; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Compounds the patterns into a single |
|
98 | + * regular expression separated with the |
|
99 | + * "or" operator. Caches the regex. |
|
100 | + * Will automatically escape (, ) and / tokens. |
|
101 | + * @param array $patterns List of patterns in order. |
|
102 | + * @access private |
|
103 | + */ |
|
104 | + function _getCompoundedRegex() { |
|
105 | + if ($this->_regex == null) { |
|
106 | + for ($i = 0, $count = count($this->_patterns); $i < $count; $i++) { |
|
107 | + $this->_patterns[$i] = '(' . str_replace( |
|
108 | + array('/', '(', ')'), |
|
109 | + array('\/', '\(', '\)'), |
|
110 | + $this->_patterns[$i]) . ')'; |
|
111 | + } |
|
112 | + $this->_regex = "/" . implode("|", $this->_patterns) . "/" . $this->_getPerlMatchingFlags(); |
|
113 | + } |
|
114 | + return $this->_regex; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Accessor for perl regex mode flags to use. |
|
119 | + * @return string Perl regex flags. |
|
120 | + * @access private |
|
121 | + */ |
|
122 | + function _getPerlMatchingFlags() { |
|
123 | + return ($this->_case ? "msS" : "msSi"); |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * States for a stack machine. |
|
129 | 129 | * @package SimpleTest |
130 | 130 | * @subpackage WebTester |
131 | - */ |
|
132 | - class SimpleStateStack { |
|
133 | - protected $_stack; |
|
134 | - |
|
135 | - /** |
|
136 | - * Constructor. Starts in named state. |
|
137 | - * @param string $start Starting state name. |
|
138 | - * @access public |
|
139 | - */ |
|
140 | - function SimpleStateStack($start) { |
|
141 | - $this->_stack = array($start); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Accessor for current state. |
|
146 | - * @return string State. |
|
147 | - * @access public |
|
148 | - */ |
|
149 | - function getCurrent() { |
|
150 | - return $this->_stack[count($this->_stack) - 1]; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Adds a state to the stack and sets it |
|
155 | - * to be the current state. |
|
156 | - * @param string $state New state. |
|
157 | - * @access public |
|
158 | - */ |
|
159 | - function enter($state) { |
|
160 | - array_push($this->_stack, $state); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Leaves the current state and reverts |
|
165 | - * to the previous one. |
|
166 | - * @return boolean False if we drop off |
|
167 | - * the bottom of the list. |
|
168 | - * @access public |
|
169 | - */ |
|
170 | - function leave() { |
|
171 | - if (count($this->_stack) == 1) { |
|
172 | - return false; |
|
173 | - } |
|
174 | - array_pop($this->_stack); |
|
175 | - return true; |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Accepts text and breaks it into tokens. |
|
181 | - * Some optimisation to make the sure the |
|
182 | - * content is only scanned by the PHP regex |
|
183 | - * parser once. Lexer modes must not start |
|
184 | - * with leading underscores. |
|
131 | + */ |
|
132 | + class SimpleStateStack { |
|
133 | + protected $_stack; |
|
134 | + |
|
135 | + /** |
|
136 | + * Constructor. Starts in named state. |
|
137 | + * @param string $start Starting state name. |
|
138 | + * @access public |
|
139 | + */ |
|
140 | + function SimpleStateStack($start) { |
|
141 | + $this->_stack = array($start); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Accessor for current state. |
|
146 | + * @return string State. |
|
147 | + * @access public |
|
148 | + */ |
|
149 | + function getCurrent() { |
|
150 | + return $this->_stack[count($this->_stack) - 1]; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Adds a state to the stack and sets it |
|
155 | + * to be the current state. |
|
156 | + * @param string $state New state. |
|
157 | + * @access public |
|
158 | + */ |
|
159 | + function enter($state) { |
|
160 | + array_push($this->_stack, $state); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Leaves the current state and reverts |
|
165 | + * to the previous one. |
|
166 | + * @return boolean False if we drop off |
|
167 | + * the bottom of the list. |
|
168 | + * @access public |
|
169 | + */ |
|
170 | + function leave() { |
|
171 | + if (count($this->_stack) == 1) { |
|
172 | + return false; |
|
173 | + } |
|
174 | + array_pop($this->_stack); |
|
175 | + return true; |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Accepts text and breaks it into tokens. |
|
181 | + * Some optimisation to make the sure the |
|
182 | + * content is only scanned by the PHP regex |
|
183 | + * parser once. Lexer modes must not start |
|
184 | + * with leading underscores. |
|
185 | 185 | * @package SimpleTest |
186 | 186 | * @subpackage WebTester |
187 | - */ |
|
188 | - class SimpleLexer { |
|
189 | - protected $_regexes; |
|
190 | - protected $_parser; |
|
191 | - protected $_mode; |
|
192 | - protected $_mode_handlers; |
|
193 | - protected $_case; |
|
194 | - |
|
195 | - /** |
|
196 | - * Sets up the lexer in case insensitive matching |
|
197 | - * by default. |
|
198 | - * @param SimpleSaxParser $parser Handling strategy by |
|
199 | - * reference. |
|
200 | - * @param string $start Starting handler. |
|
201 | - * @param boolean $case True for case sensitive. |
|
202 | - * @access public |
|
203 | - */ |
|
204 | - function SimpleLexer($parser, $start = "accept", $case = false) { |
|
205 | - $this->_case = $case; |
|
206 | - $this->_regexes = array(); |
|
207 | - $this->_parser = $parser; |
|
208 | - $this->_mode = new SimpleStateStack($start); |
|
209 | - $this->_mode_handlers = array($start => $start); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Adds a token search pattern for a particular |
|
214 | - * parsing mode. The pattern does not change the |
|
215 | - * current mode. |
|
216 | - * @param string $pattern Perl style regex, but ( and ) |
|
217 | - * lose the usual meaning. |
|
218 | - * @param string $mode Should only apply this |
|
219 | - * pattern when dealing with |
|
220 | - * this type of input. |
|
221 | - * @access public |
|
222 | - */ |
|
223 | - function addPattern($pattern, $mode = "accept") { |
|
224 | - if (! isset($this->_regexes[$mode])) { |
|
225 | - $this->_regexes[$mode] = new ParallelRegex($this->_case); |
|
226 | - } |
|
227 | - $this->_regexes[$mode]->addPattern($pattern); |
|
228 | - if (! isset($this->_mode_handlers[$mode])) { |
|
229 | - $this->_mode_handlers[$mode] = $mode; |
|
230 | - } |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Adds a pattern that will enter a new parsing |
|
235 | - * mode. Useful for entering parenthesis, strings, |
|
236 | - * tags, etc. |
|
237 | - * @param string $pattern Perl style regex, but ( and ) |
|
238 | - * lose the usual meaning. |
|
239 | - * @param string $mode Should only apply this |
|
240 | - * pattern when dealing with |
|
241 | - * this type of input. |
|
242 | - * @param string $new_mode Change parsing to this new |
|
243 | - * nested mode. |
|
244 | - * @access public |
|
245 | - */ |
|
246 | - function addEntryPattern($pattern, $mode, $new_mode) { |
|
247 | - if (! isset($this->_regexes[$mode])) { |
|
248 | - $this->_regexes[$mode] = new ParallelRegex($this->_case); |
|
249 | - } |
|
250 | - $this->_regexes[$mode]->addPattern($pattern, $new_mode); |
|
251 | - if (! isset($this->_mode_handlers[$new_mode])) { |
|
252 | - $this->_mode_handlers[$new_mode] = $new_mode; |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Adds a pattern that will exit the current mode |
|
258 | - * and re-enter the previous one. |
|
259 | - * @param string $pattern Perl style regex, but ( and ) |
|
260 | - * lose the usual meaning. |
|
261 | - * @param string $mode Mode to leave. |
|
262 | - * @access public |
|
263 | - */ |
|
264 | - function addExitPattern($pattern, $mode) { |
|
265 | - if (! isset($this->_regexes[$mode])) { |
|
266 | - $this->_regexes[$mode] = new ParallelRegex($this->_case); |
|
267 | - } |
|
268 | - $this->_regexes[$mode]->addPattern($pattern, "__exit"); |
|
269 | - if (! isset($this->_mode_handlers[$mode])) { |
|
270 | - $this->_mode_handlers[$mode] = $mode; |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Adds a pattern that has a special mode. Acts as an entry |
|
276 | - * and exit pattern in one go, effectively calling a special |
|
277 | - * parser handler for this token only. |
|
278 | - * @param string $pattern Perl style regex, but ( and ) |
|
279 | - * lose the usual meaning. |
|
280 | - * @param string $mode Should only apply this |
|
281 | - * pattern when dealing with |
|
282 | - * this type of input. |
|
283 | - * @param string $special Use this mode for this one token. |
|
284 | - * @access public |
|
285 | - */ |
|
286 | - function addSpecialPattern($pattern, $mode, $special) { |
|
287 | - if (! isset($this->_regexes[$mode])) { |
|
288 | - $this->_regexes[$mode] = new ParallelRegex($this->_case); |
|
289 | - } |
|
290 | - $this->_regexes[$mode]->addPattern($pattern, "_$special"); |
|
291 | - if (! isset($this->_mode_handlers[$special])) { |
|
292 | - $this->_mode_handlers[$special] = $special; |
|
293 | - } |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Adds a mapping from a mode to another handler. |
|
298 | - * @param string $mode Mode to be remapped. |
|
299 | - * @param string $handler New target handler. |
|
300 | - * @access public |
|
301 | - */ |
|
302 | - function mapHandler($mode, $handler) { |
|
303 | - $this->_mode_handlers[$mode] = $handler; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Splits the page text into tokens. Will fail |
|
308 | - * if the handlers report an error or if no |
|
309 | - * content is consumed. If successful then each |
|
310 | - * unparsed and parsed token invokes a call to the |
|
311 | - * held listener. |
|
312 | - * @param string $raw Raw HTML text. |
|
313 | - * @return boolean True on success, else false. |
|
314 | - * @access public |
|
315 | - */ |
|
316 | - function parse($raw) { |
|
317 | - if (! isset($this->_parser)) { |
|
318 | - return false; |
|
319 | - } |
|
320 | - $length = strlen($raw); |
|
321 | - while (is_array($parsed = $this->_reduce($raw))) { |
|
322 | - list($raw, $unmatched, $matched, $mode) = $parsed; |
|
323 | - if (! $this->_dispatchTokens($unmatched, $matched, $mode)) { |
|
324 | - return false; |
|
325 | - } |
|
326 | - if ($raw === '') { |
|
327 | - return true; |
|
328 | - } |
|
329 | - if (strlen($raw) == $length) { |
|
330 | - return false; |
|
331 | - } |
|
332 | - $length = strlen($raw); |
|
333 | - } |
|
334 | - if (! $parsed) { |
|
335 | - return false; |
|
336 | - } |
|
337 | - return $this->_invokeParser($raw, LEXER_UNMATCHED); |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Sends the matched token and any leading unmatched |
|
342 | - * text to the parser changing the lexer to a new |
|
343 | - * mode if one is listed. |
|
344 | - * @param string $unmatched Unmatched leading portion. |
|
345 | - * @param string $matched Actual token match. |
|
346 | - * @param string $mode Mode after match. A boolean |
|
347 | - * false mode causes no change. |
|
348 | - * @return boolean False if there was any error |
|
349 | - * from the parser. |
|
350 | - * @access private |
|
351 | - */ |
|
352 | - function _dispatchTokens($unmatched, $matched, $mode = false) { |
|
353 | - if (! $this->_invokeParser($unmatched, LEXER_UNMATCHED)) { |
|
354 | - return false; |
|
355 | - } |
|
356 | - if (is_bool($mode)) { |
|
357 | - return $this->_invokeParser($matched, LEXER_MATCHED); |
|
358 | - } |
|
359 | - if ($this->_isModeEnd($mode)) { |
|
360 | - if (! $this->_invokeParser($matched, LEXER_EXIT)) { |
|
361 | - return false; |
|
362 | - } |
|
363 | - return $this->_mode->leave(); |
|
364 | - } |
|
365 | - if ($this->_isSpecialMode($mode)) { |
|
366 | - $this->_mode->enter($this->_decodeSpecial($mode)); |
|
367 | - if (! $this->_invokeParser($matched, LEXER_SPECIAL)) { |
|
368 | - return false; |
|
369 | - } |
|
370 | - return $this->_mode->leave(); |
|
371 | - } |
|
372 | - $this->_mode->enter($mode); |
|
373 | - return $this->_invokeParser($matched, LEXER_ENTER); |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Tests to see if the new mode is actually to leave |
|
378 | - * the current mode and pop an item from the matching |
|
379 | - * mode stack. |
|
380 | - * @param string $mode Mode to test. |
|
381 | - * @return boolean True if this is the exit mode. |
|
382 | - * @access private |
|
383 | - */ |
|
384 | - function _isModeEnd($mode) { |
|
385 | - return ($mode === "__exit"); |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Test to see if the mode is one where this mode |
|
390 | - * is entered for this token only and automatically |
|
391 | - * leaves immediately afterwoods. |
|
392 | - * @param string $mode Mode to test. |
|
393 | - * @return boolean True if this is the exit mode. |
|
394 | - * @access private |
|
395 | - */ |
|
396 | - function _isSpecialMode($mode) { |
|
397 | - return (strncmp($mode, "_", 1) == 0); |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * Strips the magic underscore marking single token |
|
402 | - * modes. |
|
403 | - * @param string $mode Mode to decode. |
|
404 | - * @return string Underlying mode name. |
|
405 | - * @access private |
|
406 | - */ |
|
407 | - function _decodeSpecial($mode) { |
|
408 | - return substr($mode, 1); |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Calls the parser method named after the current |
|
413 | - * mode. Empty content will be ignored. The lexer |
|
414 | - * has a parser handler for each mode in the lexer. |
|
415 | - * @param string $content Text parsed. |
|
416 | - * @param boolean $is_match Token is recognised rather |
|
417 | - * than unparsed data. |
|
418 | - * @access private |
|
419 | - */ |
|
420 | - function _invokeParser($content, $is_match) { |
|
421 | - if (($content === '') || ($content === false)) { |
|
422 | - return true; |
|
423 | - } |
|
424 | - $handler = $this->_mode_handlers[$this->_mode->getCurrent()]; |
|
425 | - return $this->_parser->$handler($content, $is_match); |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Tries to match a chunk of text and if successful |
|
430 | - * removes the recognised chunk and any leading |
|
431 | - * unparsed data. Empty strings will not be matched. |
|
432 | - * @param string $raw The subject to parse. This is the |
|
433 | - * content that will be eaten. |
|
434 | - * @return array/boolean Three item list of unparsed |
|
435 | - * content followed by the |
|
436 | - * recognised token and finally the |
|
437 | - * action the parser is to take. |
|
438 | - * True if no match, false if there |
|
439 | - * is a parsing error. |
|
440 | - * @access private |
|
441 | - */ |
|
442 | - function _reduce($raw) { |
|
443 | - if ($action = $this->_regexes[$this->_mode->getCurrent()]->match($raw, $match)) { |
|
444 | - $unparsed_character_count = strpos($raw, $match); |
|
445 | - $unparsed = substr($raw, 0, $unparsed_character_count); |
|
446 | - $raw = substr($raw, $unparsed_character_count + strlen($match)); |
|
447 | - return array($raw, $unparsed, $match, $action); |
|
448 | - } |
|
449 | - return true; |
|
450 | - } |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Breas HTML into SAX events. |
|
187 | + */ |
|
188 | + class SimpleLexer { |
|
189 | + protected $_regexes; |
|
190 | + protected $_parser; |
|
191 | + protected $_mode; |
|
192 | + protected $_mode_handlers; |
|
193 | + protected $_case; |
|
194 | + |
|
195 | + /** |
|
196 | + * Sets up the lexer in case insensitive matching |
|
197 | + * by default. |
|
198 | + * @param SimpleSaxParser $parser Handling strategy by |
|
199 | + * reference. |
|
200 | + * @param string $start Starting handler. |
|
201 | + * @param boolean $case True for case sensitive. |
|
202 | + * @access public |
|
203 | + */ |
|
204 | + function SimpleLexer($parser, $start = "accept", $case = false) { |
|
205 | + $this->_case = $case; |
|
206 | + $this->_regexes = array(); |
|
207 | + $this->_parser = $parser; |
|
208 | + $this->_mode = new SimpleStateStack($start); |
|
209 | + $this->_mode_handlers = array($start => $start); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Adds a token search pattern for a particular |
|
214 | + * parsing mode. The pattern does not change the |
|
215 | + * current mode. |
|
216 | + * @param string $pattern Perl style regex, but ( and ) |
|
217 | + * lose the usual meaning. |
|
218 | + * @param string $mode Should only apply this |
|
219 | + * pattern when dealing with |
|
220 | + * this type of input. |
|
221 | + * @access public |
|
222 | + */ |
|
223 | + function addPattern($pattern, $mode = "accept") { |
|
224 | + if (! isset($this->_regexes[$mode])) { |
|
225 | + $this->_regexes[$mode] = new ParallelRegex($this->_case); |
|
226 | + } |
|
227 | + $this->_regexes[$mode]->addPattern($pattern); |
|
228 | + if (! isset($this->_mode_handlers[$mode])) { |
|
229 | + $this->_mode_handlers[$mode] = $mode; |
|
230 | + } |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Adds a pattern that will enter a new parsing |
|
235 | + * mode. Useful for entering parenthesis, strings, |
|
236 | + * tags, etc. |
|
237 | + * @param string $pattern Perl style regex, but ( and ) |
|
238 | + * lose the usual meaning. |
|
239 | + * @param string $mode Should only apply this |
|
240 | + * pattern when dealing with |
|
241 | + * this type of input. |
|
242 | + * @param string $new_mode Change parsing to this new |
|
243 | + * nested mode. |
|
244 | + * @access public |
|
245 | + */ |
|
246 | + function addEntryPattern($pattern, $mode, $new_mode) { |
|
247 | + if (! isset($this->_regexes[$mode])) { |
|
248 | + $this->_regexes[$mode] = new ParallelRegex($this->_case); |
|
249 | + } |
|
250 | + $this->_regexes[$mode]->addPattern($pattern, $new_mode); |
|
251 | + if (! isset($this->_mode_handlers[$new_mode])) { |
|
252 | + $this->_mode_handlers[$new_mode] = $new_mode; |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Adds a pattern that will exit the current mode |
|
258 | + * and re-enter the previous one. |
|
259 | + * @param string $pattern Perl style regex, but ( and ) |
|
260 | + * lose the usual meaning. |
|
261 | + * @param string $mode Mode to leave. |
|
262 | + * @access public |
|
263 | + */ |
|
264 | + function addExitPattern($pattern, $mode) { |
|
265 | + if (! isset($this->_regexes[$mode])) { |
|
266 | + $this->_regexes[$mode] = new ParallelRegex($this->_case); |
|
267 | + } |
|
268 | + $this->_regexes[$mode]->addPattern($pattern, "__exit"); |
|
269 | + if (! isset($this->_mode_handlers[$mode])) { |
|
270 | + $this->_mode_handlers[$mode] = $mode; |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Adds a pattern that has a special mode. Acts as an entry |
|
276 | + * and exit pattern in one go, effectively calling a special |
|
277 | + * parser handler for this token only. |
|
278 | + * @param string $pattern Perl style regex, but ( and ) |
|
279 | + * lose the usual meaning. |
|
280 | + * @param string $mode Should only apply this |
|
281 | + * pattern when dealing with |
|
282 | + * this type of input. |
|
283 | + * @param string $special Use this mode for this one token. |
|
284 | + * @access public |
|
285 | + */ |
|
286 | + function addSpecialPattern($pattern, $mode, $special) { |
|
287 | + if (! isset($this->_regexes[$mode])) { |
|
288 | + $this->_regexes[$mode] = new ParallelRegex($this->_case); |
|
289 | + } |
|
290 | + $this->_regexes[$mode]->addPattern($pattern, "_$special"); |
|
291 | + if (! isset($this->_mode_handlers[$special])) { |
|
292 | + $this->_mode_handlers[$special] = $special; |
|
293 | + } |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Adds a mapping from a mode to another handler. |
|
298 | + * @param string $mode Mode to be remapped. |
|
299 | + * @param string $handler New target handler. |
|
300 | + * @access public |
|
301 | + */ |
|
302 | + function mapHandler($mode, $handler) { |
|
303 | + $this->_mode_handlers[$mode] = $handler; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Splits the page text into tokens. Will fail |
|
308 | + * if the handlers report an error or if no |
|
309 | + * content is consumed. If successful then each |
|
310 | + * unparsed and parsed token invokes a call to the |
|
311 | + * held listener. |
|
312 | + * @param string $raw Raw HTML text. |
|
313 | + * @return boolean True on success, else false. |
|
314 | + * @access public |
|
315 | + */ |
|
316 | + function parse($raw) { |
|
317 | + if (! isset($this->_parser)) { |
|
318 | + return false; |
|
319 | + } |
|
320 | + $length = strlen($raw); |
|
321 | + while (is_array($parsed = $this->_reduce($raw))) { |
|
322 | + list($raw, $unmatched, $matched, $mode) = $parsed; |
|
323 | + if (! $this->_dispatchTokens($unmatched, $matched, $mode)) { |
|
324 | + return false; |
|
325 | + } |
|
326 | + if ($raw === '') { |
|
327 | + return true; |
|
328 | + } |
|
329 | + if (strlen($raw) == $length) { |
|
330 | + return false; |
|
331 | + } |
|
332 | + $length = strlen($raw); |
|
333 | + } |
|
334 | + if (! $parsed) { |
|
335 | + return false; |
|
336 | + } |
|
337 | + return $this->_invokeParser($raw, LEXER_UNMATCHED); |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Sends the matched token and any leading unmatched |
|
342 | + * text to the parser changing the lexer to a new |
|
343 | + * mode if one is listed. |
|
344 | + * @param string $unmatched Unmatched leading portion. |
|
345 | + * @param string $matched Actual token match. |
|
346 | + * @param string $mode Mode after match. A boolean |
|
347 | + * false mode causes no change. |
|
348 | + * @return boolean False if there was any error |
|
349 | + * from the parser. |
|
350 | + * @access private |
|
351 | + */ |
|
352 | + function _dispatchTokens($unmatched, $matched, $mode = false) { |
|
353 | + if (! $this->_invokeParser($unmatched, LEXER_UNMATCHED)) { |
|
354 | + return false; |
|
355 | + } |
|
356 | + if (is_bool($mode)) { |
|
357 | + return $this->_invokeParser($matched, LEXER_MATCHED); |
|
358 | + } |
|
359 | + if ($this->_isModeEnd($mode)) { |
|
360 | + if (! $this->_invokeParser($matched, LEXER_EXIT)) { |
|
361 | + return false; |
|
362 | + } |
|
363 | + return $this->_mode->leave(); |
|
364 | + } |
|
365 | + if ($this->_isSpecialMode($mode)) { |
|
366 | + $this->_mode->enter($this->_decodeSpecial($mode)); |
|
367 | + if (! $this->_invokeParser($matched, LEXER_SPECIAL)) { |
|
368 | + return false; |
|
369 | + } |
|
370 | + return $this->_mode->leave(); |
|
371 | + } |
|
372 | + $this->_mode->enter($mode); |
|
373 | + return $this->_invokeParser($matched, LEXER_ENTER); |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Tests to see if the new mode is actually to leave |
|
378 | + * the current mode and pop an item from the matching |
|
379 | + * mode stack. |
|
380 | + * @param string $mode Mode to test. |
|
381 | + * @return boolean True if this is the exit mode. |
|
382 | + * @access private |
|
383 | + */ |
|
384 | + function _isModeEnd($mode) { |
|
385 | + return ($mode === "__exit"); |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Test to see if the mode is one where this mode |
|
390 | + * is entered for this token only and automatically |
|
391 | + * leaves immediately afterwoods. |
|
392 | + * @param string $mode Mode to test. |
|
393 | + * @return boolean True if this is the exit mode. |
|
394 | + * @access private |
|
395 | + */ |
|
396 | + function _isSpecialMode($mode) { |
|
397 | + return (strncmp($mode, "_", 1) == 0); |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Strips the magic underscore marking single token |
|
402 | + * modes. |
|
403 | + * @param string $mode Mode to decode. |
|
404 | + * @return string Underlying mode name. |
|
405 | + * @access private |
|
406 | + */ |
|
407 | + function _decodeSpecial($mode) { |
|
408 | + return substr($mode, 1); |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Calls the parser method named after the current |
|
413 | + * mode. Empty content will be ignored. The lexer |
|
414 | + * has a parser handler for each mode in the lexer. |
|
415 | + * @param string $content Text parsed. |
|
416 | + * @param boolean $is_match Token is recognised rather |
|
417 | + * than unparsed data. |
|
418 | + * @access private |
|
419 | + */ |
|
420 | + function _invokeParser($content, $is_match) { |
|
421 | + if (($content === '') || ($content === false)) { |
|
422 | + return true; |
|
423 | + } |
|
424 | + $handler = $this->_mode_handlers[$this->_mode->getCurrent()]; |
|
425 | + return $this->_parser->$handler($content, $is_match); |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Tries to match a chunk of text and if successful |
|
430 | + * removes the recognised chunk and any leading |
|
431 | + * unparsed data. Empty strings will not be matched. |
|
432 | + * @param string $raw The subject to parse. This is the |
|
433 | + * content that will be eaten. |
|
434 | + * @return array/boolean Three item list of unparsed |
|
435 | + * content followed by the |
|
436 | + * recognised token and finally the |
|
437 | + * action the parser is to take. |
|
438 | + * True if no match, false if there |
|
439 | + * is a parsing error. |
|
440 | + * @access private |
|
441 | + */ |
|
442 | + function _reduce($raw) { |
|
443 | + if ($action = $this->_regexes[$this->_mode->getCurrent()]->match($raw, $match)) { |
|
444 | + $unparsed_character_count = strpos($raw, $match); |
|
445 | + $unparsed = substr($raw, 0, $unparsed_character_count); |
|
446 | + $raw = substr($raw, $unparsed_character_count + strlen($match)); |
|
447 | + return array($raw, $unparsed, $match, $action); |
|
448 | + } |
|
449 | + return true; |
|
450 | + } |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Breas HTML into SAX events. |
|
455 | 455 | * @package SimpleTest |
456 | 456 | * @subpackage WebTester |
457 | - */ |
|
458 | - class SimpleHtmlLexer extends SimpleLexer { |
|
459 | - |
|
460 | - /** |
|
461 | - * Sets up the lexer with case insensitive matching |
|
462 | - * and adds the HTML handlers. |
|
463 | - * @param SimpleSaxParser $parser Handling strategy by |
|
464 | - * reference. |
|
465 | - * @access public |
|
466 | - */ |
|
467 | - function SimpleHtmlLexer($parser) { |
|
468 | - $this->SimpleLexer($parser, 'text'); |
|
469 | - $this->mapHandler('text', 'acceptTextToken'); |
|
470 | - $this->_addSkipping(); |
|
471 | - foreach ($this->_getParsedTags() as $tag) { |
|
472 | - $this->_addTag($tag); |
|
473 | - } |
|
474 | - $this->_addInTagTokens(); |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * List of parsed tags. Others are ignored. |
|
479 | - * @return array List of searched for tags. |
|
480 | - * @access private |
|
481 | - */ |
|
482 | - function _getParsedTags() { |
|
483 | - return array('a', 'title', 'form', 'input', 'button', 'textarea', 'select', |
|
484 | - 'option', 'frameset', 'frame', 'label'); |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * The lexer has to skip certain sections such |
|
489 | - * as server code, client code and styles. |
|
490 | - * @access private |
|
491 | - */ |
|
492 | - function _addSkipping() { |
|
493 | - $this->mapHandler('css', 'ignore'); |
|
494 | - $this->addEntryPattern('<style', 'text', 'css'); |
|
495 | - $this->addExitPattern('</style>', 'css'); |
|
496 | - $this->mapHandler('js', 'ignore'); |
|
497 | - $this->addEntryPattern('<script', 'text', 'js'); |
|
498 | - $this->addExitPattern('</script>', 'js'); |
|
499 | - $this->mapHandler('comment', 'ignore'); |
|
500 | - $this->addEntryPattern('<!--', 'text', 'comment'); |
|
501 | - $this->addExitPattern('-->', 'comment'); |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * Pattern matches to start and end a tag. |
|
506 | - * @param string $tag Name of tag to scan for. |
|
507 | - * @access private |
|
508 | - */ |
|
509 | - function _addTag($tag) { |
|
510 | - $this->addSpecialPattern("</$tag>", 'text', 'acceptEndToken'); |
|
511 | - $this->addEntryPattern("<$tag", 'text', 'tag'); |
|
512 | - } |
|
513 | - |
|
514 | - /** |
|
515 | - * Pattern matches to parse the inside of a tag |
|
516 | - * including the attributes and their quoting. |
|
517 | - * @access private |
|
518 | - */ |
|
519 | - function _addInTagTokens() { |
|
520 | - $this->mapHandler('tag', 'acceptStartToken'); |
|
521 | - $this->addSpecialPattern('\s+', 'tag', 'ignore'); |
|
522 | - $this->_addAttributeTokens(); |
|
523 | - $this->addExitPattern('/>', 'tag'); |
|
524 | - $this->addExitPattern('>', 'tag'); |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * Matches attributes that are either single quoted, |
|
529 | - * double quoted or unquoted. |
|
530 | - * @access private |
|
531 | - */ |
|
532 | - function _addAttributeTokens() { |
|
533 | - $this->mapHandler('dq_attribute', 'acceptAttributeToken'); |
|
534 | - $this->addEntryPattern('=\s*"', 'tag', 'dq_attribute'); |
|
535 | - $this->addPattern("\\\\\"", 'dq_attribute'); |
|
536 | - $this->addExitPattern('"', 'dq_attribute'); |
|
537 | - $this->mapHandler('sq_attribute', 'acceptAttributeToken'); |
|
538 | - $this->addEntryPattern("=\s*'", 'tag', 'sq_attribute'); |
|
539 | - $this->addPattern("\\\\'", 'sq_attribute'); |
|
540 | - $this->addExitPattern("'", 'sq_attribute'); |
|
541 | - $this->mapHandler('uq_attribute', 'acceptAttributeToken'); |
|
542 | - $this->addSpecialPattern('=\s*[^>\s]*', 'tag', 'uq_attribute'); |
|
543 | - } |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * Converts HTML tokens into selected SAX events. |
|
457 | + */ |
|
458 | + class SimpleHtmlLexer extends SimpleLexer { |
|
459 | + |
|
460 | + /** |
|
461 | + * Sets up the lexer with case insensitive matching |
|
462 | + * and adds the HTML handlers. |
|
463 | + * @param SimpleSaxParser $parser Handling strategy by |
|
464 | + * reference. |
|
465 | + * @access public |
|
466 | + */ |
|
467 | + function SimpleHtmlLexer($parser) { |
|
468 | + $this->SimpleLexer($parser, 'text'); |
|
469 | + $this->mapHandler('text', 'acceptTextToken'); |
|
470 | + $this->_addSkipping(); |
|
471 | + foreach ($this->_getParsedTags() as $tag) { |
|
472 | + $this->_addTag($tag); |
|
473 | + } |
|
474 | + $this->_addInTagTokens(); |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * List of parsed tags. Others are ignored. |
|
479 | + * @return array List of searched for tags. |
|
480 | + * @access private |
|
481 | + */ |
|
482 | + function _getParsedTags() { |
|
483 | + return array('a', 'title', 'form', 'input', 'button', 'textarea', 'select', |
|
484 | + 'option', 'frameset', 'frame', 'label'); |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * The lexer has to skip certain sections such |
|
489 | + * as server code, client code and styles. |
|
490 | + * @access private |
|
491 | + */ |
|
492 | + function _addSkipping() { |
|
493 | + $this->mapHandler('css', 'ignore'); |
|
494 | + $this->addEntryPattern('<style', 'text', 'css'); |
|
495 | + $this->addExitPattern('</style>', 'css'); |
|
496 | + $this->mapHandler('js', 'ignore'); |
|
497 | + $this->addEntryPattern('<script', 'text', 'js'); |
|
498 | + $this->addExitPattern('</script>', 'js'); |
|
499 | + $this->mapHandler('comment', 'ignore'); |
|
500 | + $this->addEntryPattern('<!--', 'text', 'comment'); |
|
501 | + $this->addExitPattern('-->', 'comment'); |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * Pattern matches to start and end a tag. |
|
506 | + * @param string $tag Name of tag to scan for. |
|
507 | + * @access private |
|
508 | + */ |
|
509 | + function _addTag($tag) { |
|
510 | + $this->addSpecialPattern("</$tag>", 'text', 'acceptEndToken'); |
|
511 | + $this->addEntryPattern("<$tag", 'text', 'tag'); |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * Pattern matches to parse the inside of a tag |
|
516 | + * including the attributes and their quoting. |
|
517 | + * @access private |
|
518 | + */ |
|
519 | + function _addInTagTokens() { |
|
520 | + $this->mapHandler('tag', 'acceptStartToken'); |
|
521 | + $this->addSpecialPattern('\s+', 'tag', 'ignore'); |
|
522 | + $this->_addAttributeTokens(); |
|
523 | + $this->addExitPattern('/>', 'tag'); |
|
524 | + $this->addExitPattern('>', 'tag'); |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * Matches attributes that are either single quoted, |
|
529 | + * double quoted or unquoted. |
|
530 | + * @access private |
|
531 | + */ |
|
532 | + function _addAttributeTokens() { |
|
533 | + $this->mapHandler('dq_attribute', 'acceptAttributeToken'); |
|
534 | + $this->addEntryPattern('=\s*"', 'tag', 'dq_attribute'); |
|
535 | + $this->addPattern("\\\\\"", 'dq_attribute'); |
|
536 | + $this->addExitPattern('"', 'dq_attribute'); |
|
537 | + $this->mapHandler('sq_attribute', 'acceptAttributeToken'); |
|
538 | + $this->addEntryPattern("=\s*'", 'tag', 'sq_attribute'); |
|
539 | + $this->addPattern("\\\\'", 'sq_attribute'); |
|
540 | + $this->addExitPattern("'", 'sq_attribute'); |
|
541 | + $this->mapHandler('uq_attribute', 'acceptAttributeToken'); |
|
542 | + $this->addSpecialPattern('=\s*[^>\s]*', 'tag', 'uq_attribute'); |
|
543 | + } |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * Converts HTML tokens into selected SAX events. |
|
548 | 548 | * @package SimpleTest |
549 | 549 | * @subpackage WebTester |
550 | - */ |
|
551 | - class SimpleHtmlSaxParser { |
|
552 | - protected $_lexer; |
|
553 | - protected $_listener; |
|
554 | - protected $_tag; |
|
555 | - protected $_attributes; |
|
556 | - protected $_current_attribute; |
|
557 | - |
|
558 | - /** |
|
559 | - * Sets the listener. |
|
560 | - * @param SimpleSaxListener $listener SAX event handler. |
|
561 | - * @access public |
|
562 | - */ |
|
563 | - function SimpleHtmlSaxParser($listener) { |
|
564 | - $this->_listener = $listener; |
|
565 | - $this->_lexer = $this->createLexer($this); |
|
566 | - $this->_tag = ''; |
|
567 | - $this->_attributes = array(); |
|
568 | - $this->_current_attribute = ''; |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Runs the content through the lexer which |
|
573 | - * should call back to the acceptors. |
|
574 | - * @param string $raw Page text to parse. |
|
575 | - * @return boolean False if parse error. |
|
576 | - * @access public |
|
577 | - */ |
|
578 | - function parse($raw) { |
|
579 | - return $this->_lexer->parse($raw); |
|
580 | - } |
|
581 | - |
|
582 | - /** |
|
583 | - * Sets up the matching lexer. Starts in 'text' mode. |
|
584 | - * @param SimpleSaxParser $parser Event generator, usually $self. |
|
585 | - * @return SimpleLexer Lexer suitable for this parser. |
|
586 | - * @access public |
|
587 | - * @static |
|
588 | - */ |
|
589 | - static function &createLexer($parser) { |
|
590 | - $lexer = new SimpleHtmlLexer($parser); |
|
591 | - return $lexer; |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * Accepts a token from the tag mode. If the |
|
596 | - * starting element completes then the element |
|
597 | - * is dispatched and the current attributes |
|
598 | - * set back to empty. The element or attribute |
|
599 | - * name is converted to lower case. |
|
600 | - * @param string $token Incoming characters. |
|
601 | - * @param integer $event Lexer event type. |
|
602 | - * @return boolean False if parse error. |
|
603 | - * @access public |
|
604 | - */ |
|
605 | - function acceptStartToken($token, $event) { |
|
606 | - if ($event == LEXER_ENTER) { |
|
607 | - $this->_tag = strtolower(substr($token, 1)); |
|
608 | - return true; |
|
609 | - } |
|
610 | - if ($event == LEXER_EXIT) { |
|
611 | - $success = $this->_listener->startElement( |
|
612 | - $this->_tag, |
|
613 | - $this->_attributes); |
|
614 | - $this->_tag = ''; |
|
615 | - $this->_attributes = array(); |
|
616 | - return $success; |
|
617 | - } |
|
618 | - if ($token != '=') { |
|
619 | - $this->_current_attribute = strtolower(SimpleHtmlSaxParser::decodeHtml($token)); |
|
620 | - $this->_attributes[$this->_current_attribute] = ''; |
|
621 | - } |
|
622 | - return true; |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Accepts a token from the end tag mode. |
|
627 | - * The element name is converted to lower case. |
|
628 | - * @param string $token Incoming characters. |
|
629 | - * @param integer $event Lexer event type. |
|
630 | - * @return boolean False if parse error. |
|
631 | - * @access public |
|
632 | - */ |
|
633 | - function acceptEndToken($token, $event) { |
|
634 | - if (! preg_match('/<\/(.*)>/', $token, $matches)) { |
|
635 | - return false; |
|
636 | - } |
|
637 | - return $this->_listener->endElement(strtolower($matches[1])); |
|
638 | - } |
|
639 | - |
|
640 | - /** |
|
641 | - * Part of the tag data. |
|
642 | - * @param string $token Incoming characters. |
|
643 | - * @param integer $event Lexer event type. |
|
644 | - * @return boolean False if parse error. |
|
645 | - * @access public |
|
646 | - */ |
|
647 | - function acceptAttributeToken($token, $event) { |
|
648 | - if ($event == LEXER_UNMATCHED) { |
|
649 | - $this->_attributes[$this->_current_attribute] .= |
|
650 | - SimpleHtmlSaxParser::decodeHtml($token); |
|
651 | - } |
|
652 | - if ($event == LEXER_SPECIAL) { |
|
653 | - $this->_attributes[$this->_current_attribute] .= |
|
654 | - preg_replace('/^=\s*/' , '', SimpleHtmlSaxParser::decodeHtml($token)); |
|
655 | - } |
|
656 | - return true; |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * A character entity. |
|
661 | - * @param string $token Incoming characters. |
|
662 | - * @param integer $event Lexer event type. |
|
663 | - * @return boolean False if parse error. |
|
664 | - * @access public |
|
665 | - */ |
|
666 | - function acceptEntityToken($token, $event) { |
|
667 | - } |
|
668 | - |
|
669 | - /** |
|
670 | - * Character data between tags regarded as |
|
671 | - * important. |
|
672 | - * @param string $token Incoming characters. |
|
673 | - * @param integer $event Lexer event type. |
|
674 | - * @return boolean False if parse error. |
|
675 | - * @access public |
|
676 | - */ |
|
677 | - function acceptTextToken($token, $event) { |
|
678 | - return $this->_listener->addContent($token); |
|
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * Incoming data to be ignored. |
|
683 | - * @param string $token Incoming characters. |
|
684 | - * @param integer $event Lexer event type. |
|
685 | - * @return boolean False if parse error. |
|
686 | - * @access public |
|
687 | - */ |
|
688 | - function ignore($token, $event) { |
|
689 | - return true; |
|
690 | - } |
|
691 | - |
|
692 | - /** |
|
693 | - * Decodes any HTML entities. |
|
694 | - * @param string $html Incoming HTML. |
|
695 | - * @return string Outgoing plain text. |
|
696 | - * @access public |
|
697 | - * @static |
|
698 | - */ |
|
699 | - static function decodeHtml($html) { |
|
700 | - static $translations; |
|
701 | - if (! isset($translations)) { |
|
702 | - $translations = array_flip(get_html_translation_table(HTML_ENTITIES)); |
|
703 | - } |
|
704 | - return strtr($html, $translations); |
|
705 | - } |
|
706 | - |
|
707 | - /** |
|
708 | - * Turns HTML into text browser visible text. Images |
|
709 | - * are converted to their alt text and tags are supressed. |
|
710 | - * Entities are converted to their visible representation. |
|
711 | - * @param string $html HTML to convert. |
|
712 | - * @return string Plain text. |
|
713 | - * @access public |
|
714 | - * @static |
|
715 | - */ |
|
716 | - static function normalise($html) { |
|
717 | - $text = preg_replace('|<!--.*?-->|', '', $html); |
|
718 | - $text = preg_replace('|<img.*?alt\s*=\s*"(.*?)".*?>|', ' \1 ', $text); |
|
719 | - $text = preg_replace('|<img.*?alt\s*=\s*\'(.*?)\'.*?>|', ' \1 ', $text); |
|
720 | - $text = preg_replace('|<img.*?alt\s*=\s*([a-zA-Z_]+).*?>|', ' \1 ', $text); |
|
721 | - $text = preg_replace('|<.*?>|', '', $text); |
|
722 | - $text = SimpleHtmlSaxParser::decodeHtml($text); |
|
723 | - $text = preg_replace('|\s+|', ' ', $text); |
|
724 | - return trim($text); |
|
725 | - } |
|
726 | - } |
|
727 | - |
|
728 | - /** |
|
729 | - * SAX event handler. |
|
550 | + */ |
|
551 | + class SimpleHtmlSaxParser { |
|
552 | + protected $_lexer; |
|
553 | + protected $_listener; |
|
554 | + protected $_tag; |
|
555 | + protected $_attributes; |
|
556 | + protected $_current_attribute; |
|
557 | + |
|
558 | + /** |
|
559 | + * Sets the listener. |
|
560 | + * @param SimpleSaxListener $listener SAX event handler. |
|
561 | + * @access public |
|
562 | + */ |
|
563 | + function SimpleHtmlSaxParser($listener) { |
|
564 | + $this->_listener = $listener; |
|
565 | + $this->_lexer = $this->createLexer($this); |
|
566 | + $this->_tag = ''; |
|
567 | + $this->_attributes = array(); |
|
568 | + $this->_current_attribute = ''; |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Runs the content through the lexer which |
|
573 | + * should call back to the acceptors. |
|
574 | + * @param string $raw Page text to parse. |
|
575 | + * @return boolean False if parse error. |
|
576 | + * @access public |
|
577 | + */ |
|
578 | + function parse($raw) { |
|
579 | + return $this->_lexer->parse($raw); |
|
580 | + } |
|
581 | + |
|
582 | + /** |
|
583 | + * Sets up the matching lexer. Starts in 'text' mode. |
|
584 | + * @param SimpleSaxParser $parser Event generator, usually $self. |
|
585 | + * @return SimpleLexer Lexer suitable for this parser. |
|
586 | + * @access public |
|
587 | + * @static |
|
588 | + */ |
|
589 | + static function &createLexer($parser) { |
|
590 | + $lexer = new SimpleHtmlLexer($parser); |
|
591 | + return $lexer; |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Accepts a token from the tag mode. If the |
|
596 | + * starting element completes then the element |
|
597 | + * is dispatched and the current attributes |
|
598 | + * set back to empty. The element or attribute |
|
599 | + * name is converted to lower case. |
|
600 | + * @param string $token Incoming characters. |
|
601 | + * @param integer $event Lexer event type. |
|
602 | + * @return boolean False if parse error. |
|
603 | + * @access public |
|
604 | + */ |
|
605 | + function acceptStartToken($token, $event) { |
|
606 | + if ($event == LEXER_ENTER) { |
|
607 | + $this->_tag = strtolower(substr($token, 1)); |
|
608 | + return true; |
|
609 | + } |
|
610 | + if ($event == LEXER_EXIT) { |
|
611 | + $success = $this->_listener->startElement( |
|
612 | + $this->_tag, |
|
613 | + $this->_attributes); |
|
614 | + $this->_tag = ''; |
|
615 | + $this->_attributes = array(); |
|
616 | + return $success; |
|
617 | + } |
|
618 | + if ($token != '=') { |
|
619 | + $this->_current_attribute = strtolower(SimpleHtmlSaxParser::decodeHtml($token)); |
|
620 | + $this->_attributes[$this->_current_attribute] = ''; |
|
621 | + } |
|
622 | + return true; |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * Accepts a token from the end tag mode. |
|
627 | + * The element name is converted to lower case. |
|
628 | + * @param string $token Incoming characters. |
|
629 | + * @param integer $event Lexer event type. |
|
630 | + * @return boolean False if parse error. |
|
631 | + * @access public |
|
632 | + */ |
|
633 | + function acceptEndToken($token, $event) { |
|
634 | + if (! preg_match('/<\/(.*)>/', $token, $matches)) { |
|
635 | + return false; |
|
636 | + } |
|
637 | + return $this->_listener->endElement(strtolower($matches[1])); |
|
638 | + } |
|
639 | + |
|
640 | + /** |
|
641 | + * Part of the tag data. |
|
642 | + * @param string $token Incoming characters. |
|
643 | + * @param integer $event Lexer event type. |
|
644 | + * @return boolean False if parse error. |
|
645 | + * @access public |
|
646 | + */ |
|
647 | + function acceptAttributeToken($token, $event) { |
|
648 | + if ($event == LEXER_UNMATCHED) { |
|
649 | + $this->_attributes[$this->_current_attribute] .= |
|
650 | + SimpleHtmlSaxParser::decodeHtml($token); |
|
651 | + } |
|
652 | + if ($event == LEXER_SPECIAL) { |
|
653 | + $this->_attributes[$this->_current_attribute] .= |
|
654 | + preg_replace('/^=\s*/' , '', SimpleHtmlSaxParser::decodeHtml($token)); |
|
655 | + } |
|
656 | + return true; |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * A character entity. |
|
661 | + * @param string $token Incoming characters. |
|
662 | + * @param integer $event Lexer event type. |
|
663 | + * @return boolean False if parse error. |
|
664 | + * @access public |
|
665 | + */ |
|
666 | + function acceptEntityToken($token, $event) { |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * Character data between tags regarded as |
|
671 | + * important. |
|
672 | + * @param string $token Incoming characters. |
|
673 | + * @param integer $event Lexer event type. |
|
674 | + * @return boolean False if parse error. |
|
675 | + * @access public |
|
676 | + */ |
|
677 | + function acceptTextToken($token, $event) { |
|
678 | + return $this->_listener->addContent($token); |
|
679 | + } |
|
680 | + |
|
681 | + /** |
|
682 | + * Incoming data to be ignored. |
|
683 | + * @param string $token Incoming characters. |
|
684 | + * @param integer $event Lexer event type. |
|
685 | + * @return boolean False if parse error. |
|
686 | + * @access public |
|
687 | + */ |
|
688 | + function ignore($token, $event) { |
|
689 | + return true; |
|
690 | + } |
|
691 | + |
|
692 | + /** |
|
693 | + * Decodes any HTML entities. |
|
694 | + * @param string $html Incoming HTML. |
|
695 | + * @return string Outgoing plain text. |
|
696 | + * @access public |
|
697 | + * @static |
|
698 | + */ |
|
699 | + static function decodeHtml($html) { |
|
700 | + static $translations; |
|
701 | + if (! isset($translations)) { |
|
702 | + $translations = array_flip(get_html_translation_table(HTML_ENTITIES)); |
|
703 | + } |
|
704 | + return strtr($html, $translations); |
|
705 | + } |
|
706 | + |
|
707 | + /** |
|
708 | + * Turns HTML into text browser visible text. Images |
|
709 | + * are converted to their alt text and tags are supressed. |
|
710 | + * Entities are converted to their visible representation. |
|
711 | + * @param string $html HTML to convert. |
|
712 | + * @return string Plain text. |
|
713 | + * @access public |
|
714 | + * @static |
|
715 | + */ |
|
716 | + static function normalise($html) { |
|
717 | + $text = preg_replace('|<!--.*?-->|', '', $html); |
|
718 | + $text = preg_replace('|<img.*?alt\s*=\s*"(.*?)".*?>|', ' \1 ', $text); |
|
719 | + $text = preg_replace('|<img.*?alt\s*=\s*\'(.*?)\'.*?>|', ' \1 ', $text); |
|
720 | + $text = preg_replace('|<img.*?alt\s*=\s*([a-zA-Z_]+).*?>|', ' \1 ', $text); |
|
721 | + $text = preg_replace('|<.*?>|', '', $text); |
|
722 | + $text = SimpleHtmlSaxParser::decodeHtml($text); |
|
723 | + $text = preg_replace('|\s+|', ' ', $text); |
|
724 | + return trim($text); |
|
725 | + } |
|
726 | + } |
|
727 | + |
|
728 | + /** |
|
729 | + * SAX event handler. |
|
730 | 730 | * @package SimpleTest |
731 | 731 | * @subpackage WebTester |
732 | - * @abstract |
|
733 | - */ |
|
734 | - class SimpleSaxListener { |
|
735 | - |
|
736 | - /** |
|
737 | - * Sets the document to write to. |
|
738 | - * @access public |
|
739 | - */ |
|
740 | - function SimpleSaxListener() { |
|
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Start of element event. |
|
745 | - * @param string $name Element name. |
|
746 | - * @param hash $attributes Name value pairs. |
|
747 | - * Attributes without content |
|
748 | - * are marked as true. |
|
749 | - * @return boolean False on parse error. |
|
750 | - * @access public |
|
751 | - */ |
|
752 | - function startElement($name, $attributes) { |
|
753 | - } |
|
754 | - |
|
755 | - /** |
|
756 | - * End of element event. |
|
757 | - * @param string $name Element name. |
|
758 | - * @return boolean False on parse error. |
|
759 | - * @access public |
|
760 | - */ |
|
761 | - function endElement($name) { |
|
762 | - } |
|
763 | - |
|
764 | - /** |
|
765 | - * Unparsed, but relevant data. |
|
766 | - * @param string $text May include unparsed tags. |
|
767 | - * @return boolean False on parse error. |
|
768 | - * @access public |
|
769 | - */ |
|
770 | - function addContent($text) { |
|
771 | - } |
|
772 | - } |
|
773 | 732 | \ No newline at end of file |
733 | + * @abstract |
|
734 | + */ |
|
735 | + class SimpleSaxListener { |
|
736 | + |
|
737 | + /** |
|
738 | + * Sets the document to write to. |
|
739 | + * @access public |
|
740 | + */ |
|
741 | + function SimpleSaxListener() { |
|
742 | + } |
|
743 | + |
|
744 | + /** |
|
745 | + * Start of element event. |
|
746 | + * @param string $name Element name. |
|
747 | + * @param hash $attributes Name value pairs. |
|
748 | + * Attributes without content |
|
749 | + * are marked as true. |
|
750 | + * @return boolean False on parse error. |
|
751 | + * @access public |
|
752 | + */ |
|
753 | + function startElement($name, $attributes) { |
|
754 | + } |
|
755 | + |
|
756 | + /** |
|
757 | + * End of element event. |
|
758 | + * @param string $name Element name. |
|
759 | + * @return boolean False on parse error. |
|
760 | + * @access public |
|
761 | + */ |
|
762 | + function endElement($name) { |
|
763 | + } |
|
764 | + |
|
765 | + /** |
|
766 | + * Unparsed, but relevant data. |
|
767 | + * @param string $text May include unparsed tags. |
|
768 | + * @return boolean False on parse error. |
|
769 | + * @access public |
|
770 | + */ |
|
771 | + function addContent($text) { |
|
772 | + } |
|
773 | + } |
|
774 | 774 | \ No newline at end of file |
@@ -9,19 +9,19 @@ discard block |
||
9 | 9 | /**#@+ |
10 | 10 | * Lexer mode stack constants |
11 | 11 | */ |
12 | - if (! defined('LEXER_ENTER')) { |
|
12 | + if (!defined('LEXER_ENTER')) { |
|
13 | 13 | define('LEXER_ENTER', 1); |
14 | 14 | } |
15 | - if (! defined('LEXER_MATCHED')) { |
|
15 | + if (!defined('LEXER_MATCHED')) { |
|
16 | 16 | define('LEXER_MATCHED', 2); |
17 | 17 | } |
18 | - if (! defined('LEXER_UNMATCHED')) { |
|
18 | + if (!defined('LEXER_UNMATCHED')) { |
|
19 | 19 | define('LEXER_UNMATCHED', 3); |
20 | 20 | } |
21 | - if (! defined('LEXER_EXIT')) { |
|
21 | + if (!defined('LEXER_EXIT')) { |
|
22 | 22 | define('LEXER_EXIT', 4); |
23 | 23 | } |
24 | - if (! defined('LEXER_SPECIAL')) { |
|
24 | + if (!defined('LEXER_SPECIAL')) { |
|
25 | 25 | define('LEXER_SPECIAL', 5); |
26 | 26 | } |
27 | 27 | /**#@-*/ |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | if (count($this->_patterns) == 0) { |
81 | 81 | return false; |
82 | 82 | } |
83 | - if (! preg_match($this->_getCompoundedRegex(), $subject, $matches)) { |
|
83 | + if (!preg_match($this->_getCompoundedRegex(), $subject, $matches)) { |
|
84 | 84 | $match = ''; |
85 | 85 | return false; |
86 | 86 | } |
@@ -221,11 +221,11 @@ discard block |
||
221 | 221 | * @access public |
222 | 222 | */ |
223 | 223 | function addPattern($pattern, $mode = "accept") { |
224 | - if (! isset($this->_regexes[$mode])) { |
|
224 | + if (!isset($this->_regexes[$mode])) { |
|
225 | 225 | $this->_regexes[$mode] = new ParallelRegex($this->_case); |
226 | 226 | } |
227 | 227 | $this->_regexes[$mode]->addPattern($pattern); |
228 | - if (! isset($this->_mode_handlers[$mode])) { |
|
228 | + if (!isset($this->_mode_handlers[$mode])) { |
|
229 | 229 | $this->_mode_handlers[$mode] = $mode; |
230 | 230 | } |
231 | 231 | } |
@@ -244,11 +244,11 @@ discard block |
||
244 | 244 | * @access public |
245 | 245 | */ |
246 | 246 | function addEntryPattern($pattern, $mode, $new_mode) { |
247 | - if (! isset($this->_regexes[$mode])) { |
|
247 | + if (!isset($this->_regexes[$mode])) { |
|
248 | 248 | $this->_regexes[$mode] = new ParallelRegex($this->_case); |
249 | 249 | } |
250 | 250 | $this->_regexes[$mode]->addPattern($pattern, $new_mode); |
251 | - if (! isset($this->_mode_handlers[$new_mode])) { |
|
251 | + if (!isset($this->_mode_handlers[$new_mode])) { |
|
252 | 252 | $this->_mode_handlers[$new_mode] = $new_mode; |
253 | 253 | } |
254 | 254 | } |
@@ -262,11 +262,11 @@ discard block |
||
262 | 262 | * @access public |
263 | 263 | */ |
264 | 264 | function addExitPattern($pattern, $mode) { |
265 | - if (! isset($this->_regexes[$mode])) { |
|
265 | + if (!isset($this->_regexes[$mode])) { |
|
266 | 266 | $this->_regexes[$mode] = new ParallelRegex($this->_case); |
267 | 267 | } |
268 | 268 | $this->_regexes[$mode]->addPattern($pattern, "__exit"); |
269 | - if (! isset($this->_mode_handlers[$mode])) { |
|
269 | + if (!isset($this->_mode_handlers[$mode])) { |
|
270 | 270 | $this->_mode_handlers[$mode] = $mode; |
271 | 271 | } |
272 | 272 | } |
@@ -284,11 +284,11 @@ discard block |
||
284 | 284 | * @access public |
285 | 285 | */ |
286 | 286 | function addSpecialPattern($pattern, $mode, $special) { |
287 | - if (! isset($this->_regexes[$mode])) { |
|
287 | + if (!isset($this->_regexes[$mode])) { |
|
288 | 288 | $this->_regexes[$mode] = new ParallelRegex($this->_case); |
289 | 289 | } |
290 | 290 | $this->_regexes[$mode]->addPattern($pattern, "_$special"); |
291 | - if (! isset($this->_mode_handlers[$special])) { |
|
291 | + if (!isset($this->_mode_handlers[$special])) { |
|
292 | 292 | $this->_mode_handlers[$special] = $special; |
293 | 293 | } |
294 | 294 | } |
@@ -314,13 +314,13 @@ discard block |
||
314 | 314 | * @access public |
315 | 315 | */ |
316 | 316 | function parse($raw) { |
317 | - if (! isset($this->_parser)) { |
|
317 | + if (!isset($this->_parser)) { |
|
318 | 318 | return false; |
319 | 319 | } |
320 | 320 | $length = strlen($raw); |
321 | 321 | while (is_array($parsed = $this->_reduce($raw))) { |
322 | 322 | list($raw, $unmatched, $matched, $mode) = $parsed; |
323 | - if (! $this->_dispatchTokens($unmatched, $matched, $mode)) { |
|
323 | + if (!$this->_dispatchTokens($unmatched, $matched, $mode)) { |
|
324 | 324 | return false; |
325 | 325 | } |
326 | 326 | if ($raw === '') { |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | } |
332 | 332 | $length = strlen($raw); |
333 | 333 | } |
334 | - if (! $parsed) { |
|
334 | + if (!$parsed) { |
|
335 | 335 | return false; |
336 | 336 | } |
337 | 337 | return $this->_invokeParser($raw, LEXER_UNMATCHED); |
@@ -350,21 +350,21 @@ discard block |
||
350 | 350 | * @access private |
351 | 351 | */ |
352 | 352 | function _dispatchTokens($unmatched, $matched, $mode = false) { |
353 | - if (! $this->_invokeParser($unmatched, LEXER_UNMATCHED)) { |
|
353 | + if (!$this->_invokeParser($unmatched, LEXER_UNMATCHED)) { |
|
354 | 354 | return false; |
355 | 355 | } |
356 | 356 | if (is_bool($mode)) { |
357 | 357 | return $this->_invokeParser($matched, LEXER_MATCHED); |
358 | 358 | } |
359 | 359 | if ($this->_isModeEnd($mode)) { |
360 | - if (! $this->_invokeParser($matched, LEXER_EXIT)) { |
|
360 | + if (!$this->_invokeParser($matched, LEXER_EXIT)) { |
|
361 | 361 | return false; |
362 | 362 | } |
363 | 363 | return $this->_mode->leave(); |
364 | 364 | } |
365 | 365 | if ($this->_isSpecialMode($mode)) { |
366 | 366 | $this->_mode->enter($this->_decodeSpecial($mode)); |
367 | - if (! $this->_invokeParser($matched, LEXER_SPECIAL)) { |
|
367 | + if (!$this->_invokeParser($matched, LEXER_SPECIAL)) { |
|
368 | 368 | return false; |
369 | 369 | } |
370 | 370 | return $this->_mode->leave(); |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | * @access public |
632 | 632 | */ |
633 | 633 | function acceptEndToken($token, $event) { |
634 | - if (! preg_match('/<\/(.*)>/', $token, $matches)) { |
|
634 | + if (!preg_match('/<\/(.*)>/', $token, $matches)) { |
|
635 | 635 | return false; |
636 | 636 | } |
637 | 637 | return $this->_listener->endElement(strtolower($matches[1])); |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | } |
652 | 652 | if ($event == LEXER_SPECIAL) { |
653 | 653 | $this->_attributes[$this->_current_attribute] .= |
654 | - preg_replace('/^=\s*/' , '', SimpleHtmlSaxParser::decodeHtml($token)); |
|
654 | + preg_replace('/^=\s*/', '', SimpleHtmlSaxParser::decodeHtml($token)); |
|
655 | 655 | } |
656 | 656 | return true; |
657 | 657 | } |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | */ |
699 | 699 | static function decodeHtml($html) { |
700 | 700 | static $translations; |
701 | - if (! isset($translations)) { |
|
701 | + if (!isset($translations)) { |
|
702 | 702 | $translations = array_flip(get_html_translation_table(HTML_ENTITIES)); |
703 | 703 | } |
704 | 704 | return strtr($html, $translations); |
@@ -87,6 +87,7 @@ |
||
87 | 87 | * Finds the parent class name. |
88 | 88 | * @returns string Parent class name. |
89 | 89 | * @access public |
90 | + * @return string |
|
90 | 91 | */ |
91 | 92 | function getParent() { |
92 | 93 | return strtolower(get_parent_class($this->_interface)); |
@@ -1,114 +1,114 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage UnitTester |
|
6 | - * @version $Id: reflection_php4.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | - */ |
|
2 | + /** |
|
3 | + * base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage UnitTester |
|
6 | + * @version $Id: reflection_php4.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | + */ |
|
8 | 8 | |
9 | - /** |
|
10 | - * Version specific reflection API. |
|
9 | + /** |
|
10 | + * Version specific reflection API. |
|
11 | 11 | * @package SimpleTest |
12 | 12 | * @subpackage UnitTester |
13 | - */ |
|
14 | - class SimpleReflection { |
|
15 | - protected $_interface; |
|
13 | + */ |
|
14 | + class SimpleReflection { |
|
15 | + protected $_interface; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Stashes the class/interface. |
|
19 | - * @param string $interface Class or interface |
|
20 | - * to inspect. |
|
21 | - */ |
|
22 | - function SimpleReflection($interface) { |
|
23 | - $this->_interface = $interface; |
|
24 | - } |
|
17 | + /** |
|
18 | + * Stashes the class/interface. |
|
19 | + * @param string $interface Class or interface |
|
20 | + * to inspect. |
|
21 | + */ |
|
22 | + function SimpleReflection($interface) { |
|
23 | + $this->_interface = $interface; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Checks that a class has been declared. |
|
28 | - * @return boolean True if defined. |
|
29 | - * @access public |
|
30 | - */ |
|
31 | - function classExists() { |
|
32 | - return class_exists($this->_interface); |
|
33 | - } |
|
26 | + /** |
|
27 | + * Checks that a class has been declared. |
|
28 | + * @return boolean True if defined. |
|
29 | + * @access public |
|
30 | + */ |
|
31 | + function classExists() { |
|
32 | + return class_exists($this->_interface); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Needed to kill the autoload feature in PHP5 |
|
37 | - * for classes created dynamically. |
|
38 | - * @return boolean True if defined. |
|
39 | - * @access public |
|
40 | - */ |
|
41 | - function classExistsSansAutoload() { |
|
42 | - return class_exists($this->_interface); |
|
43 | - } |
|
35 | + /** |
|
36 | + * Needed to kill the autoload feature in PHP5 |
|
37 | + * for classes created dynamically. |
|
38 | + * @return boolean True if defined. |
|
39 | + * @access public |
|
40 | + */ |
|
41 | + function classExistsSansAutoload() { |
|
42 | + return class_exists($this->_interface); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Checks that a class or interface has been |
|
47 | - * declared. |
|
48 | - * @return boolean True if defined. |
|
49 | - * @access public |
|
50 | - */ |
|
51 | - function classOrInterfaceExists() { |
|
52 | - return class_exists($this->_interface); |
|
53 | - } |
|
45 | + /** |
|
46 | + * Checks that a class or interface has been |
|
47 | + * declared. |
|
48 | + * @return boolean True if defined. |
|
49 | + * @access public |
|
50 | + */ |
|
51 | + function classOrInterfaceExists() { |
|
52 | + return class_exists($this->_interface); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Needed to kill the autoload feature in PHP5 |
|
57 | - * for classes created dynamically. |
|
58 | - * @return boolean True if defined. |
|
59 | - * @access public |
|
60 | - */ |
|
61 | - function classOrInterfaceExistsSansAutoload() { |
|
62 | - return class_exists($this->_interface); |
|
63 | - } |
|
55 | + /** |
|
56 | + * Needed to kill the autoload feature in PHP5 |
|
57 | + * for classes created dynamically. |
|
58 | + * @return boolean True if defined. |
|
59 | + * @access public |
|
60 | + */ |
|
61 | + function classOrInterfaceExistsSansAutoload() { |
|
62 | + return class_exists($this->_interface); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Gets the list of methods on a class or |
|
67 | - * interface. |
|
68 | - * @returns array List of method names. |
|
69 | - * @access public |
|
70 | - */ |
|
71 | - function getMethods() { |
|
72 | - return get_class_methods($this->_interface); |
|
73 | - } |
|
65 | + /** |
|
66 | + * Gets the list of methods on a class or |
|
67 | + * interface. |
|
68 | + * @returns array List of method names. |
|
69 | + * @access public |
|
70 | + */ |
|
71 | + function getMethods() { |
|
72 | + return get_class_methods($this->_interface); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Gets the list of interfaces from a class. If the |
|
77 | - * class name is actually an interface then just that |
|
78 | - * interface is returned. |
|
79 | - * @returns array List of interfaces. |
|
80 | - * @access public |
|
81 | - */ |
|
82 | - function getInterfaces() { |
|
83 | - return array(); |
|
84 | - } |
|
75 | + /** |
|
76 | + * Gets the list of interfaces from a class. If the |
|
77 | + * class name is actually an interface then just that |
|
78 | + * interface is returned. |
|
79 | + * @returns array List of interfaces. |
|
80 | + * @access public |
|
81 | + */ |
|
82 | + function getInterfaces() { |
|
83 | + return array(); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Finds the parent class name. |
|
88 | - * @returns string Parent class name. |
|
89 | - * @access public |
|
90 | - */ |
|
91 | - function getParent() { |
|
92 | - return strtolower(get_parent_class($this->_interface)); |
|
93 | - } |
|
86 | + /** |
|
87 | + * Finds the parent class name. |
|
88 | + * @returns string Parent class name. |
|
89 | + * @access public |
|
90 | + */ |
|
91 | + function getParent() { |
|
92 | + return strtolower(get_parent_class($this->_interface)); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Determines if the class is abstract, which for PHP 4 |
|
97 | - * will never be the case. |
|
98 | - * @returns boolean True if abstract. |
|
99 | - * @access public |
|
100 | - */ |
|
101 | - function isAbstract() { |
|
102 | - return false; |
|
103 | - } |
|
95 | + /** |
|
96 | + * Determines if the class is abstract, which for PHP 4 |
|
97 | + * will never be the case. |
|
98 | + * @returns boolean True if abstract. |
|
99 | + * @access public |
|
100 | + */ |
|
101 | + function isAbstract() { |
|
102 | + return false; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Gets the source code matching the declaration |
|
107 | - * of a method. |
|
108 | - * @param string $method Method name. |
|
109 | - * @access public |
|
110 | - */ |
|
111 | - function getSignature($method) { |
|
112 | - return "function $method()"; |
|
113 | - } |
|
114 | - } |
|
115 | 105 | \ No newline at end of file |
106 | + /** |
|
107 | + * Gets the source code matching the declaration |
|
108 | + * of a method. |
|
109 | + * @param string $method Method name. |
|
110 | + * @access public |
|
111 | + */ |
|
112 | + function getSignature($method) { |
|
113 | + return "function $method()"; |
|
114 | + } |
|
115 | + } |
|
116 | 116 | \ No newline at end of file |
@@ -81,7 +81,7 @@ |
||
81 | 81 | /** |
82 | 82 | * Creates the XML parser. |
83 | 83 | * @param SimpleReporter $reporter Target of test results. |
84 | - * @return SimpleTestXmlListener XML reader. |
|
84 | + * @return SimpleTestXmlParser XML reader. |
|
85 | 85 | * @access protected |
86 | 86 | */ |
87 | 87 | function &_createParser($reporter) { |
@@ -1,114 +1,114 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage UnitTester |
|
6 | - * @version $Id: remote.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | - */ |
|
2 | + /** |
|
3 | + * base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage UnitTester |
|
6 | + * @version $Id: remote.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | + */ |
|
8 | 8 | |
9 | - /**#@+ |
|
9 | + /**#@+ |
|
10 | 10 | * include other SimpleTest class files |
11 | 11 | */ |
12 | - require_once(dirname(__FILE__) . '/browser.php'); |
|
13 | - require_once(dirname(__FILE__) . '/xml.php'); |
|
14 | - require_once(dirname(__FILE__) . '/test_case.php'); |
|
15 | - /**#@-*/ |
|
12 | + require_once(dirname(__FILE__) . '/browser.php'); |
|
13 | + require_once(dirname(__FILE__) . '/xml.php'); |
|
14 | + require_once(dirname(__FILE__) . '/test_case.php'); |
|
15 | + /**#@-*/ |
|
16 | 16 | |
17 | - /** |
|
18 | - * Runs an XML formated test on a remote server. |
|
17 | + /** |
|
18 | + * Runs an XML formated test on a remote server. |
|
19 | 19 | * @package SimpleTest |
20 | 20 | * @subpackage UnitTester |
21 | - */ |
|
22 | - class RemoteTestCase { |
|
23 | - protected $_url; |
|
24 | - protected $_dry_url; |
|
25 | - protected $_size; |
|
21 | + */ |
|
22 | + class RemoteTestCase { |
|
23 | + protected $_url; |
|
24 | + protected $_dry_url; |
|
25 | + protected $_size; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Sets the location of the remote test. |
|
29 | - * @param string $url Test location. |
|
30 | - * @param string $dry_url Location for dry run. |
|
31 | - * @access public |
|
32 | - */ |
|
33 | - function RemoteTestCase($url, $dry_url = false) { |
|
34 | - $this->_url = $url; |
|
35 | - $this->_dry_url = $dry_url ? $dry_url : $url; |
|
36 | - $this->_size = false; |
|
37 | - } |
|
27 | + /** |
|
28 | + * Sets the location of the remote test. |
|
29 | + * @param string $url Test location. |
|
30 | + * @param string $dry_url Location for dry run. |
|
31 | + * @access public |
|
32 | + */ |
|
33 | + function RemoteTestCase($url, $dry_url = false) { |
|
34 | + $this->_url = $url; |
|
35 | + $this->_dry_url = $dry_url ? $dry_url : $url; |
|
36 | + $this->_size = false; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Accessor for the test name for subclasses. |
|
41 | - * @return string Name of the test. |
|
42 | - * @access public |
|
43 | - */ |
|
44 | - function getLabel() { |
|
45 | - return $this->_url; |
|
46 | - } |
|
39 | + /** |
|
40 | + * Accessor for the test name for subclasses. |
|
41 | + * @return string Name of the test. |
|
42 | + * @access public |
|
43 | + */ |
|
44 | + function getLabel() { |
|
45 | + return $this->_url; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Runs the top level test for this class. Currently |
|
50 | - * reads the data as a single chunk. I'll fix this |
|
51 | - * once I have added iteration to the browser. |
|
52 | - * @param SimpleReporter $reporter Target of test results. |
|
53 | - * @returns boolean True if no failures. |
|
54 | - * @access public |
|
55 | - */ |
|
56 | - function run($reporter) { |
|
57 | - $browser = $this->_createBrowser(); |
|
58 | - $xml = $browser->get($this->_url); |
|
59 | - if (! $xml) { |
|
60 | - trigger_error('Cannot read remote test URL [' . $this->_url . ']'); |
|
61 | - return false; |
|
62 | - } |
|
63 | - $parser = $this->_createParser($reporter); |
|
64 | - if (! $parser->parse($xml)) { |
|
65 | - trigger_error('Cannot parse incoming XML from [' . $this->_url . ']'); |
|
66 | - return false; |
|
67 | - } |
|
68 | - return true; |
|
69 | - } |
|
48 | + /** |
|
49 | + * Runs the top level test for this class. Currently |
|
50 | + * reads the data as a single chunk. I'll fix this |
|
51 | + * once I have added iteration to the browser. |
|
52 | + * @param SimpleReporter $reporter Target of test results. |
|
53 | + * @returns boolean True if no failures. |
|
54 | + * @access public |
|
55 | + */ |
|
56 | + function run($reporter) { |
|
57 | + $browser = $this->_createBrowser(); |
|
58 | + $xml = $browser->get($this->_url); |
|
59 | + if (! $xml) { |
|
60 | + trigger_error('Cannot read remote test URL [' . $this->_url . ']'); |
|
61 | + return false; |
|
62 | + } |
|
63 | + $parser = $this->_createParser($reporter); |
|
64 | + if (! $parser->parse($xml)) { |
|
65 | + trigger_error('Cannot parse incoming XML from [' . $this->_url . ']'); |
|
66 | + return false; |
|
67 | + } |
|
68 | + return true; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Creates a new web browser object for fetching |
|
73 | - * the XML report. |
|
74 | - * @return SimpleBrowser New browser. |
|
75 | - * @access protected |
|
76 | - */ |
|
77 | - function &_createBrowser() { |
|
78 | - return new SimpleBrowser(); |
|
79 | - } |
|
71 | + /** |
|
72 | + * Creates a new web browser object for fetching |
|
73 | + * the XML report. |
|
74 | + * @return SimpleBrowser New browser. |
|
75 | + * @access protected |
|
76 | + */ |
|
77 | + function &_createBrowser() { |
|
78 | + return new SimpleBrowser(); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Creates the XML parser. |
|
83 | - * @param SimpleReporter $reporter Target of test results. |
|
84 | - * @return SimpleTestXmlListener XML reader. |
|
85 | - * @access protected |
|
86 | - */ |
|
87 | - function &_createParser($reporter) { |
|
88 | - return new SimpleTestXmlParser($reporter); |
|
89 | - } |
|
81 | + /** |
|
82 | + * Creates the XML parser. |
|
83 | + * @param SimpleReporter $reporter Target of test results. |
|
84 | + * @return SimpleTestXmlListener XML reader. |
|
85 | + * @access protected |
|
86 | + */ |
|
87 | + function &_createParser($reporter) { |
|
88 | + return new SimpleTestXmlParser($reporter); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Accessor for the number of subtests. |
|
93 | - * @return integer Number of test cases. |
|
94 | - * @access public |
|
95 | - */ |
|
96 | - function getSize() { |
|
97 | - if ($this->_size === false) { |
|
98 | - $browser = $this->_createBrowser(); |
|
99 | - $xml = $browser->get($this->_dry_url); |
|
100 | - if (! $xml) { |
|
101 | - trigger_error('Cannot read remote test URL [' . $this->_dry_url . ']'); |
|
102 | - return false; |
|
103 | - } |
|
104 | - $reporter = new SimpleReporter(); |
|
105 | - $parser = $this->_createParser($reporter); |
|
106 | - if (! $parser->parse($xml)) { |
|
107 | - trigger_error('Cannot parse incoming XML from [' . $this->_dry_url . ']'); |
|
108 | - return false; |
|
109 | - } |
|
110 | - $this->_size = $reporter->getTestCaseCount(); |
|
111 | - } |
|
112 | - return $this->_size; |
|
113 | - } |
|
114 | - } |
|
115 | 91 | \ No newline at end of file |
92 | + /** |
|
93 | + * Accessor for the number of subtests. |
|
94 | + * @return integer Number of test cases. |
|
95 | + * @access public |
|
96 | + */ |
|
97 | + function getSize() { |
|
98 | + if ($this->_size === false) { |
|
99 | + $browser = $this->_createBrowser(); |
|
100 | + $xml = $browser->get($this->_dry_url); |
|
101 | + if (! $xml) { |
|
102 | + trigger_error('Cannot read remote test URL [' . $this->_dry_url . ']'); |
|
103 | + return false; |
|
104 | + } |
|
105 | + $reporter = new SimpleReporter(); |
|
106 | + $parser = $this->_createParser($reporter); |
|
107 | + if (! $parser->parse($xml)) { |
|
108 | + trigger_error('Cannot parse incoming XML from [' . $this->_dry_url . ']'); |
|
109 | + return false; |
|
110 | + } |
|
111 | + $this->_size = $reporter->getTestCaseCount(); |
|
112 | + } |
|
113 | + return $this->_size; |
|
114 | + } |
|
115 | + } |
|
116 | 116 | \ No newline at end of file |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | function run($reporter) { |
57 | 57 | $browser = $this->_createBrowser(); |
58 | 58 | $xml = $browser->get($this->_url); |
59 | - if (! $xml) { |
|
59 | + if (!$xml) { |
|
60 | 60 | trigger_error('Cannot read remote test URL [' . $this->_url . ']'); |
61 | 61 | return false; |
62 | 62 | } |
63 | 63 | $parser = $this->_createParser($reporter); |
64 | - if (! $parser->parse($xml)) { |
|
64 | + if (!$parser->parse($xml)) { |
|
65 | 65 | trigger_error('Cannot parse incoming XML from [' . $this->_url . ']'); |
66 | 66 | return false; |
67 | 67 | } |
@@ -97,13 +97,13 @@ discard block |
||
97 | 97 | if ($this->_size === false) { |
98 | 98 | $browser = $this->_createBrowser(); |
99 | 99 | $xml = $browser->get($this->_dry_url); |
100 | - if (! $xml) { |
|
100 | + if (!$xml) { |
|
101 | 101 | trigger_error('Cannot read remote test URL [' . $this->_dry_url . ']'); |
102 | 102 | return false; |
103 | 103 | } |
104 | 104 | $reporter = new SimpleReporter(); |
105 | 105 | $parser = $this->_createParser($reporter); |
106 | - if (! $parser->parse($xml)) { |
|
106 | + if (!$parser->parse($xml)) { |
|
107 | 107 | trigger_error('Cannot parse incoming XML from [' . $this->_dry_url . ']'); |
108 | 108 | return false; |
109 | 109 | } |
@@ -164,9 +164,6 @@ discard block |
||
164 | 164 | |
165 | 165 | /** |
166 | 166 | * Runs the test methods in the test case. |
167 | - * @param SimpleTest $test_case Test case to run test on. |
|
168 | - * @param string $method Name of test method. |
|
169 | - * @access public |
|
170 | 167 | */ |
171 | 168 | function run() { |
172 | 169 | $methods = get_class_methods(get_class($this->_test_case)); |
@@ -288,7 +285,7 @@ discard block |
||
288 | 285 | * Chains to the wrapped reporter. |
289 | 286 | * @param string $type Event type as text. |
290 | 287 | * @param mixed $payload Message or object. |
291 | - * @return boolean Should return false if this |
|
288 | + * @return boolean|null Should return false if this |
|
292 | 289 | * type of signal should fail the |
293 | 290 | * test suite. |
294 | 291 | * @access public |
@@ -1,299 +1,299 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * Base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage UnitTester |
|
6 | - * @version $Id: runner.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | - */ |
|
2 | + /** |
|
3 | + * Base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage UnitTester |
|
6 | + * @version $Id: runner.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | + */ |
|
8 | 8 | |
9 | - /**#@+ |
|
9 | + /**#@+ |
|
10 | 10 | * Includes SimpleTest files and defined the root constant |
11 | 11 | * for dependent libraries. |
12 | 12 | */ |
13 | - require_once(dirname(__FILE__) . '/errors.php'); |
|
14 | - require_once(dirname(__FILE__) . '/options.php'); |
|
15 | - require_once(dirname(__FILE__) . '/scorer.php'); |
|
16 | - require_once(dirname(__FILE__) . '/expectation.php'); |
|
17 | - require_once(dirname(__FILE__) . '/dumper.php'); |
|
18 | - if (! defined('SIMPLE_TEST')) { |
|
19 | - define('SIMPLE_TEST', dirname(__FILE__) . '/'); |
|
20 | - } |
|
21 | - /**#@-*/ |
|
13 | + require_once(dirname(__FILE__) . '/errors.php'); |
|
14 | + require_once(dirname(__FILE__) . '/options.php'); |
|
15 | + require_once(dirname(__FILE__) . '/scorer.php'); |
|
16 | + require_once(dirname(__FILE__) . '/expectation.php'); |
|
17 | + require_once(dirname(__FILE__) . '/dumper.php'); |
|
18 | + if (! defined('SIMPLE_TEST')) { |
|
19 | + define('SIMPLE_TEST', dirname(__FILE__) . '/'); |
|
20 | + } |
|
21 | + /**#@-*/ |
|
22 | 22 | |
23 | - /** |
|
24 | - * This is called by the class runner to run a |
|
25 | - * single test method. Will also run the setUp() |
|
26 | - * and tearDown() methods. |
|
23 | + /** |
|
24 | + * This is called by the class runner to run a |
|
25 | + * single test method. Will also run the setUp() |
|
26 | + * and tearDown() methods. |
|
27 | 27 | * @package SimpleTest |
28 | 28 | * @subpackage UnitTester |
29 | - */ |
|
30 | - class SimpleInvoker { |
|
31 | - protected $_test_case; |
|
29 | + */ |
|
30 | + class SimpleInvoker { |
|
31 | + protected $_test_case; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Stashes the test case for later. |
|
35 | - * @param SimpleTestCase $test_case Test case to run. |
|
36 | - */ |
|
37 | - function SimpleInvoker($test_case) { |
|
38 | - $this->_test_case = $test_case; |
|
39 | - } |
|
33 | + /** |
|
34 | + * Stashes the test case for later. |
|
35 | + * @param SimpleTestCase $test_case Test case to run. |
|
36 | + */ |
|
37 | + function SimpleInvoker($test_case) { |
|
38 | + $this->_test_case = $test_case; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Accessor for test case being run. |
|
43 | - * @return SimpleTestCase Test case. |
|
44 | - * @access public |
|
45 | - */ |
|
46 | - function getTestCase() { |
|
47 | - return $this->_test_case; |
|
48 | - } |
|
41 | + /** |
|
42 | + * Accessor for test case being run. |
|
43 | + * @return SimpleTestCase Test case. |
|
44 | + * @access public |
|
45 | + */ |
|
46 | + function getTestCase() { |
|
47 | + return $this->_test_case; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Invokes a test method and buffered with setUp() |
|
52 | - * and tearDown() calls. |
|
53 | - * @param string $method Test method to call. |
|
54 | - * @access public |
|
55 | - */ |
|
56 | - function invoke($method) { |
|
57 | - $this->_test_case->setUp(); |
|
58 | - $this->_test_case->$method(); |
|
59 | - $this->_test_case->tearDown(); |
|
60 | - } |
|
61 | - } |
|
50 | + /** |
|
51 | + * Invokes a test method and buffered with setUp() |
|
52 | + * and tearDown() calls. |
|
53 | + * @param string $method Test method to call. |
|
54 | + * @access public |
|
55 | + */ |
|
56 | + function invoke($method) { |
|
57 | + $this->_test_case->setUp(); |
|
58 | + $this->_test_case->$method(); |
|
59 | + $this->_test_case->tearDown(); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Do nothing decorator. Just passes the invocation |
|
65 | - * straight through. |
|
63 | + /** |
|
64 | + * Do nothing decorator. Just passes the invocation |
|
65 | + * straight through. |
|
66 | 66 | * @package SimpleTest |
67 | 67 | * @subpackage UnitTester |
68 | - */ |
|
69 | - class SimpleInvokerDecorator { |
|
70 | - protected $_invoker; |
|
68 | + */ |
|
69 | + class SimpleInvokerDecorator { |
|
70 | + protected $_invoker; |
|
71 | 71 | |
72 | - /** |
|
73 | - * Stores the invoker to wrap. |
|
74 | - * @param SimpleInvoker $invoker Test method runner. |
|
75 | - */ |
|
76 | - function SimpleInvokerDecorator($invoker) { |
|
77 | - $this->_invoker = $invoker; |
|
78 | - } |
|
72 | + /** |
|
73 | + * Stores the invoker to wrap. |
|
74 | + * @param SimpleInvoker $invoker Test method runner. |
|
75 | + */ |
|
76 | + function SimpleInvokerDecorator($invoker) { |
|
77 | + $this->_invoker = $invoker; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Accessor for test case being run. |
|
82 | - * @return SimpleTestCase Test case. |
|
83 | - * @access public |
|
84 | - */ |
|
85 | - function getTestCase() { |
|
86 | - return $this->_invoker->getTestCase(); |
|
87 | - } |
|
80 | + /** |
|
81 | + * Accessor for test case being run. |
|
82 | + * @return SimpleTestCase Test case. |
|
83 | + * @access public |
|
84 | + */ |
|
85 | + function getTestCase() { |
|
86 | + return $this->_invoker->getTestCase(); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Invokes a test method and buffered with setUp() |
|
91 | - * and tearDown() calls. |
|
92 | - * @param string $method Test method to call. |
|
93 | - * @access public |
|
94 | - */ |
|
95 | - function invoke($method) { |
|
96 | - $this->_invoker->invoke($method); |
|
97 | - } |
|
98 | - } |
|
89 | + /** |
|
90 | + * Invokes a test method and buffered with setUp() |
|
91 | + * and tearDown() calls. |
|
92 | + * @param string $method Test method to call. |
|
93 | + * @access public |
|
94 | + */ |
|
95 | + function invoke($method) { |
|
96 | + $this->_invoker->invoke($method); |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Extension that traps errors into an error queue. |
|
100 | + /** |
|
101 | + * Extension that traps errors into an error queue. |
|
102 | 102 | * @package SimpleTest |
103 | 103 | * @subpackage UnitTester |
104 | - */ |
|
105 | - class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator { |
|
104 | + */ |
|
105 | + class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator { |
|
106 | 106 | |
107 | + /** |
|
107 | 108 | /** |
108 | - /** |
|
109 | - * Stores the invoker to wrap. |
|
110 | - * @param SimpleInvoker $invoker Test method runner. |
|
111 | - */ |
|
112 | - function SimpleErrorTrappingInvoker($invoker) { |
|
113 | - $this->SimpleInvokerDecorator($invoker); |
|
114 | - } |
|
109 | + * Stores the invoker to wrap. |
|
110 | + * @param SimpleInvoker $invoker Test method runner. |
|
111 | + */ |
|
112 | + function SimpleErrorTrappingInvoker($invoker) { |
|
113 | + $this->SimpleInvokerDecorator($invoker); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Invokes a test method and dispatches any |
|
118 | - * untrapped errors. Called back from |
|
119 | - * the visiting runner. |
|
120 | - * @param string $method Test method to call. |
|
121 | - * @access public |
|
122 | - */ |
|
123 | - function invoke($method) { |
|
124 | - set_error_handler('simpleTestErrorHandler'); |
|
125 | - parent::invoke($method); |
|
126 | - $queue = SimpleErrorQueue::instance(); |
|
127 | - while (list($severity, $message, $file, $line, $globals) = $queue->extract()) { |
|
128 | - $test_case = $this->getTestCase(); |
|
129 | - $test_case->error($severity, $message, $file, $line, $globals); |
|
130 | - } |
|
131 | - restore_error_handler(); |
|
132 | - } |
|
133 | - } |
|
116 | + /** |
|
117 | + * Invokes a test method and dispatches any |
|
118 | + * untrapped errors. Called back from |
|
119 | + * the visiting runner. |
|
120 | + * @param string $method Test method to call. |
|
121 | + * @access public |
|
122 | + */ |
|
123 | + function invoke($method) { |
|
124 | + set_error_handler('simpleTestErrorHandler'); |
|
125 | + parent::invoke($method); |
|
126 | + $queue = SimpleErrorQueue::instance(); |
|
127 | + while (list($severity, $message, $file, $line, $globals) = $queue->extract()) { |
|
128 | + $test_case = $this->getTestCase(); |
|
129 | + $test_case->error($severity, $message, $file, $line, $globals); |
|
130 | + } |
|
131 | + restore_error_handler(); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * The standard runner. Will run every method starting |
|
137 | - * with test Basically the |
|
138 | - * Mediator pattern. |
|
135 | + /** |
|
136 | + * The standard runner. Will run every method starting |
|
137 | + * with test Basically the |
|
138 | + * Mediator pattern. |
|
139 | 139 | * @package SimpleTest |
140 | 140 | * @subpackage UnitTester |
141 | - */ |
|
142 | - class SimpleRunner { |
|
143 | - protected $_test_case; |
|
144 | - protected $_scorer; |
|
141 | + */ |
|
142 | + class SimpleRunner { |
|
143 | + protected $_test_case; |
|
144 | + protected $_scorer; |
|
145 | 145 | |
146 | - /** |
|
147 | - * Takes in the test case and reporter to mediate between. |
|
148 | - * @param SimpleTestCase $test_case Test case to run. |
|
149 | - * @param SimpleScorer $scorer Reporter to receive events. |
|
150 | - */ |
|
151 | - function SimpleRunner($test_case, $scorer) { |
|
152 | - $this->_test_case = $test_case; |
|
153 | - $this->_scorer = $scorer; |
|
154 | - } |
|
146 | + /** |
|
147 | + * Takes in the test case and reporter to mediate between. |
|
148 | + * @param SimpleTestCase $test_case Test case to run. |
|
149 | + * @param SimpleScorer $scorer Reporter to receive events. |
|
150 | + */ |
|
151 | + function SimpleRunner($test_case, $scorer) { |
|
152 | + $this->_test_case = $test_case; |
|
153 | + $this->_scorer = $scorer; |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Accessor for test case being run. |
|
158 | - * @return SimpleTestCase Test case. |
|
159 | - * @access public |
|
160 | - */ |
|
161 | - function getTestCase() { |
|
162 | - return $this->_test_case; |
|
163 | - } |
|
156 | + /** |
|
157 | + * Accessor for test case being run. |
|
158 | + * @return SimpleTestCase Test case. |
|
159 | + * @access public |
|
160 | + */ |
|
161 | + function getTestCase() { |
|
162 | + return $this->_test_case; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Runs the test methods in the test case. |
|
167 | - * @param SimpleTest $test_case Test case to run test on. |
|
168 | - * @param string $method Name of test method. |
|
169 | - * @access public |
|
170 | - */ |
|
171 | - function run() { |
|
172 | - $methods = get_class_methods(get_class($this->_test_case)); |
|
173 | - $invoker = $this->_test_case->createInvoker(); |
|
174 | - foreach ($methods as $method) { |
|
175 | - if (! $this->_isTest($method)) { |
|
176 | - continue; |
|
177 | - } |
|
178 | - if ($this->_isConstructor($method)) { |
|
179 | - continue; |
|
180 | - } |
|
181 | - $this->_scorer->paintMethodStart($method); |
|
182 | - if ($this->_scorer->shouldInvoke($this->_test_case->getLabel(), $method)) { |
|
183 | - $invoker->invoke($method); |
|
184 | - } |
|
185 | - $this->_scorer->paintMethodEnd($method); |
|
186 | - } |
|
187 | - } |
|
165 | + /** |
|
166 | + * Runs the test methods in the test case. |
|
167 | + * @param SimpleTest $test_case Test case to run test on. |
|
168 | + * @param string $method Name of test method. |
|
169 | + * @access public |
|
170 | + */ |
|
171 | + function run() { |
|
172 | + $methods = get_class_methods(get_class($this->_test_case)); |
|
173 | + $invoker = $this->_test_case->createInvoker(); |
|
174 | + foreach ($methods as $method) { |
|
175 | + if (! $this->_isTest($method)) { |
|
176 | + continue; |
|
177 | + } |
|
178 | + if ($this->_isConstructor($method)) { |
|
179 | + continue; |
|
180 | + } |
|
181 | + $this->_scorer->paintMethodStart($method); |
|
182 | + if ($this->_scorer->shouldInvoke($this->_test_case->getLabel(), $method)) { |
|
183 | + $invoker->invoke($method); |
|
184 | + } |
|
185 | + $this->_scorer->paintMethodEnd($method); |
|
186 | + } |
|
187 | + } |
|
188 | 188 | |
189 | - /** |
|
190 | - * Tests to see if the method is the constructor and |
|
191 | - * so should be ignored. |
|
192 | - * @param string $method Method name to try. |
|
193 | - * @return boolean True if constructor. |
|
194 | - * @access protected |
|
195 | - */ |
|
196 | - function _isConstructor($method) { |
|
197 | - return SimpleTestCompatibility::isA( |
|
198 | - $this->_test_case, |
|
199 | - strtolower($method)); |
|
200 | - } |
|
189 | + /** |
|
190 | + * Tests to see if the method is the constructor and |
|
191 | + * so should be ignored. |
|
192 | + * @param string $method Method name to try. |
|
193 | + * @return boolean True if constructor. |
|
194 | + * @access protected |
|
195 | + */ |
|
196 | + function _isConstructor($method) { |
|
197 | + return SimpleTestCompatibility::isA( |
|
198 | + $this->_test_case, |
|
199 | + strtolower($method)); |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Tests to see if the method is a test that should |
|
204 | - * be run. Currently any method that starts with 'test' |
|
205 | - * is a candidate. |
|
206 | - * @param string $method Method name to try. |
|
207 | - * @return boolean True if test method. |
|
208 | - * @access protected |
|
209 | - */ |
|
210 | - function _isTest($method) { |
|
211 | - return strtolower(substr($method, 0, 4)) == 'test'; |
|
212 | - } |
|
202 | + /** |
|
203 | + * Tests to see if the method is a test that should |
|
204 | + * be run. Currently any method that starts with 'test' |
|
205 | + * is a candidate. |
|
206 | + * @param string $method Method name to try. |
|
207 | + * @return boolean True if test method. |
|
208 | + * @access protected |
|
209 | + */ |
|
210 | + function _isTest($method) { |
|
211 | + return strtolower(substr($method, 0, 4)) == 'test'; |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * Paints the start of a test method. |
|
216 | - * @param string $test_name Name of test or other label. |
|
217 | - * @access public |
|
218 | - */ |
|
219 | - function paintMethodStart($test_name) { |
|
220 | - $this->_scorer->paintMethodStart($test_name); |
|
221 | - } |
|
214 | + /** |
|
215 | + * Paints the start of a test method. |
|
216 | + * @param string $test_name Name of test or other label. |
|
217 | + * @access public |
|
218 | + */ |
|
219 | + function paintMethodStart($test_name) { |
|
220 | + $this->_scorer->paintMethodStart($test_name); |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * Paints the end of a test method. |
|
225 | - * @param string $test_name Name of test or other label. |
|
226 | - * @access public |
|
227 | - */ |
|
228 | - function paintMethodEnd($test_name) { |
|
229 | - $this->_scorer->paintMethodEnd($test_name); |
|
230 | - } |
|
223 | + /** |
|
224 | + * Paints the end of a test method. |
|
225 | + * @param string $test_name Name of test or other label. |
|
226 | + * @access public |
|
227 | + */ |
|
228 | + function paintMethodEnd($test_name) { |
|
229 | + $this->_scorer->paintMethodEnd($test_name); |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * Chains to the wrapped reporter. |
|
234 | - * @param string $message Message is ignored. |
|
235 | - * @access public |
|
236 | - */ |
|
237 | - function paintPass($message) { |
|
238 | - $this->_scorer->paintPass($message); |
|
239 | - } |
|
232 | + /** |
|
233 | + * Chains to the wrapped reporter. |
|
234 | + * @param string $message Message is ignored. |
|
235 | + * @access public |
|
236 | + */ |
|
237 | + function paintPass($message) { |
|
238 | + $this->_scorer->paintPass($message); |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * Chains to the wrapped reporter. |
|
243 | - * @param string $message Message is ignored. |
|
244 | - * @access public |
|
245 | - */ |
|
246 | - function paintFail($message) { |
|
247 | - $this->_scorer->paintFail($message); |
|
248 | - } |
|
241 | + /** |
|
242 | + * Chains to the wrapped reporter. |
|
243 | + * @param string $message Message is ignored. |
|
244 | + * @access public |
|
245 | + */ |
|
246 | + function paintFail($message) { |
|
247 | + $this->_scorer->paintFail($message); |
|
248 | + } |
|
249 | 249 | |
250 | - /** |
|
251 | - * Chains to the wrapped reporter. |
|
252 | - * @param string $message Text of error formatted by |
|
253 | - * the test case. |
|
254 | - * @access public |
|
255 | - */ |
|
256 | - function paintError($message) { |
|
257 | - $this->_scorer->paintError($message); |
|
258 | - } |
|
250 | + /** |
|
251 | + * Chains to the wrapped reporter. |
|
252 | + * @param string $message Text of error formatted by |
|
253 | + * the test case. |
|
254 | + * @access public |
|
255 | + */ |
|
256 | + function paintError($message) { |
|
257 | + $this->_scorer->paintError($message); |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * Chains to the wrapped reporter. |
|
262 | - * @param Exception $exception Object thrown. |
|
263 | - * @access public |
|
264 | - */ |
|
265 | - function paintException($exception) { |
|
266 | - $this->_scorer->paintException($exception); |
|
267 | - } |
|
260 | + /** |
|
261 | + * Chains to the wrapped reporter. |
|
262 | + * @param Exception $exception Object thrown. |
|
263 | + * @access public |
|
264 | + */ |
|
265 | + function paintException($exception) { |
|
266 | + $this->_scorer->paintException($exception); |
|
267 | + } |
|
268 | 268 | |
269 | - /** |
|
270 | - * Chains to the wrapped reporter. |
|
271 | - * @param string $message Text to display. |
|
272 | - * @access public |
|
273 | - */ |
|
274 | - function paintMessage($message) { |
|
275 | - $this->_scorer->paintMessage($message); |
|
276 | - } |
|
269 | + /** |
|
270 | + * Chains to the wrapped reporter. |
|
271 | + * @param string $message Text to display. |
|
272 | + * @access public |
|
273 | + */ |
|
274 | + function paintMessage($message) { |
|
275 | + $this->_scorer->paintMessage($message); |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * Chains to the wrapped reporter. |
|
280 | - * @param string $message Text to display. |
|
281 | - * @access public |
|
282 | - */ |
|
283 | - function paintFormattedMessage($message) { |
|
284 | - $this->_scorer->paintFormattedMessage($message); |
|
285 | - } |
|
278 | + /** |
|
279 | + * Chains to the wrapped reporter. |
|
280 | + * @param string $message Text to display. |
|
281 | + * @access public |
|
282 | + */ |
|
283 | + function paintFormattedMessage($message) { |
|
284 | + $this->_scorer->paintFormattedMessage($message); |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * Chains to the wrapped reporter. |
|
289 | - * @param string $type Event type as text. |
|
290 | - * @param mixed $payload Message or object. |
|
291 | - * @return boolean Should return false if this |
|
292 | - * type of signal should fail the |
|
293 | - * test suite. |
|
294 | - * @access public |
|
295 | - */ |
|
296 | - function paintSignal($type, $payload) { |
|
297 | - $this->_scorer->paintSignal($type, $payload); |
|
298 | - } |
|
299 | - } |
|
287 | + /** |
|
288 | + * Chains to the wrapped reporter. |
|
289 | + * @param string $type Event type as text. |
|
290 | + * @param mixed $payload Message or object. |
|
291 | + * @return boolean Should return false if this |
|
292 | + * type of signal should fail the |
|
293 | + * test suite. |
|
294 | + * @access public |
|
295 | + */ |
|
296 | + function paintSignal($type, $payload) { |
|
297 | + $this->_scorer->paintSignal($type, $payload); |
|
298 | + } |
|
299 | + } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | require_once(dirname(__FILE__) . '/scorer.php'); |
16 | 16 | require_once(dirname(__FILE__) . '/expectation.php'); |
17 | 17 | require_once(dirname(__FILE__) . '/dumper.php'); |
18 | - if (! defined('SIMPLE_TEST')) { |
|
18 | + if (!defined('SIMPLE_TEST')) { |
|
19 | 19 | define('SIMPLE_TEST', dirname(__FILE__) . '/'); |
20 | 20 | } |
21 | 21 | /**#@-*/ |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | $methods = get_class_methods(get_class($this->_test_case)); |
173 | 173 | $invoker = $this->_test_case->createInvoker(); |
174 | 174 | foreach ($methods as $method) { |
175 | - if (! $this->_isTest($method)) { |
|
175 | + if (!$this->_isTest($method)) { |
|
176 | 176 | continue; |
177 | 177 | } |
178 | 178 | if ($this->_isConstructor($method)) { |
@@ -261,8 +261,6 @@ discard block |
||
261 | 261 | * Paints the end of a group test. Will paint the page |
262 | 262 | * footer if the stack of tests has unwound. |
263 | 263 | * @param string $test_name Name of test that is ending. |
264 | - * @param integer $progress Number of test cases ending. |
|
265 | - * @access public |
|
266 | 264 | */ |
267 | 265 | function paintGroupEnd($test_name) { |
268 | 266 | array_pop($this->_test_stack); |
@@ -549,7 +547,7 @@ discard block |
||
549 | 547 | * Chains to the wrapped reporter. |
550 | 548 | * @param string $type Event type as text. |
551 | 549 | * @param mixed $payload Message or object. |
552 | - * @return boolean Should return false if this |
|
550 | + * @return boolean|null Should return false if this |
|
553 | 551 | * type of signal should fail the |
554 | 552 | * test suite. |
555 | 553 | * @access public |
@@ -763,7 +761,7 @@ discard block |
||
763 | 761 | * Chains to the wrapped reporter. |
764 | 762 | * @param string $type Event type as text. |
765 | 763 | * @param mixed $payload Message or object. |
766 | - * @return boolean Should return false if this |
|
764 | + * @return boolean|null Should return false if this |
|
767 | 765 | * type of signal should fail the |
768 | 766 | * test suite. |
769 | 767 | * @access public |
@@ -1,776 +1,776 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage UnitTester |
|
6 | - * @version $Id: scorer.php 1532 2006-12-01 12:28:55Z xue $ |
|
7 | - */ |
|
8 | - |
|
9 | - /**#@+*/ |
|
10 | - require_once(dirname(__FILE__) . '/invoker.php'); |
|
11 | - /**#@-*/ |
|
12 | - |
|
13 | - /** |
|
14 | - * Can recieve test events and display them. Display |
|
15 | - * is achieved by making display methods available |
|
16 | - * and visiting the incoming event. |
|
2 | + /** |
|
3 | + * base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage UnitTester |
|
6 | + * @version $Id: scorer.php 1532 2006-12-01 12:28:55Z xue $ |
|
7 | + */ |
|
8 | + |
|
9 | + /**#@+*/ |
|
10 | + require_once(dirname(__FILE__) . '/invoker.php'); |
|
11 | + /**#@-*/ |
|
12 | + |
|
13 | + /** |
|
14 | + * Can recieve test events and display them. Display |
|
15 | + * is achieved by making display methods available |
|
16 | + * and visiting the incoming event. |
|
17 | 17 | * @package SimpleTest |
18 | 18 | * @subpackage UnitTester |
19 | - * @abstract |
|
20 | - */ |
|
21 | - class SimpleScorer { |
|
22 | - protected $_passes; |
|
23 | - protected $_fails; |
|
24 | - protected $_exceptions; |
|
25 | - protected $_is_dry_run; |
|
26 | - |
|
27 | - /** |
|
28 | - * Starts the test run with no results. |
|
29 | - * @access public |
|
30 | - */ |
|
31 | - function SimpleScorer() { |
|
32 | - $this->_passes = 0; |
|
33 | - $this->_fails = 0; |
|
34 | - $this->_exceptions = 0; |
|
35 | - $this->_is_dry_run = false; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Signals that the next evaluation will be a dry |
|
40 | - * run. That is, the structure events will be |
|
41 | - * recorded, but no tests will be run. |
|
42 | - * @param boolean $is_dry Dry run if true. |
|
43 | - * @access public |
|
44 | - */ |
|
45 | - function makeDry($is_dry = true) { |
|
46 | - $this->_is_dry_run = $is_dry; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * The reporter has a veto on what should be run. |
|
51 | - * @param string $test_case_name name of test case. |
|
52 | - * @param string $method Name of test method. |
|
53 | - * @access public |
|
54 | - */ |
|
55 | - function shouldInvoke($test_case_name, $method) { |
|
56 | - return ! $this->_is_dry_run; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Can wrap the invoker in preperation for running |
|
61 | - * a test. |
|
62 | - * @param SimpleInvoker $invoker Individual test runner. |
|
63 | - * @return SimpleInvoker Wrapped test runner. |
|
64 | - * @access public |
|
65 | - */ |
|
66 | - function &createInvoker($invoker) { |
|
67 | - return $invoker; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Accessor for current status. Will be false |
|
72 | - * if there have been any failures or exceptions. |
|
73 | - * Used for command line tools. |
|
74 | - * @return boolean True if no failures. |
|
75 | - * @access public |
|
76 | - */ |
|
77 | - function getStatus() { |
|
78 | - if ($this->_exceptions + $this->_fails > 0) { |
|
79 | - return false; |
|
80 | - } |
|
81 | - return true; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Paints the start of a group test. |
|
86 | - * @param string $test_name Name of test or other label. |
|
87 | - * @param integer $size Number of test cases starting. |
|
88 | - * @access public |
|
89 | - */ |
|
90 | - function paintGroupStart($test_name, $size) { |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Paints the end of a group test. |
|
95 | - * @param string $test_name Name of test or other label. |
|
96 | - * @access public |
|
97 | - */ |
|
98 | - function paintGroupEnd($test_name) { |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Paints the start of a test case. |
|
103 | - * @param string $test_name Name of test or other label. |
|
104 | - * @access public |
|
105 | - */ |
|
106 | - function paintCaseStart($test_name) { |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Paints the end of a test case. |
|
111 | - * @param string $test_name Name of test or other label. |
|
112 | - * @access public |
|
113 | - */ |
|
114 | - function paintCaseEnd($test_name) { |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Paints the start of a test method. |
|
119 | - * @param string $test_name Name of test or other label. |
|
120 | - * @access public |
|
121 | - */ |
|
122 | - function paintMethodStart($test_name) { |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Paints the end of a test method. |
|
127 | - * @param string $test_name Name of test or other label. |
|
128 | - * @access public |
|
129 | - */ |
|
130 | - function paintMethodEnd($test_name) { |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Increments the pass count. |
|
135 | - * @param string $message Message is ignored. |
|
136 | - * @access public |
|
137 | - */ |
|
138 | - function paintPass($message) { |
|
139 | - $this->_passes++; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Increments the fail count. |
|
144 | - * @param string $message Message is ignored. |
|
145 | - * @access public |
|
146 | - */ |
|
147 | - function paintFail($message) { |
|
148 | - $this->_fails++; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Deals with PHP 4 throwing an error or PHP 5 |
|
153 | - * throwing an exception. |
|
154 | - * @param string $message Text of error formatted by |
|
155 | - * the test case. |
|
156 | - * @access public |
|
157 | - */ |
|
158 | - function paintError($message) { |
|
159 | - $this->_exceptions++; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Accessor for the number of passes so far. |
|
164 | - * @return integer Number of passes. |
|
165 | - * @access public |
|
166 | - */ |
|
167 | - function getPassCount() { |
|
168 | - return $this->_passes; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Accessor for the number of fails so far. |
|
173 | - * @return integer Number of fails. |
|
174 | - * @access public |
|
175 | - */ |
|
176 | - function getFailCount() { |
|
177 | - return $this->_fails; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Accessor for the number of untrapped errors |
|
182 | - * so far. |
|
183 | - * @return integer Number of exceptions. |
|
184 | - * @access public |
|
185 | - */ |
|
186 | - function getExceptionCount() { |
|
187 | - return $this->_exceptions; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Paints a simple supplementary message. |
|
192 | - * @param string $message Text to display. |
|
193 | - * @access public |
|
194 | - */ |
|
195 | - function paintMessage($message) { |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Paints a formatted ASCII message such as a |
|
200 | - * variable dump. |
|
201 | - * @param string $message Text to display. |
|
202 | - * @access public |
|
203 | - */ |
|
204 | - function paintFormattedMessage($message) { |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * By default just ignores user generated events. |
|
209 | - * @param string $type Event type as text. |
|
210 | - * @param mixed $payload Message or object. |
|
211 | - * @access public |
|
212 | - */ |
|
213 | - function paintSignal($type, $payload) { |
|
214 | - } |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Recipient of generated test messages that can display |
|
219 | - * page footers and headers. Also keeps track of the |
|
220 | - * test nesting. This is the main base class on which |
|
221 | - * to build the finished test (page based) displays. |
|
19 | + * @abstract |
|
20 | + */ |
|
21 | + class SimpleScorer { |
|
22 | + protected $_passes; |
|
23 | + protected $_fails; |
|
24 | + protected $_exceptions; |
|
25 | + protected $_is_dry_run; |
|
26 | + |
|
27 | + /** |
|
28 | + * Starts the test run with no results. |
|
29 | + * @access public |
|
30 | + */ |
|
31 | + function SimpleScorer() { |
|
32 | + $this->_passes = 0; |
|
33 | + $this->_fails = 0; |
|
34 | + $this->_exceptions = 0; |
|
35 | + $this->_is_dry_run = false; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Signals that the next evaluation will be a dry |
|
40 | + * run. That is, the structure events will be |
|
41 | + * recorded, but no tests will be run. |
|
42 | + * @param boolean $is_dry Dry run if true. |
|
43 | + * @access public |
|
44 | + */ |
|
45 | + function makeDry($is_dry = true) { |
|
46 | + $this->_is_dry_run = $is_dry; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * The reporter has a veto on what should be run. |
|
51 | + * @param string $test_case_name name of test case. |
|
52 | + * @param string $method Name of test method. |
|
53 | + * @access public |
|
54 | + */ |
|
55 | + function shouldInvoke($test_case_name, $method) { |
|
56 | + return ! $this->_is_dry_run; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Can wrap the invoker in preperation for running |
|
61 | + * a test. |
|
62 | + * @param SimpleInvoker $invoker Individual test runner. |
|
63 | + * @return SimpleInvoker Wrapped test runner. |
|
64 | + * @access public |
|
65 | + */ |
|
66 | + function &createInvoker($invoker) { |
|
67 | + return $invoker; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Accessor for current status. Will be false |
|
72 | + * if there have been any failures or exceptions. |
|
73 | + * Used for command line tools. |
|
74 | + * @return boolean True if no failures. |
|
75 | + * @access public |
|
76 | + */ |
|
77 | + function getStatus() { |
|
78 | + if ($this->_exceptions + $this->_fails > 0) { |
|
79 | + return false; |
|
80 | + } |
|
81 | + return true; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Paints the start of a group test. |
|
86 | + * @param string $test_name Name of test or other label. |
|
87 | + * @param integer $size Number of test cases starting. |
|
88 | + * @access public |
|
89 | + */ |
|
90 | + function paintGroupStart($test_name, $size) { |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Paints the end of a group test. |
|
95 | + * @param string $test_name Name of test or other label. |
|
96 | + * @access public |
|
97 | + */ |
|
98 | + function paintGroupEnd($test_name) { |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Paints the start of a test case. |
|
103 | + * @param string $test_name Name of test or other label. |
|
104 | + * @access public |
|
105 | + */ |
|
106 | + function paintCaseStart($test_name) { |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Paints the end of a test case. |
|
111 | + * @param string $test_name Name of test or other label. |
|
112 | + * @access public |
|
113 | + */ |
|
114 | + function paintCaseEnd($test_name) { |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Paints the start of a test method. |
|
119 | + * @param string $test_name Name of test or other label. |
|
120 | + * @access public |
|
121 | + */ |
|
122 | + function paintMethodStart($test_name) { |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Paints the end of a test method. |
|
127 | + * @param string $test_name Name of test or other label. |
|
128 | + * @access public |
|
129 | + */ |
|
130 | + function paintMethodEnd($test_name) { |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Increments the pass count. |
|
135 | + * @param string $message Message is ignored. |
|
136 | + * @access public |
|
137 | + */ |
|
138 | + function paintPass($message) { |
|
139 | + $this->_passes++; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Increments the fail count. |
|
144 | + * @param string $message Message is ignored. |
|
145 | + * @access public |
|
146 | + */ |
|
147 | + function paintFail($message) { |
|
148 | + $this->_fails++; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Deals with PHP 4 throwing an error or PHP 5 |
|
153 | + * throwing an exception. |
|
154 | + * @param string $message Text of error formatted by |
|
155 | + * the test case. |
|
156 | + * @access public |
|
157 | + */ |
|
158 | + function paintError($message) { |
|
159 | + $this->_exceptions++; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Accessor for the number of passes so far. |
|
164 | + * @return integer Number of passes. |
|
165 | + * @access public |
|
166 | + */ |
|
167 | + function getPassCount() { |
|
168 | + return $this->_passes; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Accessor for the number of fails so far. |
|
173 | + * @return integer Number of fails. |
|
174 | + * @access public |
|
175 | + */ |
|
176 | + function getFailCount() { |
|
177 | + return $this->_fails; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Accessor for the number of untrapped errors |
|
182 | + * so far. |
|
183 | + * @return integer Number of exceptions. |
|
184 | + * @access public |
|
185 | + */ |
|
186 | + function getExceptionCount() { |
|
187 | + return $this->_exceptions; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Paints a simple supplementary message. |
|
192 | + * @param string $message Text to display. |
|
193 | + * @access public |
|
194 | + */ |
|
195 | + function paintMessage($message) { |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Paints a formatted ASCII message such as a |
|
200 | + * variable dump. |
|
201 | + * @param string $message Text to display. |
|
202 | + * @access public |
|
203 | + */ |
|
204 | + function paintFormattedMessage($message) { |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * By default just ignores user generated events. |
|
209 | + * @param string $type Event type as text. |
|
210 | + * @param mixed $payload Message or object. |
|
211 | + * @access public |
|
212 | + */ |
|
213 | + function paintSignal($type, $payload) { |
|
214 | + } |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Recipient of generated test messages that can display |
|
219 | + * page footers and headers. Also keeps track of the |
|
220 | + * test nesting. This is the main base class on which |
|
221 | + * to build the finished test (page based) displays. |
|
222 | 222 | * @package SimpleTest |
223 | 223 | * @subpackage UnitTester |
224 | - */ |
|
225 | - class SimpleReporter extends SimpleScorer { |
|
226 | - protected $_test_stack; |
|
227 | - protected $_size; |
|
228 | - protected $_progress; |
|
229 | - |
|
230 | - /** |
|
231 | - * Starts the display with no results in. |
|
232 | - * @access public |
|
233 | - */ |
|
234 | - function SimpleReporter() { |
|
235 | - $this->SimpleScorer(); |
|
236 | - $this->_test_stack = array(); |
|
237 | - $this->_size = null; |
|
238 | - $this->_progress = 0; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Paints the start of a group test. Will also paint |
|
243 | - * the page header and footer if this is the |
|
244 | - * first test. Will stash the size if the first |
|
245 | - * start. |
|
246 | - * @param string $test_name Name of test that is starting. |
|
247 | - * @param integer $size Number of test cases starting. |
|
248 | - * @access public |
|
249 | - */ |
|
250 | - function paintGroupStart($test_name, $size) { |
|
251 | - if (! isset($this->_size)) { |
|
252 | - $this->_size = $size; |
|
253 | - } |
|
254 | - if (count($this->_test_stack) == 0) { |
|
255 | - $this->paintHeader($test_name); |
|
256 | - } |
|
257 | - $this->_test_stack[] = $test_name; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Paints the end of a group test. Will paint the page |
|
262 | - * footer if the stack of tests has unwound. |
|
263 | - * @param string $test_name Name of test that is ending. |
|
264 | - * @param integer $progress Number of test cases ending. |
|
265 | - * @access public |
|
266 | - */ |
|
267 | - function paintGroupEnd($test_name) { |
|
268 | - array_pop($this->_test_stack); |
|
269 | - if (count($this->_test_stack) == 0) { |
|
270 | - $this->paintFooter($test_name); |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Paints the start of a test case. Will also paint |
|
276 | - * the page header and footer if this is the |
|
277 | - * first test. Will stash the size if the first |
|
278 | - * start. |
|
279 | - * @param string $test_name Name of test that is starting. |
|
280 | - * @access public |
|
281 | - */ |
|
282 | - function paintCaseStart($test_name) { |
|
283 | - if (! isset($this->_size)) { |
|
284 | - $this->_size = 1; |
|
285 | - } |
|
286 | - if (count($this->_test_stack) == 0) { |
|
287 | - $this->paintHeader($test_name); |
|
288 | - } |
|
289 | - $this->_test_stack[] = $test_name; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Paints the end of a test case. Will paint the page |
|
294 | - * footer if the stack of tests has unwound. |
|
295 | - * @param string $test_name Name of test that is ending. |
|
296 | - * @access public |
|
297 | - */ |
|
298 | - function paintCaseEnd($test_name) { |
|
299 | - $this->_progress++; |
|
300 | - array_pop($this->_test_stack); |
|
301 | - if (count($this->_test_stack) == 0) { |
|
302 | - $this->paintFooter($test_name); |
|
303 | - } |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Paints the start of a test method. |
|
308 | - * @param string $test_name Name of test that is starting. |
|
309 | - * @access public |
|
310 | - */ |
|
311 | - function paintMethodStart($test_name) { |
|
312 | - $this->_test_stack[] = $test_name; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Paints the end of a test method. Will paint the page |
|
317 | - * footer if the stack of tests has unwound. |
|
318 | - * @param string $test_name Name of test that is ending. |
|
319 | - * @access public |
|
320 | - */ |
|
321 | - function paintMethodEnd($test_name) { |
|
322 | - array_pop($this->_test_stack); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Paints the test document header. |
|
327 | - * @param string $test_name First test top level |
|
328 | - * to start. |
|
329 | - * @access public |
|
330 | - * @abstract |
|
331 | - */ |
|
332 | - function paintHeader($test_name) { |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Paints the test document footer. |
|
337 | - * @param string $test_name The top level test. |
|
338 | - * @access public |
|
339 | - * @abstract |
|
340 | - */ |
|
341 | - function paintFooter($test_name) { |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Accessor for internal test stack. For |
|
346 | - * subclasses that need to see the whole test |
|
347 | - * history for display purposes. |
|
348 | - * @return array List of methods in nesting order. |
|
349 | - * @access public |
|
350 | - */ |
|
351 | - function getTestList() { |
|
352 | - return $this->_test_stack; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Accessor for total test size in number |
|
357 | - * of test cases. Null until the first |
|
358 | - * test is started. |
|
359 | - * @return integer Total number of cases at start. |
|
360 | - * @access public |
|
361 | - */ |
|
362 | - function getTestCaseCount() { |
|
363 | - return $this->_size; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Accessor for the number of test cases |
|
368 | - * completed so far. |
|
369 | - * @return integer Number of ended cases. |
|
370 | - * @access public |
|
371 | - */ |
|
372 | - function getTestCaseProgress() { |
|
373 | - return $this->_progress; |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Static check for running in the comand line. |
|
378 | - * @return boolean True if CLI. |
|
379 | - * @access public |
|
380 | - * @static |
|
381 | - */ |
|
382 | - static function inCli() { |
|
383 | - return php_sapi_name() == 'cli'; |
|
384 | - } |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * For modifying the behaviour of the visual reporters. |
|
224 | + */ |
|
225 | + class SimpleReporter extends SimpleScorer { |
|
226 | + protected $_test_stack; |
|
227 | + protected $_size; |
|
228 | + protected $_progress; |
|
229 | + |
|
230 | + /** |
|
231 | + * Starts the display with no results in. |
|
232 | + * @access public |
|
233 | + */ |
|
234 | + function SimpleReporter() { |
|
235 | + $this->SimpleScorer(); |
|
236 | + $this->_test_stack = array(); |
|
237 | + $this->_size = null; |
|
238 | + $this->_progress = 0; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Paints the start of a group test. Will also paint |
|
243 | + * the page header and footer if this is the |
|
244 | + * first test. Will stash the size if the first |
|
245 | + * start. |
|
246 | + * @param string $test_name Name of test that is starting. |
|
247 | + * @param integer $size Number of test cases starting. |
|
248 | + * @access public |
|
249 | + */ |
|
250 | + function paintGroupStart($test_name, $size) { |
|
251 | + if (! isset($this->_size)) { |
|
252 | + $this->_size = $size; |
|
253 | + } |
|
254 | + if (count($this->_test_stack) == 0) { |
|
255 | + $this->paintHeader($test_name); |
|
256 | + } |
|
257 | + $this->_test_stack[] = $test_name; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Paints the end of a group test. Will paint the page |
|
262 | + * footer if the stack of tests has unwound. |
|
263 | + * @param string $test_name Name of test that is ending. |
|
264 | + * @param integer $progress Number of test cases ending. |
|
265 | + * @access public |
|
266 | + */ |
|
267 | + function paintGroupEnd($test_name) { |
|
268 | + array_pop($this->_test_stack); |
|
269 | + if (count($this->_test_stack) == 0) { |
|
270 | + $this->paintFooter($test_name); |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Paints the start of a test case. Will also paint |
|
276 | + * the page header and footer if this is the |
|
277 | + * first test. Will stash the size if the first |
|
278 | + * start. |
|
279 | + * @param string $test_name Name of test that is starting. |
|
280 | + * @access public |
|
281 | + */ |
|
282 | + function paintCaseStart($test_name) { |
|
283 | + if (! isset($this->_size)) { |
|
284 | + $this->_size = 1; |
|
285 | + } |
|
286 | + if (count($this->_test_stack) == 0) { |
|
287 | + $this->paintHeader($test_name); |
|
288 | + } |
|
289 | + $this->_test_stack[] = $test_name; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Paints the end of a test case. Will paint the page |
|
294 | + * footer if the stack of tests has unwound. |
|
295 | + * @param string $test_name Name of test that is ending. |
|
296 | + * @access public |
|
297 | + */ |
|
298 | + function paintCaseEnd($test_name) { |
|
299 | + $this->_progress++; |
|
300 | + array_pop($this->_test_stack); |
|
301 | + if (count($this->_test_stack) == 0) { |
|
302 | + $this->paintFooter($test_name); |
|
303 | + } |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Paints the start of a test method. |
|
308 | + * @param string $test_name Name of test that is starting. |
|
309 | + * @access public |
|
310 | + */ |
|
311 | + function paintMethodStart($test_name) { |
|
312 | + $this->_test_stack[] = $test_name; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Paints the end of a test method. Will paint the page |
|
317 | + * footer if the stack of tests has unwound. |
|
318 | + * @param string $test_name Name of test that is ending. |
|
319 | + * @access public |
|
320 | + */ |
|
321 | + function paintMethodEnd($test_name) { |
|
322 | + array_pop($this->_test_stack); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Paints the test document header. |
|
327 | + * @param string $test_name First test top level |
|
328 | + * to start. |
|
329 | + * @access public |
|
330 | + * @abstract |
|
331 | + */ |
|
332 | + function paintHeader($test_name) { |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Paints the test document footer. |
|
337 | + * @param string $test_name The top level test. |
|
338 | + * @access public |
|
339 | + * @abstract |
|
340 | + */ |
|
341 | + function paintFooter($test_name) { |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Accessor for internal test stack. For |
|
346 | + * subclasses that need to see the whole test |
|
347 | + * history for display purposes. |
|
348 | + * @return array List of methods in nesting order. |
|
349 | + * @access public |
|
350 | + */ |
|
351 | + function getTestList() { |
|
352 | + return $this->_test_stack; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Accessor for total test size in number |
|
357 | + * of test cases. Null until the first |
|
358 | + * test is started. |
|
359 | + * @return integer Total number of cases at start. |
|
360 | + * @access public |
|
361 | + */ |
|
362 | + function getTestCaseCount() { |
|
363 | + return $this->_size; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Accessor for the number of test cases |
|
368 | + * completed so far. |
|
369 | + * @return integer Number of ended cases. |
|
370 | + * @access public |
|
371 | + */ |
|
372 | + function getTestCaseProgress() { |
|
373 | + return $this->_progress; |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Static check for running in the comand line. |
|
378 | + * @return boolean True if CLI. |
|
379 | + * @access public |
|
380 | + * @static |
|
381 | + */ |
|
382 | + static function inCli() { |
|
383 | + return php_sapi_name() == 'cli'; |
|
384 | + } |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * For modifying the behaviour of the visual reporters. |
|
389 | 389 | * @package SimpleTest |
390 | 390 | * @subpackage UnitTester |
391 | - */ |
|
392 | - class SimpleReporterDecorator { |
|
393 | - protected $_reporter; |
|
394 | - |
|
395 | - /** |
|
396 | - * Mediates between teh reporter and the test case. |
|
397 | - * @param SimpleScorer $reporter Reporter to receive events. |
|
398 | - */ |
|
399 | - function SimpleReporterDecorator($reporter) { |
|
400 | - $this->_reporter = $reporter; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Signals that the next evaluation will be a dry |
|
405 | - * run. That is, the structure events will be |
|
406 | - * recorded, but no tests will be run. |
|
407 | - * @param boolean $is_dry Dry run if true. |
|
408 | - * @access public |
|
409 | - */ |
|
410 | - function makeDry($is_dry = true) { |
|
411 | - $this->_reporter->makeDry($is_dry); |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Accessor for current status. Will be false |
|
416 | - * if there have been any failures or exceptions. |
|
417 | - * Used for command line tools. |
|
418 | - * @return boolean True if no failures. |
|
419 | - * @access public |
|
420 | - */ |
|
421 | - function getStatus() { |
|
422 | - return $this->_reporter->getStatus(); |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * The reporter has a veto on what should be run. |
|
427 | - * @param string $test_case_name name of test case. |
|
428 | - * @param string $method Name of test method. |
|
429 | - * @return boolean True if test should be run. |
|
430 | - * @access public |
|
431 | - */ |
|
432 | - function shouldInvoke($test_case_name, $method) { |
|
433 | - return $this->_reporter->shouldInvoke($test_case_name, $method); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Can wrap the invoker in preperation for running |
|
438 | - * a test. |
|
439 | - * @param SimpleInvoker $invoker Individual test runner. |
|
440 | - * @return SimpleInvoker Wrapped test runner. |
|
441 | - * @access public |
|
442 | - */ |
|
443 | - function &createInvoker($invoker) { |
|
444 | - return $this->_reporter->createInvoker($invoker); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Paints the start of a group test. |
|
449 | - * @param string $test_name Name of test or other label. |
|
450 | - * @param integer $size Number of test cases starting. |
|
451 | - * @access public |
|
452 | - */ |
|
453 | - function paintGroupStart($test_name, $size) { |
|
454 | - $this->_reporter->paintGroupStart($test_name, $size); |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Paints the end of a group test. |
|
459 | - * @param string $test_name Name of test or other label. |
|
460 | - * @access public |
|
461 | - */ |
|
462 | - function paintGroupEnd($test_name) { |
|
463 | - $this->_reporter->paintGroupEnd($test_name); |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Paints the start of a test case. |
|
468 | - * @param string $test_name Name of test or other label. |
|
469 | - * @access public |
|
470 | - */ |
|
471 | - function paintCaseStart($test_name) { |
|
472 | - $this->_reporter->paintCaseStart($test_name); |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Paints the end of a test case. |
|
477 | - * @param string $test_name Name of test or other label. |
|
478 | - * @access public |
|
479 | - */ |
|
480 | - function paintCaseEnd($test_name) { |
|
481 | - $this->_reporter->paintCaseEnd($test_name); |
|
482 | - } |
|
483 | - |
|
484 | - /** |
|
485 | - * Paints the start of a test method. |
|
486 | - * @param string $test_name Name of test or other label. |
|
487 | - * @access public |
|
488 | - */ |
|
489 | - function paintMethodStart($test_name) { |
|
490 | - $this->_reporter->paintMethodStart($test_name); |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Paints the end of a test method. |
|
495 | - * @param string $test_name Name of test or other label. |
|
496 | - * @access public |
|
497 | - */ |
|
498 | - function paintMethodEnd($test_name) { |
|
499 | - $this->_reporter->paintMethodEnd($test_name); |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Chains to the wrapped reporter. |
|
504 | - * @param string $message Message is ignored. |
|
505 | - * @access public |
|
506 | - */ |
|
507 | - function paintPass($message) { |
|
508 | - $this->_reporter->paintPass($message); |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Chains to the wrapped reporter. |
|
513 | - * @param string $message Message is ignored. |
|
514 | - * @access public |
|
515 | - */ |
|
516 | - function paintFail($message) { |
|
517 | - $this->_reporter->paintFail($message); |
|
518 | - } |
|
519 | - |
|
520 | - /** |
|
521 | - * Chains to the wrapped reporter. |
|
522 | - * @param string $message Text of error formatted by |
|
523 | - * the test case. |
|
524 | - * @access public |
|
525 | - */ |
|
526 | - function paintError($message) { |
|
527 | - $this->_reporter->paintError($message); |
|
528 | - } |
|
529 | - |
|
530 | - /** |
|
531 | - * Chains to the wrapped reporter. |
|
532 | - * @param string $message Text to display. |
|
533 | - * @access public |
|
534 | - */ |
|
535 | - function paintMessage($message) { |
|
536 | - $this->_reporter->paintMessage($message); |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * Chains to the wrapped reporter. |
|
541 | - * @param string $message Text to display. |
|
542 | - * @access public |
|
543 | - */ |
|
544 | - function paintFormattedMessage($message) { |
|
545 | - $this->_reporter->paintFormattedMessage($message); |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Chains to the wrapped reporter. |
|
550 | - * @param string $type Event type as text. |
|
551 | - * @param mixed $payload Message or object. |
|
552 | - * @return boolean Should return false if this |
|
553 | - * type of signal should fail the |
|
554 | - * test suite. |
|
555 | - * @access public |
|
556 | - */ |
|
557 | - function paintSignal($type, $payload) { |
|
558 | - $this->_reporter->paintSignal($type, $payload); |
|
559 | - } |
|
560 | - } |
|
561 | - |
|
562 | - /** |
|
563 | - * For sending messages to multiple reporters at |
|
564 | - * the same time. |
|
391 | + */ |
|
392 | + class SimpleReporterDecorator { |
|
393 | + protected $_reporter; |
|
394 | + |
|
395 | + /** |
|
396 | + * Mediates between teh reporter and the test case. |
|
397 | + * @param SimpleScorer $reporter Reporter to receive events. |
|
398 | + */ |
|
399 | + function SimpleReporterDecorator($reporter) { |
|
400 | + $this->_reporter = $reporter; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Signals that the next evaluation will be a dry |
|
405 | + * run. That is, the structure events will be |
|
406 | + * recorded, but no tests will be run. |
|
407 | + * @param boolean $is_dry Dry run if true. |
|
408 | + * @access public |
|
409 | + */ |
|
410 | + function makeDry($is_dry = true) { |
|
411 | + $this->_reporter->makeDry($is_dry); |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Accessor for current status. Will be false |
|
416 | + * if there have been any failures or exceptions. |
|
417 | + * Used for command line tools. |
|
418 | + * @return boolean True if no failures. |
|
419 | + * @access public |
|
420 | + */ |
|
421 | + function getStatus() { |
|
422 | + return $this->_reporter->getStatus(); |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * The reporter has a veto on what should be run. |
|
427 | + * @param string $test_case_name name of test case. |
|
428 | + * @param string $method Name of test method. |
|
429 | + * @return boolean True if test should be run. |
|
430 | + * @access public |
|
431 | + */ |
|
432 | + function shouldInvoke($test_case_name, $method) { |
|
433 | + return $this->_reporter->shouldInvoke($test_case_name, $method); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Can wrap the invoker in preperation for running |
|
438 | + * a test. |
|
439 | + * @param SimpleInvoker $invoker Individual test runner. |
|
440 | + * @return SimpleInvoker Wrapped test runner. |
|
441 | + * @access public |
|
442 | + */ |
|
443 | + function &createInvoker($invoker) { |
|
444 | + return $this->_reporter->createInvoker($invoker); |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Paints the start of a group test. |
|
449 | + * @param string $test_name Name of test or other label. |
|
450 | + * @param integer $size Number of test cases starting. |
|
451 | + * @access public |
|
452 | + */ |
|
453 | + function paintGroupStart($test_name, $size) { |
|
454 | + $this->_reporter->paintGroupStart($test_name, $size); |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Paints the end of a group test. |
|
459 | + * @param string $test_name Name of test or other label. |
|
460 | + * @access public |
|
461 | + */ |
|
462 | + function paintGroupEnd($test_name) { |
|
463 | + $this->_reporter->paintGroupEnd($test_name); |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Paints the start of a test case. |
|
468 | + * @param string $test_name Name of test or other label. |
|
469 | + * @access public |
|
470 | + */ |
|
471 | + function paintCaseStart($test_name) { |
|
472 | + $this->_reporter->paintCaseStart($test_name); |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Paints the end of a test case. |
|
477 | + * @param string $test_name Name of test or other label. |
|
478 | + * @access public |
|
479 | + */ |
|
480 | + function paintCaseEnd($test_name) { |
|
481 | + $this->_reporter->paintCaseEnd($test_name); |
|
482 | + } |
|
483 | + |
|
484 | + /** |
|
485 | + * Paints the start of a test method. |
|
486 | + * @param string $test_name Name of test or other label. |
|
487 | + * @access public |
|
488 | + */ |
|
489 | + function paintMethodStart($test_name) { |
|
490 | + $this->_reporter->paintMethodStart($test_name); |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Paints the end of a test method. |
|
495 | + * @param string $test_name Name of test or other label. |
|
496 | + * @access public |
|
497 | + */ |
|
498 | + function paintMethodEnd($test_name) { |
|
499 | + $this->_reporter->paintMethodEnd($test_name); |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Chains to the wrapped reporter. |
|
504 | + * @param string $message Message is ignored. |
|
505 | + * @access public |
|
506 | + */ |
|
507 | + function paintPass($message) { |
|
508 | + $this->_reporter->paintPass($message); |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Chains to the wrapped reporter. |
|
513 | + * @param string $message Message is ignored. |
|
514 | + * @access public |
|
515 | + */ |
|
516 | + function paintFail($message) { |
|
517 | + $this->_reporter->paintFail($message); |
|
518 | + } |
|
519 | + |
|
520 | + /** |
|
521 | + * Chains to the wrapped reporter. |
|
522 | + * @param string $message Text of error formatted by |
|
523 | + * the test case. |
|
524 | + * @access public |
|
525 | + */ |
|
526 | + function paintError($message) { |
|
527 | + $this->_reporter->paintError($message); |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * Chains to the wrapped reporter. |
|
532 | + * @param string $message Text to display. |
|
533 | + * @access public |
|
534 | + */ |
|
535 | + function paintMessage($message) { |
|
536 | + $this->_reporter->paintMessage($message); |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * Chains to the wrapped reporter. |
|
541 | + * @param string $message Text to display. |
|
542 | + * @access public |
|
543 | + */ |
|
544 | + function paintFormattedMessage($message) { |
|
545 | + $this->_reporter->paintFormattedMessage($message); |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Chains to the wrapped reporter. |
|
550 | + * @param string $type Event type as text. |
|
551 | + * @param mixed $payload Message or object. |
|
552 | + * @return boolean Should return false if this |
|
553 | + * type of signal should fail the |
|
554 | + * test suite. |
|
555 | + * @access public |
|
556 | + */ |
|
557 | + function paintSignal($type, $payload) { |
|
558 | + $this->_reporter->paintSignal($type, $payload); |
|
559 | + } |
|
560 | + } |
|
561 | + |
|
562 | + /** |
|
563 | + * For sending messages to multiple reporters at |
|
564 | + * the same time. |
|
565 | 565 | * @package SimpleTest |
566 | 566 | * @subpackage UnitTester |
567 | - */ |
|
568 | - class MultipleReporter { |
|
569 | - protected $_reporters = array(); |
|
570 | - |
|
571 | - /** |
|
572 | - * Adds a reporter to the subscriber list. |
|
573 | - * @param SimpleScorer $reporter Reporter to receive events. |
|
574 | - * @access public |
|
575 | - */ |
|
576 | - function attachReporter($reporter) { |
|
577 | - $this->_reporters[] = $reporter; |
|
578 | - } |
|
579 | - |
|
580 | - /** |
|
581 | - * Signals that the next evaluation will be a dry |
|
582 | - * run. That is, the structure events will be |
|
583 | - * recorded, but no tests will be run. |
|
584 | - * @param boolean $is_dry Dry run if true. |
|
585 | - * @access public |
|
586 | - */ |
|
587 | - function makeDry($is_dry = true) { |
|
588 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
589 | - $this->_reporters[$i]->makeDry($is_dry); |
|
590 | - } |
|
591 | - } |
|
592 | - |
|
593 | - /** |
|
594 | - * Accessor for current status. Will be false |
|
595 | - * if there have been any failures or exceptions. |
|
596 | - * If any reporter reports a failure, the whole |
|
597 | - * suite fails. |
|
598 | - * @return boolean True if no failures. |
|
599 | - * @access public |
|
600 | - */ |
|
601 | - function getStatus() { |
|
602 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
603 | - if (! $this->_reporters[$i]->getStatus()) { |
|
604 | - return false; |
|
605 | - } |
|
606 | - } |
|
607 | - return true; |
|
608 | - } |
|
609 | - |
|
610 | - /** |
|
611 | - * The reporter has a veto on what should be run. |
|
612 | - * It requires all reporters to want to run the method. |
|
613 | - * @param string $test_case_name name of test case. |
|
614 | - * @param string $method Name of test method. |
|
615 | - * @access public |
|
616 | - */ |
|
617 | - function shouldInvoke($test_case_name, $method) { |
|
618 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
619 | - if (! $this->_reporters[$i]->shouldInvoke($test_case_name, $method)) { |
|
620 | - return false; |
|
621 | - } |
|
622 | - } |
|
623 | - return true; |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
627 | - * Every reporter gets a chance to wrap the invoker. |
|
628 | - * @param SimpleInvoker $invoker Individual test runner. |
|
629 | - * @return SimpleInvoker Wrapped test runner. |
|
630 | - * @access public |
|
631 | - */ |
|
632 | - function &createInvoker($invoker) { |
|
633 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
634 | - $invoker = $this->_reporters[$i]->createInvoker($invoker); |
|
635 | - } |
|
636 | - return $invoker; |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * Paints the start of a group test. |
|
641 | - * @param string $test_name Name of test or other label. |
|
642 | - * @param integer $size Number of test cases starting. |
|
643 | - * @access public |
|
644 | - */ |
|
645 | - function paintGroupStart($test_name, $size) { |
|
646 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
647 | - $this->_reporters[$i]->paintGroupStart($test_name, $size); |
|
648 | - } |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Paints the end of a group test. |
|
653 | - * @param string $test_name Name of test or other label. |
|
654 | - * @access public |
|
655 | - */ |
|
656 | - function paintGroupEnd($test_name) { |
|
657 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
658 | - $this->_reporters[$i]->paintGroupEnd($test_name); |
|
659 | - } |
|
660 | - } |
|
661 | - |
|
662 | - /** |
|
663 | - * Paints the start of a test case. |
|
664 | - * @param string $test_name Name of test or other label. |
|
665 | - * @access public |
|
666 | - */ |
|
667 | - function paintCaseStart($test_name) { |
|
668 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
669 | - $this->_reporters[$i]->paintCaseStart($test_name); |
|
670 | - } |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * Paints the end of a test case. |
|
675 | - * @param string $test_name Name of test or other label. |
|
676 | - * @access public |
|
677 | - */ |
|
678 | - function paintCaseEnd($test_name) { |
|
679 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
680 | - $this->_reporters[$i]->paintCaseEnd($test_name); |
|
681 | - } |
|
682 | - } |
|
683 | - |
|
684 | - /** |
|
685 | - * Paints the start of a test method. |
|
686 | - * @param string $test_name Name of test or other label. |
|
687 | - * @access public |
|
688 | - */ |
|
689 | - function paintMethodStart($test_name) { |
|
690 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
691 | - $this->_reporters[$i]->paintMethodStart($test_name); |
|
692 | - } |
|
693 | - } |
|
694 | - |
|
695 | - /** |
|
696 | - * Paints the end of a test method. |
|
697 | - * @param string $test_name Name of test or other label. |
|
698 | - * @access public |
|
699 | - */ |
|
700 | - function paintMethodEnd($test_name) { |
|
701 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
702 | - $this->_reporters[$i]->paintMethodEnd($test_name); |
|
703 | - } |
|
704 | - } |
|
705 | - |
|
706 | - /** |
|
707 | - * Chains to the wrapped reporter. |
|
708 | - * @param string $message Message is ignored. |
|
709 | - * @access public |
|
710 | - */ |
|
711 | - function paintPass($message) { |
|
712 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
713 | - $this->_reporters[$i]->paintPass($message); |
|
714 | - } |
|
715 | - } |
|
716 | - |
|
717 | - /** |
|
718 | - * Chains to the wrapped reporter. |
|
719 | - * @param string $message Message is ignored. |
|
720 | - * @access public |
|
721 | - */ |
|
722 | - function paintFail($message) { |
|
723 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
724 | - $this->_reporters[$i]->paintFail($message); |
|
725 | - } |
|
726 | - } |
|
727 | - |
|
728 | - /** |
|
729 | - * Chains to the wrapped reporter. |
|
730 | - * @param string $message Text of error formatted by |
|
731 | - * the test case. |
|
732 | - * @access public |
|
733 | - */ |
|
734 | - function paintError($message) { |
|
735 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
736 | - $this->_reporters[$i]->paintError($message); |
|
737 | - } |
|
738 | - } |
|
739 | - |
|
740 | - /** |
|
741 | - * Chains to the wrapped reporter. |
|
742 | - * @param string $message Text to display. |
|
743 | - * @access public |
|
744 | - */ |
|
745 | - function paintMessage($message) { |
|
746 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
747 | - $this->_reporters[$i]->paintMessage($message); |
|
748 | - } |
|
749 | - } |
|
750 | - |
|
751 | - /** |
|
752 | - * Chains to the wrapped reporter. |
|
753 | - * @param string $message Text to display. |
|
754 | - * @access public |
|
755 | - */ |
|
756 | - function paintFormattedMessage($message) { |
|
757 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
758 | - $this->_reporters[$i]->paintFormattedMessage($message); |
|
759 | - } |
|
760 | - } |
|
761 | - |
|
762 | - /** |
|
763 | - * Chains to the wrapped reporter. |
|
764 | - * @param string $type Event type as text. |
|
765 | - * @param mixed $payload Message or object. |
|
766 | - * @return boolean Should return false if this |
|
767 | - * type of signal should fail the |
|
768 | - * test suite. |
|
769 | - * @access public |
|
770 | - */ |
|
771 | - function paintSignal($type, $payload) { |
|
772 | - for ($i = 0; $i < count($this->_reporters); $i++) { |
|
773 | - $this->_reporters[$i]->paintSignal($type, $payload); |
|
774 | - } |
|
775 | - } |
|
776 | - } |
|
777 | 567 | \ No newline at end of file |
568 | + */ |
|
569 | + class MultipleReporter { |
|
570 | + protected $_reporters = array(); |
|
571 | + |
|
572 | + /** |
|
573 | + * Adds a reporter to the subscriber list. |
|
574 | + * @param SimpleScorer $reporter Reporter to receive events. |
|
575 | + * @access public |
|
576 | + */ |
|
577 | + function attachReporter($reporter) { |
|
578 | + $this->_reporters[] = $reporter; |
|
579 | + } |
|
580 | + |
|
581 | + /** |
|
582 | + * Signals that the next evaluation will be a dry |
|
583 | + * run. That is, the structure events will be |
|
584 | + * recorded, but no tests will be run. |
|
585 | + * @param boolean $is_dry Dry run if true. |
|
586 | + * @access public |
|
587 | + */ |
|
588 | + function makeDry($is_dry = true) { |
|
589 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
590 | + $this->_reporters[$i]->makeDry($is_dry); |
|
591 | + } |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Accessor for current status. Will be false |
|
596 | + * if there have been any failures or exceptions. |
|
597 | + * If any reporter reports a failure, the whole |
|
598 | + * suite fails. |
|
599 | + * @return boolean True if no failures. |
|
600 | + * @access public |
|
601 | + */ |
|
602 | + function getStatus() { |
|
603 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
604 | + if (! $this->_reporters[$i]->getStatus()) { |
|
605 | + return false; |
|
606 | + } |
|
607 | + } |
|
608 | + return true; |
|
609 | + } |
|
610 | + |
|
611 | + /** |
|
612 | + * The reporter has a veto on what should be run. |
|
613 | + * It requires all reporters to want to run the method. |
|
614 | + * @param string $test_case_name name of test case. |
|
615 | + * @param string $method Name of test method. |
|
616 | + * @access public |
|
617 | + */ |
|
618 | + function shouldInvoke($test_case_name, $method) { |
|
619 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
620 | + if (! $this->_reporters[$i]->shouldInvoke($test_case_name, $method)) { |
|
621 | + return false; |
|
622 | + } |
|
623 | + } |
|
624 | + return true; |
|
625 | + } |
|
626 | + |
|
627 | + /** |
|
628 | + * Every reporter gets a chance to wrap the invoker. |
|
629 | + * @param SimpleInvoker $invoker Individual test runner. |
|
630 | + * @return SimpleInvoker Wrapped test runner. |
|
631 | + * @access public |
|
632 | + */ |
|
633 | + function &createInvoker($invoker) { |
|
634 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
635 | + $invoker = $this->_reporters[$i]->createInvoker($invoker); |
|
636 | + } |
|
637 | + return $invoker; |
|
638 | + } |
|
639 | + |
|
640 | + /** |
|
641 | + * Paints the start of a group test. |
|
642 | + * @param string $test_name Name of test or other label. |
|
643 | + * @param integer $size Number of test cases starting. |
|
644 | + * @access public |
|
645 | + */ |
|
646 | + function paintGroupStart($test_name, $size) { |
|
647 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
648 | + $this->_reporters[$i]->paintGroupStart($test_name, $size); |
|
649 | + } |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * Paints the end of a group test. |
|
654 | + * @param string $test_name Name of test or other label. |
|
655 | + * @access public |
|
656 | + */ |
|
657 | + function paintGroupEnd($test_name) { |
|
658 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
659 | + $this->_reporters[$i]->paintGroupEnd($test_name); |
|
660 | + } |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * Paints the start of a test case. |
|
665 | + * @param string $test_name Name of test or other label. |
|
666 | + * @access public |
|
667 | + */ |
|
668 | + function paintCaseStart($test_name) { |
|
669 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
670 | + $this->_reporters[$i]->paintCaseStart($test_name); |
|
671 | + } |
|
672 | + } |
|
673 | + |
|
674 | + /** |
|
675 | + * Paints the end of a test case. |
|
676 | + * @param string $test_name Name of test or other label. |
|
677 | + * @access public |
|
678 | + */ |
|
679 | + function paintCaseEnd($test_name) { |
|
680 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
681 | + $this->_reporters[$i]->paintCaseEnd($test_name); |
|
682 | + } |
|
683 | + } |
|
684 | + |
|
685 | + /** |
|
686 | + * Paints the start of a test method. |
|
687 | + * @param string $test_name Name of test or other label. |
|
688 | + * @access public |
|
689 | + */ |
|
690 | + function paintMethodStart($test_name) { |
|
691 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
692 | + $this->_reporters[$i]->paintMethodStart($test_name); |
|
693 | + } |
|
694 | + } |
|
695 | + |
|
696 | + /** |
|
697 | + * Paints the end of a test method. |
|
698 | + * @param string $test_name Name of test or other label. |
|
699 | + * @access public |
|
700 | + */ |
|
701 | + function paintMethodEnd($test_name) { |
|
702 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
703 | + $this->_reporters[$i]->paintMethodEnd($test_name); |
|
704 | + } |
|
705 | + } |
|
706 | + |
|
707 | + /** |
|
708 | + * Chains to the wrapped reporter. |
|
709 | + * @param string $message Message is ignored. |
|
710 | + * @access public |
|
711 | + */ |
|
712 | + function paintPass($message) { |
|
713 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
714 | + $this->_reporters[$i]->paintPass($message); |
|
715 | + } |
|
716 | + } |
|
717 | + |
|
718 | + /** |
|
719 | + * Chains to the wrapped reporter. |
|
720 | + * @param string $message Message is ignored. |
|
721 | + * @access public |
|
722 | + */ |
|
723 | + function paintFail($message) { |
|
724 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
725 | + $this->_reporters[$i]->paintFail($message); |
|
726 | + } |
|
727 | + } |
|
728 | + |
|
729 | + /** |
|
730 | + * Chains to the wrapped reporter. |
|
731 | + * @param string $message Text of error formatted by |
|
732 | + * the test case. |
|
733 | + * @access public |
|
734 | + */ |
|
735 | + function paintError($message) { |
|
736 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
737 | + $this->_reporters[$i]->paintError($message); |
|
738 | + } |
|
739 | + } |
|
740 | + |
|
741 | + /** |
|
742 | + * Chains to the wrapped reporter. |
|
743 | + * @param string $message Text to display. |
|
744 | + * @access public |
|
745 | + */ |
|
746 | + function paintMessage($message) { |
|
747 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
748 | + $this->_reporters[$i]->paintMessage($message); |
|
749 | + } |
|
750 | + } |
|
751 | + |
|
752 | + /** |
|
753 | + * Chains to the wrapped reporter. |
|
754 | + * @param string $message Text to display. |
|
755 | + * @access public |
|
756 | + */ |
|
757 | + function paintFormattedMessage($message) { |
|
758 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
759 | + $this->_reporters[$i]->paintFormattedMessage($message); |
|
760 | + } |
|
761 | + } |
|
762 | + |
|
763 | + /** |
|
764 | + * Chains to the wrapped reporter. |
|
765 | + * @param string $type Event type as text. |
|
766 | + * @param mixed $payload Message or object. |
|
767 | + * @return boolean Should return false if this |
|
768 | + * type of signal should fail the |
|
769 | + * test suite. |
|
770 | + * @access public |
|
771 | + */ |
|
772 | + function paintSignal($type, $payload) { |
|
773 | + for ($i = 0; $i < count($this->_reporters); $i++) { |
|
774 | + $this->_reporters[$i]->paintSignal($type, $payload); |
|
775 | + } |
|
776 | + } |
|
777 | + } |
|
778 | 778 | \ No newline at end of file |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @access public |
54 | 54 | */ |
55 | 55 | function shouldInvoke($test_case_name, $method) { |
56 | - return ! $this->_is_dry_run; |
|
56 | + return !$this->_is_dry_run; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * @access public |
249 | 249 | */ |
250 | 250 | function paintGroupStart($test_name, $size) { |
251 | - if (! isset($this->_size)) { |
|
251 | + if (!isset($this->_size)) { |
|
252 | 252 | $this->_size = $size; |
253 | 253 | } |
254 | 254 | if (count($this->_test_stack) == 0) { |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @access public |
281 | 281 | */ |
282 | 282 | function paintCaseStart($test_name) { |
283 | - if (! isset($this->_size)) { |
|
283 | + if (!isset($this->_size)) { |
|
284 | 284 | $this->_size = 1; |
285 | 285 | } |
286 | 286 | if (count($this->_test_stack) == 0) { |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | */ |
601 | 601 | function getStatus() { |
602 | 602 | for ($i = 0; $i < count($this->_reporters); $i++) { |
603 | - if (! $this->_reporters[$i]->getStatus()) { |
|
603 | + if (!$this->_reporters[$i]->getStatus()) { |
|
604 | 604 | return false; |
605 | 605 | } |
606 | 606 | } |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | */ |
617 | 617 | function shouldInvoke($test_case_name, $method) { |
618 | 618 | for ($i = 0; $i < count($this->_reporters); $i++) { |
619 | - if (! $this->_reporters[$i]->shouldInvoke($test_case_name, $method)) { |
|
619 | + if (!$this->_reporters[$i]->shouldInvoke($test_case_name, $method)) { |
|
620 | 620 | return false; |
621 | 621 | } |
622 | 622 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Accessor for the last output. |
56 | - * @return array Output as array of lines. |
|
56 | + * @return boolean Output as array of lines. |
|
57 | 57 | * @access public |
58 | 58 | */ |
59 | 59 | function getOutputAsList() { |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | |
121 | 121 | /** |
122 | 122 | * Accessor for the last output. |
123 | - * @return array Output as array of lines. |
|
123 | + * @return boolean Output as array of lines. |
|
124 | 124 | * @access public |
125 | 125 | */ |
126 | 126 | function getOutputAsList() { |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | /** |
287 | 287 | * Accessor for current shell. Used for testing the |
288 | 288 | * the tester itself. |
289 | - * @return Shell Current shell. |
|
289 | + * @return SimpleShell Current shell. |
|
290 | 290 | * @access protected |
291 | 291 | */ |
292 | 292 | function &_getShell() { |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | |
296 | 296 | /** |
297 | 297 | * Factory for the shell to run the command on. |
298 | - * @return Shell New shell object. |
|
298 | + * @return SimpleShell New shell object. |
|
299 | 299 | * @access protected |
300 | 300 | */ |
301 | 301 | function &_createShell() { |
@@ -1,305 +1,305 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage UnitTester |
|
6 | - * @version $Id: shell_tester.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | - */ |
|
2 | + /** |
|
3 | + * base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage UnitTester |
|
6 | + * @version $Id: shell_tester.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | + */ |
|
8 | 8 | |
9 | - /**#@+ |
|
9 | + /**#@+ |
|
10 | 10 | * include other SimpleTest class files |
11 | 11 | */ |
12 | - require_once(dirname(__FILE__) . '/test_case.php'); |
|
13 | - /**#@-*/ |
|
12 | + require_once(dirname(__FILE__) . '/test_case.php'); |
|
13 | + /**#@-*/ |
|
14 | 14 | |
15 | - /** |
|
16 | - * Wrapper for exec() functionality. |
|
15 | + /** |
|
16 | + * Wrapper for exec() functionality. |
|
17 | 17 | * @package SimpleTest |
18 | 18 | * @subpackage UnitTester |
19 | - */ |
|
20 | - class SimpleShell { |
|
21 | - protected $_output; |
|
19 | + */ |
|
20 | + class SimpleShell { |
|
21 | + protected $_output; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Executes the shell comand and stashes the output. |
|
25 | - * @access public |
|
26 | - */ |
|
27 | - function SimpleShell() { |
|
28 | - $this->_output = false; |
|
29 | - } |
|
23 | + /** |
|
24 | + * Executes the shell comand and stashes the output. |
|
25 | + * @access public |
|
26 | + */ |
|
27 | + function SimpleShell() { |
|
28 | + $this->_output = false; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Actually runs the command. Does not trap the |
|
33 | - * error stream output as this need PHP 4.3+. |
|
34 | - * @param string $command The actual command line |
|
35 | - * to run. |
|
36 | - * @return integer Exit code. |
|
37 | - * @access public |
|
38 | - */ |
|
39 | - function execute($command) { |
|
40 | - $this->_output = false; |
|
41 | - exec($command, $this->_output, $ret); |
|
42 | - return $ret; |
|
43 | - } |
|
31 | + /** |
|
32 | + * Actually runs the command. Does not trap the |
|
33 | + * error stream output as this need PHP 4.3+. |
|
34 | + * @param string $command The actual command line |
|
35 | + * to run. |
|
36 | + * @return integer Exit code. |
|
37 | + * @access public |
|
38 | + */ |
|
39 | + function execute($command) { |
|
40 | + $this->_output = false; |
|
41 | + exec($command, $this->_output, $ret); |
|
42 | + return $ret; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Accessor for the last output. |
|
47 | - * @return string Output as text. |
|
48 | - * @access public |
|
49 | - */ |
|
50 | - function getOutput() { |
|
51 | - return implode("\n", $this->_output); |
|
52 | - } |
|
45 | + /** |
|
46 | + * Accessor for the last output. |
|
47 | + * @return string Output as text. |
|
48 | + * @access public |
|
49 | + */ |
|
50 | + function getOutput() { |
|
51 | + return implode("\n", $this->_output); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Accessor for the last output. |
|
56 | - * @return array Output as array of lines. |
|
57 | - * @access public |
|
58 | - */ |
|
54 | + /** |
|
55 | + * Accessor for the last output. |
|
56 | + * @return array Output as array of lines. |
|
57 | + * @access public |
|
58 | + */ |
|
59 | 59 | function getOutputAsList() { |
60 | 60 | return $this->_output; |
61 | 61 | } |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Test case for testing of command line scripts and |
|
66 | - * utilities. Usually scripts taht are external to the |
|
67 | - * PHP code, but support it in some way. |
|
64 | + /** |
|
65 | + * Test case for testing of command line scripts and |
|
66 | + * utilities. Usually scripts taht are external to the |
|
67 | + * PHP code, but support it in some way. |
|
68 | 68 | * @package SimpleTest |
69 | 69 | * @subpackage UnitTester |
70 | - */ |
|
71 | - class ShellTestCase extends SimpleTestCase { |
|
72 | - protected $_current_shell; |
|
73 | - protected $_last_status; |
|
74 | - protected $_last_command; |
|
70 | + */ |
|
71 | + class ShellTestCase extends SimpleTestCase { |
|
72 | + protected $_current_shell; |
|
73 | + protected $_last_status; |
|
74 | + protected $_last_command; |
|
75 | 75 | |
76 | - /** |
|
77 | - * Creates an empty test case. Should be subclassed |
|
78 | - * with test methods for a functional test case. |
|
79 | - * @param string $label Name of test case. Will use |
|
80 | - * the class name if none specified. |
|
81 | - * @access public |
|
82 | - */ |
|
83 | - function ShellTestCase($label = false) { |
|
84 | - $this->SimpleTestCase($label); |
|
85 | - $this->_current_shell = $this->_createShell(); |
|
86 | - $this->_last_status = false; |
|
87 | - $this->_last_command = ''; |
|
88 | - } |
|
76 | + /** |
|
77 | + * Creates an empty test case. Should be subclassed |
|
78 | + * with test methods for a functional test case. |
|
79 | + * @param string $label Name of test case. Will use |
|
80 | + * the class name if none specified. |
|
81 | + * @access public |
|
82 | + */ |
|
83 | + function ShellTestCase($label = false) { |
|
84 | + $this->SimpleTestCase($label); |
|
85 | + $this->_current_shell = $this->_createShell(); |
|
86 | + $this->_last_status = false; |
|
87 | + $this->_last_command = ''; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Executes a command and buffers the results. |
|
92 | - * @param string $command Command to run. |
|
93 | - * @return boolean True if zero exit code. |
|
94 | - * @access public |
|
95 | - */ |
|
96 | - function execute($command) { |
|
97 | - $shell = $this->_getShell(); |
|
98 | - $this->_last_status = $shell->execute($command); |
|
99 | - $this->_last_command = $command; |
|
100 | - return ($this->_last_status === 0); |
|
101 | - } |
|
90 | + /** |
|
91 | + * Executes a command and buffers the results. |
|
92 | + * @param string $command Command to run. |
|
93 | + * @return boolean True if zero exit code. |
|
94 | + * @access public |
|
95 | + */ |
|
96 | + function execute($command) { |
|
97 | + $shell = $this->_getShell(); |
|
98 | + $this->_last_status = $shell->execute($command); |
|
99 | + $this->_last_command = $command; |
|
100 | + return ($this->_last_status === 0); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Dumps the output of the last command. |
|
105 | - * @access public |
|
106 | - */ |
|
107 | - function dumpOutput() { |
|
108 | - $this->dump($this->getOutput()); |
|
109 | - } |
|
103 | + /** |
|
104 | + * Dumps the output of the last command. |
|
105 | + * @access public |
|
106 | + */ |
|
107 | + function dumpOutput() { |
|
108 | + $this->dump($this->getOutput()); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Accessor for the last output. |
|
113 | - * @return string Output as text. |
|
114 | - * @access public |
|
115 | - */ |
|
111 | + /** |
|
112 | + * Accessor for the last output. |
|
113 | + * @return string Output as text. |
|
114 | + * @access public |
|
115 | + */ |
|
116 | 116 | function getOutput() { |
117 | - $shell = $this->_getShell(); |
|
118 | - return $shell->getOutput(); |
|
117 | + $shell = $this->_getShell(); |
|
118 | + return $shell->getOutput(); |
|
119 | 119 | } |
120 | 120 | |
121 | - /** |
|
122 | - * Accessor for the last output. |
|
123 | - * @return array Output as array of lines. |
|
124 | - * @access public |
|
125 | - */ |
|
121 | + /** |
|
122 | + * Accessor for the last output. |
|
123 | + * @return array Output as array of lines. |
|
124 | + * @access public |
|
125 | + */ |
|
126 | 126 | function getOutputAsList() { |
127 | - $shell = $this->_getShell(); |
|
128 | - return $shell->getOutputAsList(); |
|
127 | + $shell = $this->_getShell(); |
|
128 | + return $shell->getOutputAsList(); |
|
129 | 129 | } |
130 | 130 | |
131 | - /** |
|
132 | - * Will trigger a pass if the two parameters have |
|
133 | - * the same value only. Otherwise a fail. This |
|
134 | - * is for testing hand extracted text, etc. |
|
135 | - * @param mixed $first Value to compare. |
|
136 | - * @param mixed $second Value to compare. |
|
137 | - * @param string $message Message to display. |
|
138 | - * @return boolean True on pass |
|
139 | - * @access public |
|
140 | - */ |
|
141 | - function assertEqual($first, $second, $message = "%s") { |
|
142 | - return $this->assert( |
|
143 | - new EqualExpectation($first), |
|
144 | - $second, |
|
145 | - $message); |
|
146 | - } |
|
131 | + /** |
|
132 | + * Will trigger a pass if the two parameters have |
|
133 | + * the same value only. Otherwise a fail. This |
|
134 | + * is for testing hand extracted text, etc. |
|
135 | + * @param mixed $first Value to compare. |
|
136 | + * @param mixed $second Value to compare. |
|
137 | + * @param string $message Message to display. |
|
138 | + * @return boolean True on pass |
|
139 | + * @access public |
|
140 | + */ |
|
141 | + function assertEqual($first, $second, $message = "%s") { |
|
142 | + return $this->assert( |
|
143 | + new EqualExpectation($first), |
|
144 | + $second, |
|
145 | + $message); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Will trigger a pass if the two parameters have |
|
150 | - * a different value. Otherwise a fail. This |
|
151 | - * is for testing hand extracted text, etc. |
|
152 | - * @param mixed $first Value to compare. |
|
153 | - * @param mixed $second Value to compare. |
|
154 | - * @param string $message Message to display. |
|
155 | - * @return boolean True on pass |
|
156 | - * @access public |
|
157 | - */ |
|
158 | - function assertNotEqual($first, $second, $message = "%s") { |
|
159 | - return $this->assert( |
|
160 | - new NotEqualExpectation($first), |
|
161 | - $second, |
|
162 | - $message); |
|
163 | - } |
|
148 | + /** |
|
149 | + * Will trigger a pass if the two parameters have |
|
150 | + * a different value. Otherwise a fail. This |
|
151 | + * is for testing hand extracted text, etc. |
|
152 | + * @param mixed $first Value to compare. |
|
153 | + * @param mixed $second Value to compare. |
|
154 | + * @param string $message Message to display. |
|
155 | + * @return boolean True on pass |
|
156 | + * @access public |
|
157 | + */ |
|
158 | + function assertNotEqual($first, $second, $message = "%s") { |
|
159 | + return $this->assert( |
|
160 | + new NotEqualExpectation($first), |
|
161 | + $second, |
|
162 | + $message); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Tests the last status code from the shell. |
|
167 | - * @param integer $status Expected status of last |
|
168 | - * command. |
|
169 | - * @param string $message Message to display. |
|
170 | - * @return boolean True if pass. |
|
171 | - * @access public |
|
172 | - */ |
|
173 | - function assertExitCode($status, $message = "%s") { |
|
174 | - $message = sprintf($message, "Expected status code of [$status] from [" . |
|
175 | - $this->_last_command . "], but got [" . |
|
176 | - $this->_last_status . "]"); |
|
177 | - return $this->assertTrue($status === $this->_last_status, $message); |
|
178 | - } |
|
165 | + /** |
|
166 | + * Tests the last status code from the shell. |
|
167 | + * @param integer $status Expected status of last |
|
168 | + * command. |
|
169 | + * @param string $message Message to display. |
|
170 | + * @return boolean True if pass. |
|
171 | + * @access public |
|
172 | + */ |
|
173 | + function assertExitCode($status, $message = "%s") { |
|
174 | + $message = sprintf($message, "Expected status code of [$status] from [" . |
|
175 | + $this->_last_command . "], but got [" . |
|
176 | + $this->_last_status . "]"); |
|
177 | + return $this->assertTrue($status === $this->_last_status, $message); |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * Attempt to exactly match the combined STDERR and |
|
182 | - * STDOUT output. |
|
183 | - * @param string $expected Expected output. |
|
184 | - * @param string $message Message to display. |
|
185 | - * @return boolean True if pass. |
|
186 | - * @access public |
|
187 | - */ |
|
188 | - function assertOutput($expected, $message = "%s") { |
|
189 | - $shell = $this->_getShell(); |
|
190 | - return $this->assert( |
|
191 | - new EqualExpectation($expected), |
|
192 | - $shell->getOutput(), |
|
193 | - $message); |
|
194 | - } |
|
180 | + /** |
|
181 | + * Attempt to exactly match the combined STDERR and |
|
182 | + * STDOUT output. |
|
183 | + * @param string $expected Expected output. |
|
184 | + * @param string $message Message to display. |
|
185 | + * @return boolean True if pass. |
|
186 | + * @access public |
|
187 | + */ |
|
188 | + function assertOutput($expected, $message = "%s") { |
|
189 | + $shell = $this->_getShell(); |
|
190 | + return $this->assert( |
|
191 | + new EqualExpectation($expected), |
|
192 | + $shell->getOutput(), |
|
193 | + $message); |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Scans the output for a Perl regex. If found |
|
198 | - * anywhere it passes, else it fails. |
|
199 | - * @param string $pattern Regex to search for. |
|
200 | - * @param string $message Message to display. |
|
201 | - * @return boolean True if pass. |
|
202 | - * @access public |
|
203 | - */ |
|
204 | - function assertOutputPattern($pattern, $message = "%s") { |
|
205 | - $shell = $this->_getShell(); |
|
206 | - return $this->assert( |
|
207 | - new PatternExpectation($pattern), |
|
208 | - $shell->getOutput(), |
|
209 | - $message); |
|
210 | - } |
|
196 | + /** |
|
197 | + * Scans the output for a Perl regex. If found |
|
198 | + * anywhere it passes, else it fails. |
|
199 | + * @param string $pattern Regex to search for. |
|
200 | + * @param string $message Message to display. |
|
201 | + * @return boolean True if pass. |
|
202 | + * @access public |
|
203 | + */ |
|
204 | + function assertOutputPattern($pattern, $message = "%s") { |
|
205 | + $shell = $this->_getShell(); |
|
206 | + return $this->assert( |
|
207 | + new PatternExpectation($pattern), |
|
208 | + $shell->getOutput(), |
|
209 | + $message); |
|
210 | + } |
|
211 | 211 | |
212 | - /** |
|
213 | - * If a Perl regex is found anywhere in the current |
|
214 | - * output then a failure is generated, else a pass. |
|
215 | - * @param string $pattern Regex to search for. |
|
216 | - * @param $message Message to display. |
|
217 | - * @return boolean True if pass. |
|
218 | - * @access public |
|
219 | - */ |
|
220 | - function assertNoOutputPattern($pattern, $message = "%s") { |
|
221 | - $shell = $this->_getShell(); |
|
222 | - return $this->assert( |
|
223 | - new NoPatternExpectation($pattern), |
|
224 | - $shell->getOutput(), |
|
225 | - $message); |
|
226 | - } |
|
212 | + /** |
|
213 | + * If a Perl regex is found anywhere in the current |
|
214 | + * output then a failure is generated, else a pass. |
|
215 | + * @param string $pattern Regex to search for. |
|
216 | + * @param $message Message to display. |
|
217 | + * @return boolean True if pass. |
|
218 | + * @access public |
|
219 | + */ |
|
220 | + function assertNoOutputPattern($pattern, $message = "%s") { |
|
221 | + $shell = $this->_getShell(); |
|
222 | + return $this->assert( |
|
223 | + new NoPatternExpectation($pattern), |
|
224 | + $shell->getOutput(), |
|
225 | + $message); |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * File existence check. |
|
230 | - * @param string $path Full filename and path. |
|
231 | - * @param string $message Message to display. |
|
232 | - * @return boolean True if pass. |
|
233 | - * @access public |
|
234 | - */ |
|
235 | - function assertFileExists($path, $message = "%s") { |
|
236 | - $message = sprintf($message, "File [$path] should exist"); |
|
237 | - return $this->assertTrue(file_exists($path), $message); |
|
238 | - } |
|
228 | + /** |
|
229 | + * File existence check. |
|
230 | + * @param string $path Full filename and path. |
|
231 | + * @param string $message Message to display. |
|
232 | + * @return boolean True if pass. |
|
233 | + * @access public |
|
234 | + */ |
|
235 | + function assertFileExists($path, $message = "%s") { |
|
236 | + $message = sprintf($message, "File [$path] should exist"); |
|
237 | + return $this->assertTrue(file_exists($path), $message); |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * File non-existence check. |
|
242 | - * @param string $path Full filename and path. |
|
243 | - * @param string $message Message to display. |
|
244 | - * @return boolean True if pass. |
|
245 | - * @access public |
|
246 | - */ |
|
247 | - function assertFileNotExists($path, $message = "%s") { |
|
248 | - $message = sprintf($message, "File [$path] should not exist"); |
|
249 | - return $this->assertFalse(file_exists($path), $message); |
|
250 | - } |
|
240 | + /** |
|
241 | + * File non-existence check. |
|
242 | + * @param string $path Full filename and path. |
|
243 | + * @param string $message Message to display. |
|
244 | + * @return boolean True if pass. |
|
245 | + * @access public |
|
246 | + */ |
|
247 | + function assertFileNotExists($path, $message = "%s") { |
|
248 | + $message = sprintf($message, "File [$path] should not exist"); |
|
249 | + return $this->assertFalse(file_exists($path), $message); |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * Scans a file for a Perl regex. If found |
|
254 | - * anywhere it passes, else it fails. |
|
255 | - * @param string $pattern Regex to search for. |
|
256 | - * @param string $path Full filename and path. |
|
257 | - * @param string $message Message to display. |
|
258 | - * @return boolean True if pass. |
|
259 | - * @access public |
|
260 | - */ |
|
261 | - function assertFilePattern($pattern, $path, $message = "%s") { |
|
262 | - $shell = $this->_getShell(); |
|
263 | - return $this->assert( |
|
264 | - new PatternExpectation($pattern), |
|
265 | - implode('', file($path)), |
|
266 | - $message); |
|
267 | - } |
|
252 | + /** |
|
253 | + * Scans a file for a Perl regex. If found |
|
254 | + * anywhere it passes, else it fails. |
|
255 | + * @param string $pattern Regex to search for. |
|
256 | + * @param string $path Full filename and path. |
|
257 | + * @param string $message Message to display. |
|
258 | + * @return boolean True if pass. |
|
259 | + * @access public |
|
260 | + */ |
|
261 | + function assertFilePattern($pattern, $path, $message = "%s") { |
|
262 | + $shell = $this->_getShell(); |
|
263 | + return $this->assert( |
|
264 | + new PatternExpectation($pattern), |
|
265 | + implode('', file($path)), |
|
266 | + $message); |
|
267 | + } |
|
268 | 268 | |
269 | - /** |
|
270 | - * If a Perl regex is found anywhere in the named |
|
271 | - * file then a failure is generated, else a pass. |
|
272 | - * @param string $pattern Regex to search for. |
|
273 | - * @param string $path Full filename and path. |
|
274 | - * @param string $message Message to display. |
|
275 | - * @return boolean True if pass. |
|
276 | - * @access public |
|
277 | - */ |
|
278 | - function assertNoFilePattern($pattern, $path, $message = "%s") { |
|
279 | - $shell = $this->_getShell(); |
|
280 | - return $this->assert( |
|
281 | - new NoPatternExpectation($pattern), |
|
282 | - implode('', file($path)), |
|
283 | - $message); |
|
284 | - } |
|
269 | + /** |
|
270 | + * If a Perl regex is found anywhere in the named |
|
271 | + * file then a failure is generated, else a pass. |
|
272 | + * @param string $pattern Regex to search for. |
|
273 | + * @param string $path Full filename and path. |
|
274 | + * @param string $message Message to display. |
|
275 | + * @return boolean True if pass. |
|
276 | + * @access public |
|
277 | + */ |
|
278 | + function assertNoFilePattern($pattern, $path, $message = "%s") { |
|
279 | + $shell = $this->_getShell(); |
|
280 | + return $this->assert( |
|
281 | + new NoPatternExpectation($pattern), |
|
282 | + implode('', file($path)), |
|
283 | + $message); |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * Accessor for current shell. Used for testing the |
|
288 | - * the tester itself. |
|
289 | - * @return Shell Current shell. |
|
290 | - * @access protected |
|
291 | - */ |
|
292 | - function &_getShell() { |
|
293 | - return $this->_current_shell; |
|
294 | - } |
|
286 | + /** |
|
287 | + * Accessor for current shell. Used for testing the |
|
288 | + * the tester itself. |
|
289 | + * @return Shell Current shell. |
|
290 | + * @access protected |
|
291 | + */ |
|
292 | + function &_getShell() { |
|
293 | + return $this->_current_shell; |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * Factory for the shell to run the command on. |
|
298 | - * @return Shell New shell object. |
|
299 | - * @access protected |
|
300 | - */ |
|
301 | - function &_createShell() { |
|
302 | - $shell = new SimpleShell(); |
|
303 | - return $shell; |
|
304 | - } |
|
305 | - } |
|
306 | 296 | \ No newline at end of file |
297 | + /** |
|
298 | + * Factory for the shell to run the command on. |
|
299 | + * @return Shell New shell object. |
|
300 | + * @access protected |
|
301 | + */ |
|
302 | + function &_createShell() { |
|
303 | + $shell = new SimpleShell(); |
|
304 | + return $shell; |
|
305 | + } |
|
306 | + } |
|
307 | 307 | \ No newline at end of file |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * the tests differently. This version simply |
68 | 68 | * passes it straight through. |
69 | 69 | * @param SimpleReporter $reporter Incoming observer. |
70 | - * @return SimpleReporter |
|
70 | + * @return SimpleRunner |
|
71 | 71 | * @access protected |
72 | 72 | */ |
73 | 73 | function _createRunner($reporter) { |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * Sends a formatted dump of a variable to the |
238 | 238 | * test suite for those emergency debugging |
239 | 239 | * situations. |
240 | - * @param mixed $variable Variable to display. |
|
240 | + * @param string|boolean $variable Variable to display. |
|
241 | 241 | * @param string $message Message to display. |
242 | 242 | * @return mixed The original variable. |
243 | 243 | * @access public |
@@ -323,10 +323,6 @@ discard block |
||
323 | 323 | /** |
324 | 324 | * Adds a test into the suite by class name. The class will |
325 | 325 | * be instantiated as needed. |
326 | - * @param SimpleTestCase $test_case Suite or individual test |
|
327 | - * case implementing the |
|
328 | - * runnable test interface. |
|
329 | - * @access public |
|
330 | 326 | */ |
331 | 327 | function addTestClass($class) { |
332 | 328 | $this->_test_cases[] = $class; |
@@ -1,552 +1,552 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * Base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage UnitTester |
|
6 | - * @version $Id: simple_test.php 1532 2006-12-01 12:28:55Z xue $ |
|
7 | - */ |
|
8 | - |
|
9 | - /**#@+ |
|
2 | + /** |
|
3 | + * Base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage UnitTester |
|
6 | + * @version $Id: simple_test.php 1532 2006-12-01 12:28:55Z xue $ |
|
7 | + */ |
|
8 | + |
|
9 | + /**#@+ |
|
10 | 10 | * Includes SimpleTest files and defined the root constant |
11 | 11 | * for dependent libraries. |
12 | 12 | */ |
13 | - require_once(dirname(__FILE__) . '/errors.php'); |
|
14 | - require_once(dirname(__FILE__) . '/options.php'); |
|
15 | - require_once(dirname(__FILE__) . '/runner.php'); |
|
16 | - require_once(dirname(__FILE__) . '/scorer.php'); |
|
17 | - require_once(dirname(__FILE__) . '/expectation.php'); |
|
18 | - require_once(dirname(__FILE__) . '/dumper.php'); |
|
19 | - if (! defined('SIMPLE_TEST')) { |
|
20 | - define('SIMPLE_TEST', dirname(__FILE__) . '/'); |
|
21 | - } |
|
22 | - /**#@-*/ |
|
23 | - |
|
24 | - /** |
|
25 | - * Basic test case. This is the smallest unit of a test |
|
26 | - * suite. It searches for |
|
27 | - * all methods that start with the the string "test" and |
|
28 | - * runs them. Working test cases extend this class. |
|
13 | + require_once(dirname(__FILE__) . '/errors.php'); |
|
14 | + require_once(dirname(__FILE__) . '/options.php'); |
|
15 | + require_once(dirname(__FILE__) . '/runner.php'); |
|
16 | + require_once(dirname(__FILE__) . '/scorer.php'); |
|
17 | + require_once(dirname(__FILE__) . '/expectation.php'); |
|
18 | + require_once(dirname(__FILE__) . '/dumper.php'); |
|
19 | + if (! defined('SIMPLE_TEST')) { |
|
20 | + define('SIMPLE_TEST', dirname(__FILE__) . '/'); |
|
21 | + } |
|
22 | + /**#@-*/ |
|
23 | + |
|
24 | + /** |
|
25 | + * Basic test case. This is the smallest unit of a test |
|
26 | + * suite. It searches for |
|
27 | + * all methods that start with the the string "test" and |
|
28 | + * runs them. Working test cases extend this class. |
|
29 | 29 | * @package SimpleTest |
30 | 30 | * @subpackage UnitTester |
31 | - */ |
|
32 | - class SimpleTestCase { |
|
33 | - protected $_label; |
|
34 | - protected $_runner; |
|
35 | - |
|
36 | - /** |
|
37 | - * Sets up the test with no display. |
|
38 | - * @param string $label If no test name is given then |
|
39 | - * the class name is used. |
|
40 | - * @access public |
|
41 | - */ |
|
42 | - function SimpleTestCase($label = false) { |
|
43 | - $this->_label = $label ? $label : get_class($this); |
|
44 | - $this->_runner = false; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Accessor for the test name for subclasses. |
|
49 | - * @return string Name of the test. |
|
50 | - * @access public |
|
51 | - */ |
|
52 | - function getLabel() { |
|
53 | - return $this->_label; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Used to invoke the single tests. |
|
58 | - * @return SimpleInvoker Individual test runner. |
|
59 | - * @access public |
|
60 | - */ |
|
61 | - function createInvoker() { |
|
62 | - return new SimpleErrorTrappingInvoker(new SimpleInvoker($this)); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Can modify the incoming reporter so as to run |
|
67 | - * the tests differently. This version simply |
|
68 | - * passes it straight through. |
|
69 | - * @param SimpleReporter $reporter Incoming observer. |
|
70 | - * @return SimpleReporter |
|
71 | - * @access protected |
|
72 | - */ |
|
73 | - function _createRunner($reporter) { |
|
74 | - return new SimpleRunner($this, $reporter); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Uses reflection to run every method within itself |
|
79 | - * starting with the string "test" unless a method |
|
80 | - * is specified. |
|
81 | - * @param SimpleReporter $reporter Current test reporter. |
|
82 | - * @access public |
|
83 | - */ |
|
84 | - function run($reporter) { |
|
85 | - $reporter->paintCaseStart($this->getLabel()); |
|
86 | - $this->_runner = $this->_createRunner($reporter); |
|
87 | - $this->_runner->run(); |
|
88 | - $reporter->paintCaseEnd($this->getLabel()); |
|
89 | - return $reporter->getStatus(); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Sets up unit test wide variables at the start |
|
94 | - * of each test method. To be overridden in |
|
95 | - * actual user test cases. |
|
96 | - * @access public |
|
97 | - */ |
|
98 | - function setUp() { |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Clears the data set in the setUp() method call. |
|
103 | - * To be overridden by the user in actual user test cases. |
|
104 | - * @access public |
|
105 | - */ |
|
106 | - function tearDown() { |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Sends a pass event with a message. |
|
111 | - * @param string $message Message to send. |
|
112 | - * @access public |
|
113 | - */ |
|
114 | - function pass($message = "Pass") { |
|
115 | - $this->_runner->paintPass($message . $this->getAssertionLine(' at line [%d]')); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Sends a fail event with a message. |
|
120 | - * @param string $message Message to send. |
|
121 | - * @access public |
|
122 | - */ |
|
123 | - function fail($message = "Fail") { |
|
124 | - $this->_runner->paintFail($message . $this->getAssertionLine(' at line [%d]')); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Formats a PHP error and dispatches it to the |
|
129 | - * runner. |
|
130 | - * @param integer $severity PHP error code. |
|
131 | - * @param string $message Text of error. |
|
132 | - * @param string $file File error occoured in. |
|
133 | - * @param integer $line Line number of error. |
|
134 | - * @param hash $globals PHP super global arrays. |
|
135 | - * @access public |
|
136 | - */ |
|
137 | - function error($severity, $message, $file, $line, $globals) { |
|
138 | - $severity = SimpleErrorQueue::getSeverityAsString($severity); |
|
139 | - $this->_runner->paintError( |
|
140 | - "Unexpected PHP error [$message] severity [$severity] in [$file] line [$line]"); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Sends a user defined event to the test runner. |
|
145 | - * This is for small scale extension where |
|
146 | - * both the test case and either the runner or |
|
147 | - * display are subclassed. |
|
148 | - * @param string $type Type of event. |
|
149 | - * @param mixed $payload Object or message to deliver. |
|
150 | - * @access public |
|
151 | - */ |
|
152 | - function signal($type, $payload) { |
|
153 | - $this->_runner->paintSignal($type, $payload); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Cancels any outstanding errors. |
|
158 | - * @access public |
|
159 | - */ |
|
160 | - function swallowErrors() { |
|
161 | - $queue = SimpleErrorQueue::instance(); |
|
162 | - $queue->clear(); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Runs an expectation directly, for extending the |
|
167 | - * tests with new expectation classes. |
|
168 | - * @param SimpleExpectation $expectation Expectation subclass. |
|
169 | - * @param mixed $test_value Value to compare. |
|
170 | - * @param string $message Message to display. |
|
171 | - * @return boolean True on pass |
|
172 | - * @access public |
|
173 | - */ |
|
174 | - function assertExpectation($expectation, $test_value, $message = '%s') { |
|
175 | - return $this->assertTrue( |
|
176 | - $expectation->test($test_value), |
|
177 | - sprintf($message, $expectation->overlayMessage($test_value))); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Called from within the test methods to register |
|
182 | - * passes and failures. |
|
183 | - * @param boolean $result Pass on true. |
|
184 | - * @param string $message Message to display describing |
|
185 | - * the test state. |
|
186 | - * @return boolean True on pass |
|
187 | - * @access public |
|
188 | - */ |
|
189 | - function assertTrue($result, $message = false) { |
|
190 | - if (! $message) { |
|
191 | - $message = 'True assertion got ' . ($result ? 'True' : 'False'); |
|
192 | - } |
|
193 | - if ($result) { |
|
194 | - $this->pass($message); |
|
195 | - return true; |
|
196 | - } else { |
|
197 | - $this->fail($message); |
|
198 | - return false; |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Will be true on false and vice versa. False |
|
204 | - * is the PHP definition of false, so that null, |
|
205 | - * empty strings, zero and an empty array all count |
|
206 | - * as false. |
|
207 | - * @param boolean $result Pass on false. |
|
208 | - * @param string $message Message to display. |
|
209 | - * @return boolean True on pass |
|
210 | - * @access public |
|
211 | - */ |
|
212 | - function assertFalse($result, $message = false) { |
|
213 | - if (! $message) { |
|
214 | - $message = 'False assertion got ' . ($result ? 'True' : 'False'); |
|
215 | - } |
|
216 | - return $this->assertTrue(! $result, $message); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Uses a stack trace to find the line of an assertion. |
|
221 | - * @param string $format String formatting. |
|
222 | - * @param array $stack Stack frames top most first. Only |
|
223 | - * needed if not using the PHP |
|
224 | - * backtrace function. |
|
225 | - * @return string Line number of first assert* |
|
226 | - * method embedded in format string. |
|
227 | - * @access public |
|
228 | - */ |
|
229 | - function getAssertionLine($format = '%d', $stack = false) { |
|
230 | - if ($stack === false) { |
|
231 | - $stack = SimpleTestCompatibility::getStackTrace(); |
|
232 | - } |
|
233 | - return SimpleDumper::getFormattedAssertionLine($stack, $format); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Sends a formatted dump of a variable to the |
|
238 | - * test suite for those emergency debugging |
|
239 | - * situations. |
|
240 | - * @param mixed $variable Variable to display. |
|
241 | - * @param string $message Message to display. |
|
242 | - * @return mixed The original variable. |
|
243 | - * @access public |
|
244 | - */ |
|
245 | - function dump($variable, $message = false) { |
|
246 | - $formatted = SimpleDumper::dump($variable); |
|
247 | - if ($message) { |
|
248 | - $formatted = $message . "\n" . $formatted; |
|
249 | - } |
|
250 | - $this->_runner->paintFormattedMessage($formatted); |
|
251 | - return $variable; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Dispatches a text message straight to the |
|
256 | - * test suite. Useful for status bar displays. |
|
257 | - * @param string $message Message to show. |
|
258 | - * @access public |
|
259 | - */ |
|
260 | - function sendMessage($message) { |
|
261 | - $this->_runner->PaintMessage($message); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Accessor for the number of subtests. |
|
266 | - * @return integer Number of test cases. |
|
267 | - * @access public |
|
268 | - * @static |
|
269 | - */ |
|
270 | - static function getSize() { |
|
271 | - return 1; |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * This is a composite test class for combining |
|
277 | - * test cases and other RunnableTest classes into |
|
278 | - * a group test. |
|
31 | + */ |
|
32 | + class SimpleTestCase { |
|
33 | + protected $_label; |
|
34 | + protected $_runner; |
|
35 | + |
|
36 | + /** |
|
37 | + * Sets up the test with no display. |
|
38 | + * @param string $label If no test name is given then |
|
39 | + * the class name is used. |
|
40 | + * @access public |
|
41 | + */ |
|
42 | + function SimpleTestCase($label = false) { |
|
43 | + $this->_label = $label ? $label : get_class($this); |
|
44 | + $this->_runner = false; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Accessor for the test name for subclasses. |
|
49 | + * @return string Name of the test. |
|
50 | + * @access public |
|
51 | + */ |
|
52 | + function getLabel() { |
|
53 | + return $this->_label; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Used to invoke the single tests. |
|
58 | + * @return SimpleInvoker Individual test runner. |
|
59 | + * @access public |
|
60 | + */ |
|
61 | + function createInvoker() { |
|
62 | + return new SimpleErrorTrappingInvoker(new SimpleInvoker($this)); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Can modify the incoming reporter so as to run |
|
67 | + * the tests differently. This version simply |
|
68 | + * passes it straight through. |
|
69 | + * @param SimpleReporter $reporter Incoming observer. |
|
70 | + * @return SimpleReporter |
|
71 | + * @access protected |
|
72 | + */ |
|
73 | + function _createRunner($reporter) { |
|
74 | + return new SimpleRunner($this, $reporter); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Uses reflection to run every method within itself |
|
79 | + * starting with the string "test" unless a method |
|
80 | + * is specified. |
|
81 | + * @param SimpleReporter $reporter Current test reporter. |
|
82 | + * @access public |
|
83 | + */ |
|
84 | + function run($reporter) { |
|
85 | + $reporter->paintCaseStart($this->getLabel()); |
|
86 | + $this->_runner = $this->_createRunner($reporter); |
|
87 | + $this->_runner->run(); |
|
88 | + $reporter->paintCaseEnd($this->getLabel()); |
|
89 | + return $reporter->getStatus(); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Sets up unit test wide variables at the start |
|
94 | + * of each test method. To be overridden in |
|
95 | + * actual user test cases. |
|
96 | + * @access public |
|
97 | + */ |
|
98 | + function setUp() { |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Clears the data set in the setUp() method call. |
|
103 | + * To be overridden by the user in actual user test cases. |
|
104 | + * @access public |
|
105 | + */ |
|
106 | + function tearDown() { |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Sends a pass event with a message. |
|
111 | + * @param string $message Message to send. |
|
112 | + * @access public |
|
113 | + */ |
|
114 | + function pass($message = "Pass") { |
|
115 | + $this->_runner->paintPass($message . $this->getAssertionLine(' at line [%d]')); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Sends a fail event with a message. |
|
120 | + * @param string $message Message to send. |
|
121 | + * @access public |
|
122 | + */ |
|
123 | + function fail($message = "Fail") { |
|
124 | + $this->_runner->paintFail($message . $this->getAssertionLine(' at line [%d]')); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Formats a PHP error and dispatches it to the |
|
129 | + * runner. |
|
130 | + * @param integer $severity PHP error code. |
|
131 | + * @param string $message Text of error. |
|
132 | + * @param string $file File error occoured in. |
|
133 | + * @param integer $line Line number of error. |
|
134 | + * @param hash $globals PHP super global arrays. |
|
135 | + * @access public |
|
136 | + */ |
|
137 | + function error($severity, $message, $file, $line, $globals) { |
|
138 | + $severity = SimpleErrorQueue::getSeverityAsString($severity); |
|
139 | + $this->_runner->paintError( |
|
140 | + "Unexpected PHP error [$message] severity [$severity] in [$file] line [$line]"); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Sends a user defined event to the test runner. |
|
145 | + * This is for small scale extension where |
|
146 | + * both the test case and either the runner or |
|
147 | + * display are subclassed. |
|
148 | + * @param string $type Type of event. |
|
149 | + * @param mixed $payload Object or message to deliver. |
|
150 | + * @access public |
|
151 | + */ |
|
152 | + function signal($type, $payload) { |
|
153 | + $this->_runner->paintSignal($type, $payload); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Cancels any outstanding errors. |
|
158 | + * @access public |
|
159 | + */ |
|
160 | + function swallowErrors() { |
|
161 | + $queue = SimpleErrorQueue::instance(); |
|
162 | + $queue->clear(); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Runs an expectation directly, for extending the |
|
167 | + * tests with new expectation classes. |
|
168 | + * @param SimpleExpectation $expectation Expectation subclass. |
|
169 | + * @param mixed $test_value Value to compare. |
|
170 | + * @param string $message Message to display. |
|
171 | + * @return boolean True on pass |
|
172 | + * @access public |
|
173 | + */ |
|
174 | + function assertExpectation($expectation, $test_value, $message = '%s') { |
|
175 | + return $this->assertTrue( |
|
176 | + $expectation->test($test_value), |
|
177 | + sprintf($message, $expectation->overlayMessage($test_value))); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Called from within the test methods to register |
|
182 | + * passes and failures. |
|
183 | + * @param boolean $result Pass on true. |
|
184 | + * @param string $message Message to display describing |
|
185 | + * the test state. |
|
186 | + * @return boolean True on pass |
|
187 | + * @access public |
|
188 | + */ |
|
189 | + function assertTrue($result, $message = false) { |
|
190 | + if (! $message) { |
|
191 | + $message = 'True assertion got ' . ($result ? 'True' : 'False'); |
|
192 | + } |
|
193 | + if ($result) { |
|
194 | + $this->pass($message); |
|
195 | + return true; |
|
196 | + } else { |
|
197 | + $this->fail($message); |
|
198 | + return false; |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Will be true on false and vice versa. False |
|
204 | + * is the PHP definition of false, so that null, |
|
205 | + * empty strings, zero and an empty array all count |
|
206 | + * as false. |
|
207 | + * @param boolean $result Pass on false. |
|
208 | + * @param string $message Message to display. |
|
209 | + * @return boolean True on pass |
|
210 | + * @access public |
|
211 | + */ |
|
212 | + function assertFalse($result, $message = false) { |
|
213 | + if (! $message) { |
|
214 | + $message = 'False assertion got ' . ($result ? 'True' : 'False'); |
|
215 | + } |
|
216 | + return $this->assertTrue(! $result, $message); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Uses a stack trace to find the line of an assertion. |
|
221 | + * @param string $format String formatting. |
|
222 | + * @param array $stack Stack frames top most first. Only |
|
223 | + * needed if not using the PHP |
|
224 | + * backtrace function. |
|
225 | + * @return string Line number of first assert* |
|
226 | + * method embedded in format string. |
|
227 | + * @access public |
|
228 | + */ |
|
229 | + function getAssertionLine($format = '%d', $stack = false) { |
|
230 | + if ($stack === false) { |
|
231 | + $stack = SimpleTestCompatibility::getStackTrace(); |
|
232 | + } |
|
233 | + return SimpleDumper::getFormattedAssertionLine($stack, $format); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Sends a formatted dump of a variable to the |
|
238 | + * test suite for those emergency debugging |
|
239 | + * situations. |
|
240 | + * @param mixed $variable Variable to display. |
|
241 | + * @param string $message Message to display. |
|
242 | + * @return mixed The original variable. |
|
243 | + * @access public |
|
244 | + */ |
|
245 | + function dump($variable, $message = false) { |
|
246 | + $formatted = SimpleDumper::dump($variable); |
|
247 | + if ($message) { |
|
248 | + $formatted = $message . "\n" . $formatted; |
|
249 | + } |
|
250 | + $this->_runner->paintFormattedMessage($formatted); |
|
251 | + return $variable; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Dispatches a text message straight to the |
|
256 | + * test suite. Useful for status bar displays. |
|
257 | + * @param string $message Message to show. |
|
258 | + * @access public |
|
259 | + */ |
|
260 | + function sendMessage($message) { |
|
261 | + $this->_runner->PaintMessage($message); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Accessor for the number of subtests. |
|
266 | + * @return integer Number of test cases. |
|
267 | + * @access public |
|
268 | + * @static |
|
269 | + */ |
|
270 | + static function getSize() { |
|
271 | + return 1; |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * This is a composite test class for combining |
|
277 | + * test cases and other RunnableTest classes into |
|
278 | + * a group test. |
|
279 | 279 | * @package SimpleTest |
280 | 280 | * @subpackage UnitTester |
281 | - */ |
|
282 | - class GroupTest { |
|
283 | - protected $_label; |
|
284 | - protected $_test_cases; |
|
285 | - protected $_old_track_errors; |
|
286 | - protected $_xdebug_is_enabled; |
|
287 | - |
|
288 | - /** |
|
289 | - * Sets the name of the test suite. |
|
290 | - * @param string $label Name sent at the start and end |
|
291 | - * of the test. |
|
292 | - * @access public |
|
293 | - */ |
|
294 | - function GroupTest($label) { |
|
295 | - $this->_label = $label; |
|
296 | - $this->_test_cases = array(); |
|
297 | - $this->_old_track_errors = ini_get('track_errors'); |
|
298 | - $this->_xdebug_is_enabled = function_exists('xdebug_is_enabled') ? |
|
299 | - xdebug_is_enabled() : false; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Accessor for the test name for subclasses. |
|
304 | - * @return string Name of the test. |
|
305 | - * @access public |
|
306 | - */ |
|
307 | - function getLabel() { |
|
308 | - return $this->_label; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Adds a test into the suite. Can be either a group |
|
313 | - * test or some other unit test. |
|
314 | - * @param SimpleTestCase $test_case Suite or individual test |
|
315 | - * case implementing the |
|
316 | - * runnable test interface. |
|
317 | - * @access public |
|
318 | - */ |
|
319 | - function addTestCase($test_case) { |
|
320 | - $this->_test_cases[] = $test_case; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Adds a test into the suite by class name. The class will |
|
325 | - * be instantiated as needed. |
|
326 | - * @param SimpleTestCase $test_case Suite or individual test |
|
327 | - * case implementing the |
|
328 | - * runnable test interface. |
|
329 | - * @access public |
|
330 | - */ |
|
331 | - function addTestClass($class) { |
|
332 | - $this->_test_cases[] = $class; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Builds a group test from a library of test cases. |
|
337 | - * The new group is composed into this one. |
|
338 | - * @param string $test_file File name of library with |
|
339 | - * test case classes. |
|
340 | - * @access public |
|
341 | - */ |
|
342 | - function addTestFile($test_file) { |
|
343 | - $existing_classes = get_declared_classes(); |
|
344 | - if ($error = $this->_requireWithError($test_file)) { |
|
345 | - $this->addTestCase(new BadGroupTest($test_file, $error)); |
|
346 | - return; |
|
347 | - } |
|
348 | - $classes = $this->_selectRunnableTests($existing_classes, get_declared_classes()); |
|
349 | - if (count($classes) == 0) { |
|
350 | - $this->addTestCase(new BadGroupTest($test_file, 'No new test cases')); |
|
351 | - return; |
|
352 | - } |
|
353 | - $this->addTestCase($this->_createGroupFromClasses($test_file, $classes)); |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * Requires a source file recording any syntax errors. |
|
358 | - * @param string $file File name to require in. |
|
359 | - * @return string/boolean An error message on failure or false |
|
360 | - * if no errors. |
|
361 | - * @access private |
|
362 | - */ |
|
363 | - function _requireWithError($file) { |
|
364 | - $this->_enableErrorReporting(); |
|
365 | - include($file); |
|
366 | - $error = isset($php_errormsg) ? $php_errormsg : false; |
|
367 | - $this->_disableErrorReporting(); |
|
368 | - $self_inflicted = array( |
|
369 | - 'Assigning the return value of new by reference is deprecated', |
|
370 | - 'var: Deprecated. Please use the public/private/protected modifiers'); |
|
371 | - if (in_array($error, $self_inflicted)) { |
|
372 | - return false; |
|
373 | - } |
|
374 | - return $error; |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Sets up detection of parse errors. Note that XDebug |
|
379 | - * interferes with this and has to be disabled. This is |
|
380 | - * to make sure the correct error code is returned |
|
381 | - * from unattended scripts. |
|
382 | - * @access private |
|
383 | - */ |
|
384 | - function _enableErrorReporting() { |
|
385 | - if ($this->_xdebug_is_enabled) { |
|
386 | - xdebug_disable(); |
|
387 | - } |
|
388 | - ini_set('track_errors', true); |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Resets detection of parse errors to their old values. |
|
393 | - * This is to make sure the correct error code is returned |
|
394 | - * from unattended scripts. |
|
395 | - * @access private |
|
396 | - */ |
|
397 | - function _disableErrorReporting() { |
|
398 | - ini_set('track_errors', $this->_old_track_errors); |
|
399 | - if ($this->_xdebug_is_enabled) { |
|
400 | - xdebug_enable(); |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Calculates the incoming test cases from a before |
|
406 | - * and after list of loaded classes. |
|
407 | - * @param array $existing_classes Classes before require(). |
|
408 | - * @param array $new_classes Classes after require(). |
|
409 | - * @return array New classes which are test |
|
410 | - * cases that shouldn't be ignored. |
|
411 | - * @access private |
|
412 | - */ |
|
413 | - function _selectRunnableTests($existing_classes, $new_classes) { |
|
414 | - $classes = array(); |
|
415 | - foreach ($new_classes as $class) { |
|
416 | - if (in_array($class, $existing_classes)) { |
|
417 | - continue; |
|
418 | - } |
|
419 | - if (! $this->_isTestCase($class)) { |
|
420 | - continue; |
|
421 | - } |
|
422 | - $classes[] = $class; |
|
423 | - } |
|
424 | - return $classes; |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Builds a group test from a class list. |
|
429 | - * @param string $title Title of new group. |
|
430 | - * @param array $classes Test classes. |
|
431 | - * @return GroupTest Group loaded with the new |
|
432 | - * test cases. |
|
433 | - * @access private |
|
434 | - */ |
|
435 | - function _createGroupFromClasses($title, $classes) { |
|
436 | - $group = new GroupTest($title); |
|
437 | - foreach ($classes as $class) { |
|
438 | - if (SimpleTestOptions::isIgnored($class)) { |
|
439 | - continue; |
|
440 | - } |
|
441 | - $group->addTestClass($class); |
|
442 | - } |
|
443 | - return $group; |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Test to see if a class is derived from the |
|
448 | - * TestCase class. |
|
449 | - * @param string $class Class name. |
|
450 | - * @access private |
|
451 | - */ |
|
452 | - function _isTestCase($class) { |
|
453 | - while ($class = get_parent_class($class)) { |
|
454 | - $class = strtolower($class); |
|
455 | - if ($class == "simpletestcase" || $class == "grouptest") { |
|
456 | - return true; |
|
457 | - } |
|
458 | - } |
|
459 | - return false; |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * Invokes run() on all of the held test cases, instantiating |
|
464 | - * them if necessary. |
|
465 | - * @param SimpleReporter $reporter Current test reporter. |
|
466 | - * @access public |
|
467 | - */ |
|
468 | - function run($reporter) { |
|
469 | - $reporter->paintGroupStart($this->getLabel(), $this->getSize()); |
|
470 | - for ($i = 0, $count = count($this->_test_cases); $i < $count; $i++) { |
|
471 | - if (is_string($this->_test_cases[$i])) { |
|
472 | - $class = $this->_test_cases[$i]; |
|
473 | - $test = new $class(); |
|
474 | - $test->run($reporter); |
|
475 | - } else { |
|
476 | - $this->_test_cases[$i]->run($reporter); |
|
477 | - } |
|
478 | - } |
|
479 | - $reporter->paintGroupEnd($this->getLabel()); |
|
480 | - return $reporter->getStatus(); |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Number of contained test cases. |
|
485 | - * @return integer Total count of cases in the group. |
|
486 | - * @access public |
|
487 | - */ |
|
488 | - function getSize() { |
|
489 | - $count = 0; |
|
490 | - foreach ($this->_test_cases as $case) { |
|
491 | - if (is_string($case)) { |
|
492 | - $count++; |
|
493 | - } else { |
|
494 | - $count += $case->getSize(); |
|
495 | - } |
|
496 | - } |
|
497 | - return $count; |
|
498 | - } |
|
499 | - } |
|
500 | - |
|
501 | - /** |
|
502 | - * This is a failing group test for when a test suite hasn't |
|
503 | - * loaded properly. |
|
281 | + */ |
|
282 | + class GroupTest { |
|
283 | + protected $_label; |
|
284 | + protected $_test_cases; |
|
285 | + protected $_old_track_errors; |
|
286 | + protected $_xdebug_is_enabled; |
|
287 | + |
|
288 | + /** |
|
289 | + * Sets the name of the test suite. |
|
290 | + * @param string $label Name sent at the start and end |
|
291 | + * of the test. |
|
292 | + * @access public |
|
293 | + */ |
|
294 | + function GroupTest($label) { |
|
295 | + $this->_label = $label; |
|
296 | + $this->_test_cases = array(); |
|
297 | + $this->_old_track_errors = ini_get('track_errors'); |
|
298 | + $this->_xdebug_is_enabled = function_exists('xdebug_is_enabled') ? |
|
299 | + xdebug_is_enabled() : false; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Accessor for the test name for subclasses. |
|
304 | + * @return string Name of the test. |
|
305 | + * @access public |
|
306 | + */ |
|
307 | + function getLabel() { |
|
308 | + return $this->_label; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Adds a test into the suite. Can be either a group |
|
313 | + * test or some other unit test. |
|
314 | + * @param SimpleTestCase $test_case Suite or individual test |
|
315 | + * case implementing the |
|
316 | + * runnable test interface. |
|
317 | + * @access public |
|
318 | + */ |
|
319 | + function addTestCase($test_case) { |
|
320 | + $this->_test_cases[] = $test_case; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Adds a test into the suite by class name. The class will |
|
325 | + * be instantiated as needed. |
|
326 | + * @param SimpleTestCase $test_case Suite or individual test |
|
327 | + * case implementing the |
|
328 | + * runnable test interface. |
|
329 | + * @access public |
|
330 | + */ |
|
331 | + function addTestClass($class) { |
|
332 | + $this->_test_cases[] = $class; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Builds a group test from a library of test cases. |
|
337 | + * The new group is composed into this one. |
|
338 | + * @param string $test_file File name of library with |
|
339 | + * test case classes. |
|
340 | + * @access public |
|
341 | + */ |
|
342 | + function addTestFile($test_file) { |
|
343 | + $existing_classes = get_declared_classes(); |
|
344 | + if ($error = $this->_requireWithError($test_file)) { |
|
345 | + $this->addTestCase(new BadGroupTest($test_file, $error)); |
|
346 | + return; |
|
347 | + } |
|
348 | + $classes = $this->_selectRunnableTests($existing_classes, get_declared_classes()); |
|
349 | + if (count($classes) == 0) { |
|
350 | + $this->addTestCase(new BadGroupTest($test_file, 'No new test cases')); |
|
351 | + return; |
|
352 | + } |
|
353 | + $this->addTestCase($this->_createGroupFromClasses($test_file, $classes)); |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Requires a source file recording any syntax errors. |
|
358 | + * @param string $file File name to require in. |
|
359 | + * @return string/boolean An error message on failure or false |
|
360 | + * if no errors. |
|
361 | + * @access private |
|
362 | + */ |
|
363 | + function _requireWithError($file) { |
|
364 | + $this->_enableErrorReporting(); |
|
365 | + include($file); |
|
366 | + $error = isset($php_errormsg) ? $php_errormsg : false; |
|
367 | + $this->_disableErrorReporting(); |
|
368 | + $self_inflicted = array( |
|
369 | + 'Assigning the return value of new by reference is deprecated', |
|
370 | + 'var: Deprecated. Please use the public/private/protected modifiers'); |
|
371 | + if (in_array($error, $self_inflicted)) { |
|
372 | + return false; |
|
373 | + } |
|
374 | + return $error; |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Sets up detection of parse errors. Note that XDebug |
|
379 | + * interferes with this and has to be disabled. This is |
|
380 | + * to make sure the correct error code is returned |
|
381 | + * from unattended scripts. |
|
382 | + * @access private |
|
383 | + */ |
|
384 | + function _enableErrorReporting() { |
|
385 | + if ($this->_xdebug_is_enabled) { |
|
386 | + xdebug_disable(); |
|
387 | + } |
|
388 | + ini_set('track_errors', true); |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Resets detection of parse errors to their old values. |
|
393 | + * This is to make sure the correct error code is returned |
|
394 | + * from unattended scripts. |
|
395 | + * @access private |
|
396 | + */ |
|
397 | + function _disableErrorReporting() { |
|
398 | + ini_set('track_errors', $this->_old_track_errors); |
|
399 | + if ($this->_xdebug_is_enabled) { |
|
400 | + xdebug_enable(); |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Calculates the incoming test cases from a before |
|
406 | + * and after list of loaded classes. |
|
407 | + * @param array $existing_classes Classes before require(). |
|
408 | + * @param array $new_classes Classes after require(). |
|
409 | + * @return array New classes which are test |
|
410 | + * cases that shouldn't be ignored. |
|
411 | + * @access private |
|
412 | + */ |
|
413 | + function _selectRunnableTests($existing_classes, $new_classes) { |
|
414 | + $classes = array(); |
|
415 | + foreach ($new_classes as $class) { |
|
416 | + if (in_array($class, $existing_classes)) { |
|
417 | + continue; |
|
418 | + } |
|
419 | + if (! $this->_isTestCase($class)) { |
|
420 | + continue; |
|
421 | + } |
|
422 | + $classes[] = $class; |
|
423 | + } |
|
424 | + return $classes; |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Builds a group test from a class list. |
|
429 | + * @param string $title Title of new group. |
|
430 | + * @param array $classes Test classes. |
|
431 | + * @return GroupTest Group loaded with the new |
|
432 | + * test cases. |
|
433 | + * @access private |
|
434 | + */ |
|
435 | + function _createGroupFromClasses($title, $classes) { |
|
436 | + $group = new GroupTest($title); |
|
437 | + foreach ($classes as $class) { |
|
438 | + if (SimpleTestOptions::isIgnored($class)) { |
|
439 | + continue; |
|
440 | + } |
|
441 | + $group->addTestClass($class); |
|
442 | + } |
|
443 | + return $group; |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Test to see if a class is derived from the |
|
448 | + * TestCase class. |
|
449 | + * @param string $class Class name. |
|
450 | + * @access private |
|
451 | + */ |
|
452 | + function _isTestCase($class) { |
|
453 | + while ($class = get_parent_class($class)) { |
|
454 | + $class = strtolower($class); |
|
455 | + if ($class == "simpletestcase" || $class == "grouptest") { |
|
456 | + return true; |
|
457 | + } |
|
458 | + } |
|
459 | + return false; |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * Invokes run() on all of the held test cases, instantiating |
|
464 | + * them if necessary. |
|
465 | + * @param SimpleReporter $reporter Current test reporter. |
|
466 | + * @access public |
|
467 | + */ |
|
468 | + function run($reporter) { |
|
469 | + $reporter->paintGroupStart($this->getLabel(), $this->getSize()); |
|
470 | + for ($i = 0, $count = count($this->_test_cases); $i < $count; $i++) { |
|
471 | + if (is_string($this->_test_cases[$i])) { |
|
472 | + $class = $this->_test_cases[$i]; |
|
473 | + $test = new $class(); |
|
474 | + $test->run($reporter); |
|
475 | + } else { |
|
476 | + $this->_test_cases[$i]->run($reporter); |
|
477 | + } |
|
478 | + } |
|
479 | + $reporter->paintGroupEnd($this->getLabel()); |
|
480 | + return $reporter->getStatus(); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Number of contained test cases. |
|
485 | + * @return integer Total count of cases in the group. |
|
486 | + * @access public |
|
487 | + */ |
|
488 | + function getSize() { |
|
489 | + $count = 0; |
|
490 | + foreach ($this->_test_cases as $case) { |
|
491 | + if (is_string($case)) { |
|
492 | + $count++; |
|
493 | + } else { |
|
494 | + $count += $case->getSize(); |
|
495 | + } |
|
496 | + } |
|
497 | + return $count; |
|
498 | + } |
|
499 | + } |
|
500 | + |
|
501 | + /** |
|
502 | + * This is a failing group test for when a test suite hasn't |
|
503 | + * loaded properly. |
|
504 | 504 | * @package SimpleTest |
505 | 505 | * @subpackage UnitTester |
506 | - */ |
|
507 | - class BadGroupTest { |
|
508 | - protected $_label; |
|
509 | - protected $_error; |
|
510 | - |
|
511 | - /** |
|
512 | - * Sets the name of the test suite and error message. |
|
513 | - * @param string $label Name sent at the start and end |
|
514 | - * of the test. |
|
515 | - * @access public |
|
516 | - */ |
|
517 | - function BadGroupTest($label, $error) { |
|
518 | - $this->_label = $label; |
|
519 | - $this->_error = $error; |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * Accessor for the test name for subclasses. |
|
524 | - * @return string Name of the test. |
|
525 | - * @access public |
|
526 | - */ |
|
527 | - function getLabel() { |
|
528 | - return $this->_label; |
|
529 | - } |
|
530 | - |
|
531 | - /** |
|
532 | - * Sends a single error to the reporter. |
|
533 | - * @param SimpleReporter $reporter Current test reporter. |
|
534 | - * @access public |
|
535 | - */ |
|
536 | - function run($reporter) { |
|
537 | - $reporter->paintGroupStart($this->getLabel(), $this->getSize()); |
|
538 | - $reporter->paintFail('Bad GroupTest [' . $this->getLabel() . |
|
539 | - '] with error [' . $this->_error . ']'); |
|
540 | - $reporter->paintGroupEnd($this->getLabel()); |
|
541 | - return $reporter->getStatus(); |
|
542 | - } |
|
543 | - |
|
544 | - /** |
|
545 | - * Number of contained test cases. Always zero. |
|
546 | - * @return integer Total count of cases in the group. |
|
547 | - * @access public |
|
548 | - */ |
|
549 | - function getSize() { |
|
550 | - return 0; |
|
551 | - } |
|
552 | - } |
|
506 | + */ |
|
507 | + class BadGroupTest { |
|
508 | + protected $_label; |
|
509 | + protected $_error; |
|
510 | + |
|
511 | + /** |
|
512 | + * Sets the name of the test suite and error message. |
|
513 | + * @param string $label Name sent at the start and end |
|
514 | + * of the test. |
|
515 | + * @access public |
|
516 | + */ |
|
517 | + function BadGroupTest($label, $error) { |
|
518 | + $this->_label = $label; |
|
519 | + $this->_error = $error; |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * Accessor for the test name for subclasses. |
|
524 | + * @return string Name of the test. |
|
525 | + * @access public |
|
526 | + */ |
|
527 | + function getLabel() { |
|
528 | + return $this->_label; |
|
529 | + } |
|
530 | + |
|
531 | + /** |
|
532 | + * Sends a single error to the reporter. |
|
533 | + * @param SimpleReporter $reporter Current test reporter. |
|
534 | + * @access public |
|
535 | + */ |
|
536 | + function run($reporter) { |
|
537 | + $reporter->paintGroupStart($this->getLabel(), $this->getSize()); |
|
538 | + $reporter->paintFail('Bad GroupTest [' . $this->getLabel() . |
|
539 | + '] with error [' . $this->_error . ']'); |
|
540 | + $reporter->paintGroupEnd($this->getLabel()); |
|
541 | + return $reporter->getStatus(); |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * Number of contained test cases. Always zero. |
|
546 | + * @return integer Total count of cases in the group. |
|
547 | + * @access public |
|
548 | + */ |
|
549 | + function getSize() { |
|
550 | + return 0; |
|
551 | + } |
|
552 | + } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | require_once(dirname(__FILE__) . '/scorer.php'); |
17 | 17 | require_once(dirname(__FILE__) . '/expectation.php'); |
18 | 18 | require_once(dirname(__FILE__) . '/dumper.php'); |
19 | - if (! defined('SIMPLE_TEST')) { |
|
19 | + if (!defined('SIMPLE_TEST')) { |
|
20 | 20 | define('SIMPLE_TEST', dirname(__FILE__) . '/'); |
21 | 21 | } |
22 | 22 | /**#@-*/ |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @access public |
188 | 188 | */ |
189 | 189 | function assertTrue($result, $message = false) { |
190 | - if (! $message) { |
|
190 | + if (!$message) { |
|
191 | 191 | $message = 'True assertion got ' . ($result ? 'True' : 'False'); |
192 | 192 | } |
193 | 193 | if ($result) { |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | * @access public |
211 | 211 | */ |
212 | 212 | function assertFalse($result, $message = false) { |
213 | - if (! $message) { |
|
213 | + if (!$message) { |
|
214 | 214 | $message = 'False assertion got ' . ($result ? 'True' : 'False'); |
215 | 215 | } |
216 | - return $this->assertTrue(! $result, $message); |
|
216 | + return $this->assertTrue(!$result, $message); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | if (in_array($class, $existing_classes)) { |
417 | 417 | continue; |
418 | 418 | } |
419 | - if (! $this->_isTestCase($class)) { |
|
419 | + if (!$this->_isTestCase($class)) { |
|
420 | 420 | continue; |
421 | 421 | } |
422 | 422 | $classes[] = $class; |