@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Creates a copy whether in PHP5 or PHP4. |
17 | - * @param object $object Thing to copy. |
|
17 | + * @param SimpleFormTag $object Thing to copy. |
|
18 | 18 | * @return object A copy. |
19 | 19 | * @access public |
20 | 20 | * @static |
@@ -1,183 +1,183 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @version $Id: compatibility.php 1532 2006-12-01 12:28:55Z xue $ |
|
6 | - */ |
|
2 | + /** |
|
3 | + * base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @version $Id: compatibility.php 1532 2006-12-01 12:28:55Z xue $ |
|
6 | + */ |
|
7 | 7 | |
8 | - /** |
|
9 | - * Static methods for compatibility between different |
|
10 | - * PHP versions. |
|
11 | - * @package SimpleTest |
|
12 | - */ |
|
13 | - class SimpleTestCompatibility { |
|
8 | + /** |
|
9 | + * Static methods for compatibility between different |
|
10 | + * PHP versions. |
|
11 | + * @package SimpleTest |
|
12 | + */ |
|
13 | + class SimpleTestCompatibility { |
|
14 | 14 | |
15 | - /** |
|
16 | - * Creates a copy whether in PHP5 or PHP4. |
|
17 | - * @param object $object Thing to copy. |
|
18 | - * @return object A copy. |
|
19 | - * @access public |
|
20 | - * @static |
|
21 | - */ |
|
22 | - static function copy($object) { |
|
23 | - if (version_compare(phpversion(), '5') >= 0) { |
|
24 | - eval('$copy = clone $object;'); |
|
25 | - return $copy; |
|
26 | - } |
|
27 | - return $object; |
|
28 | - } |
|
15 | + /** |
|
16 | + * Creates a copy whether in PHP5 or PHP4. |
|
17 | + * @param object $object Thing to copy. |
|
18 | + * @return object A copy. |
|
19 | + * @access public |
|
20 | + * @static |
|
21 | + */ |
|
22 | + static function copy($object) { |
|
23 | + if (version_compare(phpversion(), '5') >= 0) { |
|
24 | + eval('$copy = clone $object;'); |
|
25 | + return $copy; |
|
26 | + } |
|
27 | + return $object; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Identity test. Drops back to equality + types for PHP5 |
|
32 | - * objects as the === operator counts as the |
|
33 | - * stronger reference constraint. |
|
34 | - * @param mixed $first Test subject. |
|
35 | - * @param mixed $second Comparison object. |
|
36 | - * @return boolean True if identical. |
|
37 | - * @access public |
|
38 | - * @static |
|
39 | - */ |
|
40 | - static function isIdentical($first, $second) { |
|
41 | - if ($first != $second) { |
|
42 | - return false; |
|
43 | - } |
|
44 | - if (version_compare(phpversion(), '5') >= 0) { |
|
45 | - return SimpleTestCompatibility::_isIdenticalType($first, $second); |
|
46 | - } |
|
47 | - return ($first === $second); |
|
48 | - } |
|
30 | + /** |
|
31 | + * Identity test. Drops back to equality + types for PHP5 |
|
32 | + * objects as the === operator counts as the |
|
33 | + * stronger reference constraint. |
|
34 | + * @param mixed $first Test subject. |
|
35 | + * @param mixed $second Comparison object. |
|
36 | + * @return boolean True if identical. |
|
37 | + * @access public |
|
38 | + * @static |
|
39 | + */ |
|
40 | + static function isIdentical($first, $second) { |
|
41 | + if ($first != $second) { |
|
42 | + return false; |
|
43 | + } |
|
44 | + if (version_compare(phpversion(), '5') >= 0) { |
|
45 | + return SimpleTestCompatibility::_isIdenticalType($first, $second); |
|
46 | + } |
|
47 | + return ($first === $second); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Recursive type test. |
|
52 | - * @param mixed $first Test subject. |
|
53 | - * @param mixed $second Comparison object. |
|
54 | - * @return boolean True if same type. |
|
55 | - * @access private |
|
56 | - * @static |
|
57 | - */ |
|
58 | - static function _isIdenticalType($first, $second) { |
|
59 | - if (gettype($first) != gettype($second)) { |
|
60 | - return false; |
|
61 | - } |
|
62 | - if (is_object($first) && is_object($second)) { |
|
63 | - if (get_class($first) != get_class($second)) { |
|
64 | - return false; |
|
65 | - } |
|
66 | - return SimpleTestCompatibility::_isArrayOfIdenticalTypes( |
|
67 | - get_object_vars($first), |
|
68 | - get_object_vars($second)); |
|
69 | - } |
|
70 | - if (is_array($first) && is_array($second)) { |
|
71 | - return SimpleTestCompatibility::_isArrayOfIdenticalTypes($first, $second); |
|
72 | - } |
|
73 | - return true; |
|
74 | - } |
|
50 | + /** |
|
51 | + * Recursive type test. |
|
52 | + * @param mixed $first Test subject. |
|
53 | + * @param mixed $second Comparison object. |
|
54 | + * @return boolean True if same type. |
|
55 | + * @access private |
|
56 | + * @static |
|
57 | + */ |
|
58 | + static function _isIdenticalType($first, $second) { |
|
59 | + if (gettype($first) != gettype($second)) { |
|
60 | + return false; |
|
61 | + } |
|
62 | + if (is_object($first) && is_object($second)) { |
|
63 | + if (get_class($first) != get_class($second)) { |
|
64 | + return false; |
|
65 | + } |
|
66 | + return SimpleTestCompatibility::_isArrayOfIdenticalTypes( |
|
67 | + get_object_vars($first), |
|
68 | + get_object_vars($second)); |
|
69 | + } |
|
70 | + if (is_array($first) && is_array($second)) { |
|
71 | + return SimpleTestCompatibility::_isArrayOfIdenticalTypes($first, $second); |
|
72 | + } |
|
73 | + return true; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Recursive type test for each element of an array. |
|
78 | - * @param mixed $first Test subject. |
|
79 | - * @param mixed $second Comparison object. |
|
80 | - * @return boolean True if identical. |
|
81 | - * @access private |
|
82 | - * @static |
|
83 | - */ |
|
84 | - static function _isArrayOfIdenticalTypes($first, $second) { |
|
85 | - if (array_keys($first) != array_keys($second)) { |
|
86 | - return false; |
|
87 | - } |
|
88 | - foreach (array_keys($first) as $key) { |
|
89 | - $is_identical = SimpleTestCompatibility::_isIdenticalType( |
|
90 | - $first[$key], |
|
91 | - $second[$key]); |
|
92 | - if (! $is_identical) { |
|
93 | - return false; |
|
94 | - } |
|
95 | - } |
|
96 | - return true; |
|
97 | - } |
|
76 | + /** |
|
77 | + * Recursive type test for each element of an array. |
|
78 | + * @param mixed $first Test subject. |
|
79 | + * @param mixed $second Comparison object. |
|
80 | + * @return boolean True if identical. |
|
81 | + * @access private |
|
82 | + * @static |
|
83 | + */ |
|
84 | + static function _isArrayOfIdenticalTypes($first, $second) { |
|
85 | + if (array_keys($first) != array_keys($second)) { |
|
86 | + return false; |
|
87 | + } |
|
88 | + foreach (array_keys($first) as $key) { |
|
89 | + $is_identical = SimpleTestCompatibility::_isIdenticalType( |
|
90 | + $first[$key], |
|
91 | + $second[$key]); |
|
92 | + if (! $is_identical) { |
|
93 | + return false; |
|
94 | + } |
|
95 | + } |
|
96 | + return true; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Test for two variables being aliases. |
|
101 | - * @param mixed $first Test subject. |
|
102 | - * @param mixed $second Comparison object. |
|
103 | - * @return boolean True if same. |
|
104 | - * @access public |
|
105 | - * @static |
|
106 | - */ |
|
107 | - static function isReference($first, $second) { |
|
108 | - if (version_compare(phpversion(), '5', '>=') |
|
109 | - && is_object($first)) { |
|
110 | - return ($first === $second); |
|
111 | - } |
|
112 | - if (is_object($first) && is_object($second)) { |
|
113 | - $id = uniqid("test"); |
|
114 | - $first->$id = true; |
|
115 | - $is_ref = isset($second->$id); |
|
116 | - unset($first->$id); |
|
117 | - return $is_ref; |
|
118 | - } |
|
119 | - $temp = $first; |
|
120 | - $first = uniqid("test"); |
|
121 | - $is_ref = ($first === $second); |
|
122 | - $first = $temp; |
|
123 | - return $is_ref; |
|
124 | - } |
|
99 | + /** |
|
100 | + * Test for two variables being aliases. |
|
101 | + * @param mixed $first Test subject. |
|
102 | + * @param mixed $second Comparison object. |
|
103 | + * @return boolean True if same. |
|
104 | + * @access public |
|
105 | + * @static |
|
106 | + */ |
|
107 | + static function isReference($first, $second) { |
|
108 | + if (version_compare(phpversion(), '5', '>=') |
|
109 | + && is_object($first)) { |
|
110 | + return ($first === $second); |
|
111 | + } |
|
112 | + if (is_object($first) && is_object($second)) { |
|
113 | + $id = uniqid("test"); |
|
114 | + $first->$id = true; |
|
115 | + $is_ref = isset($second->$id); |
|
116 | + unset($first->$id); |
|
117 | + return $is_ref; |
|
118 | + } |
|
119 | + $temp = $first; |
|
120 | + $first = uniqid("test"); |
|
121 | + $is_ref = ($first === $second); |
|
122 | + $first = $temp; |
|
123 | + return $is_ref; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Test to see if an object is a member of a |
|
128 | - * class hiearchy. |
|
129 | - * @param object $object Object to test. |
|
130 | - * @param string $class Root name of hiearchy. |
|
131 | - * @return boolean True if class in hiearchy. |
|
132 | - * @access public |
|
133 | - * @static |
|
134 | - */ |
|
135 | - static function isA($object, $class) { |
|
136 | - if (version_compare(phpversion(), '5') >= 0) { |
|
137 | - if (! class_exists($class, false)) { |
|
138 | - if (function_exists('interface_exists')) { |
|
139 | - if (! interface_exists($class, false)) { |
|
140 | - return false; |
|
141 | - } |
|
142 | - } |
|
143 | - } |
|
144 | - eval("\$is_a = \$object instanceof $class;"); |
|
145 | - return $is_a; |
|
146 | - } |
|
147 | - if (function_exists('is_a')) { |
|
148 | - return is_a($object, $class); |
|
149 | - } |
|
150 | - return ((strtolower($class) == get_class($object)) |
|
151 | - or (is_subclass_of($object, $class))); |
|
152 | - } |
|
126 | + /** |
|
127 | + * Test to see if an object is a member of a |
|
128 | + * class hiearchy. |
|
129 | + * @param object $object Object to test. |
|
130 | + * @param string $class Root name of hiearchy. |
|
131 | + * @return boolean True if class in hiearchy. |
|
132 | + * @access public |
|
133 | + * @static |
|
134 | + */ |
|
135 | + static function isA($object, $class) { |
|
136 | + if (version_compare(phpversion(), '5') >= 0) { |
|
137 | + if (! class_exists($class, false)) { |
|
138 | + if (function_exists('interface_exists')) { |
|
139 | + if (! interface_exists($class, false)) { |
|
140 | + return false; |
|
141 | + } |
|
142 | + } |
|
143 | + } |
|
144 | + eval("\$is_a = \$object instanceof $class;"); |
|
145 | + return $is_a; |
|
146 | + } |
|
147 | + if (function_exists('is_a')) { |
|
148 | + return is_a($object, $class); |
|
149 | + } |
|
150 | + return ((strtolower($class) == get_class($object)) |
|
151 | + or (is_subclass_of($object, $class))); |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * Sets a socket timeout for each chunk. |
|
156 | - * @param resource $handle Socket handle. |
|
157 | - * @param integer $timeout Limit in seconds. |
|
158 | - * @access public |
|
159 | - * @static |
|
160 | - */ |
|
161 | - static function setTimeout($handle, $timeout) { |
|
162 | - if (function_exists('stream_set_timeout')) { |
|
163 | - stream_set_timeout($handle, $timeout, 0); |
|
164 | - } elseif (function_exists('socket_set_timeout')) { |
|
165 | - socket_set_timeout($handle, $timeout, 0); |
|
166 | - } elseif (function_exists('set_socket_timeout')) { |
|
167 | - set_socket_timeout($handle, $timeout, 0); |
|
168 | - } |
|
169 | - } |
|
154 | + /** |
|
155 | + * Sets a socket timeout for each chunk. |
|
156 | + * @param resource $handle Socket handle. |
|
157 | + * @param integer $timeout Limit in seconds. |
|
158 | + * @access public |
|
159 | + * @static |
|
160 | + */ |
|
161 | + static function setTimeout($handle, $timeout) { |
|
162 | + if (function_exists('stream_set_timeout')) { |
|
163 | + stream_set_timeout($handle, $timeout, 0); |
|
164 | + } elseif (function_exists('socket_set_timeout')) { |
|
165 | + socket_set_timeout($handle, $timeout, 0); |
|
166 | + } elseif (function_exists('set_socket_timeout')) { |
|
167 | + set_socket_timeout($handle, $timeout, 0); |
|
168 | + } |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Gets the current stack trace topmost first. |
|
173 | - * @return array List of stack frames. |
|
174 | - * @access public |
|
175 | - * @static |
|
176 | - */ |
|
177 | - static function getStackTrace() { |
|
178 | - if (function_exists('debug_backtrace')) { |
|
179 | - return array_reverse(debug_backtrace()); |
|
180 | - } |
|
181 | - return array(); |
|
182 | - } |
|
183 | - } |
|
171 | + /** |
|
172 | + * Gets the current stack trace topmost first. |
|
173 | + * @return array List of stack frames. |
|
174 | + * @access public |
|
175 | + * @static |
|
176 | + */ |
|
177 | + static function getStackTrace() { |
|
178 | + if (function_exists('debug_backtrace')) { |
|
179 | + return array_reverse(debug_backtrace()); |
|
180 | + } |
|
181 | + return array(); |
|
182 | + } |
|
183 | + } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $is_identical = SimpleTestCompatibility::_isIdenticalType( |
90 | 90 | $first[$key], |
91 | 91 | $second[$key]); |
92 | - if (! $is_identical) { |
|
92 | + if (!$is_identical) { |
|
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | } |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | */ |
135 | 135 | static function isA($object, $class) { |
136 | 136 | if (version_compare(phpversion(), '5') >= 0) { |
137 | - if (! class_exists($class, false)) { |
|
137 | + if (!class_exists($class, false)) { |
|
138 | 138 | if (function_exists('interface_exists')) { |
139 | - if (! interface_exists($class, false)) { |
|
139 | + if (!interface_exists($class, false)) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | 142 | } |
@@ -239,8 +239,6 @@ |
||
239 | 239 | /** |
240 | 240 | * Removes expired and temporary cookies as if |
241 | 241 | * the browser was closed and re-opened. |
242 | - * @param string/integer $now Time to test expiry against. |
|
243 | - * @access public |
|
244 | 242 | */ |
245 | 243 | function restartSession($date = false) { |
246 | 244 | $surviving_cookies = array(); |
@@ -1,379 +1,379 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * Base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage WebTester |
|
6 | - * @version $Id: cookies.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | - */ |
|
2 | + /** |
|
3 | + * Base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage WebTester |
|
6 | + * @version $Id: cookies.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__) . '/url.php'); |
|
13 | - /**#@-*/ |
|
12 | + require_once(dirname(__FILE__) . '/url.php'); |
|
13 | + /**#@-*/ |
|
14 | 14 | |
15 | - /** |
|
16 | - * Cookie data holder. Cookie rules are full of pretty |
|
17 | - * arbitary stuff. I have used... |
|
18 | - * http://wp.netscape.com/newsref/std/cookie_spec.html |
|
19 | - * http://www.cookiecentral.com/faq/ |
|
15 | + /** |
|
16 | + * Cookie data holder. Cookie rules are full of pretty |
|
17 | + * arbitary stuff. I have used... |
|
18 | + * http://wp.netscape.com/newsref/std/cookie_spec.html |
|
19 | + * http://www.cookiecentral.com/faq/ |
|
20 | 20 | * @package SimpleTest |
21 | 21 | * @subpackage WebTester |
22 | - */ |
|
23 | - class SimpleCookie { |
|
24 | - protected $_host; |
|
25 | - protected $_name; |
|
26 | - protected $_value; |
|
27 | - protected $_path; |
|
28 | - protected $_expiry; |
|
29 | - protected $_is_secure; |
|
22 | + */ |
|
23 | + class SimpleCookie { |
|
24 | + protected $_host; |
|
25 | + protected $_name; |
|
26 | + protected $_value; |
|
27 | + protected $_path; |
|
28 | + protected $_expiry; |
|
29 | + protected $_is_secure; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor. Sets the stored values. |
|
33 | - * @param string $name Cookie key. |
|
34 | - * @param string $value Value of cookie. |
|
35 | - * @param string $path Cookie path if not host wide. |
|
36 | - * @param string $expiry Expiry date as string. |
|
37 | - * @param boolean $is_secure Currently ignored. |
|
38 | - */ |
|
39 | - function SimpleCookie($name, $value = false, $path = false, $expiry = false, $is_secure = false) { |
|
40 | - $this->_host = false; |
|
41 | - $this->_name = $name; |
|
42 | - $this->_value = $value; |
|
43 | - $this->_path = ($path ? $this->_fixPath($path) : "/"); |
|
44 | - $this->_expiry = false; |
|
45 | - if (is_string($expiry)) { |
|
46 | - $this->_expiry = strtotime($expiry); |
|
47 | - } elseif (is_integer($expiry)) { |
|
48 | - $this->_expiry = $expiry; |
|
49 | - } |
|
50 | - $this->_is_secure = $is_secure; |
|
51 | - } |
|
31 | + /** |
|
32 | + * Constructor. Sets the stored values. |
|
33 | + * @param string $name Cookie key. |
|
34 | + * @param string $value Value of cookie. |
|
35 | + * @param string $path Cookie path if not host wide. |
|
36 | + * @param string $expiry Expiry date as string. |
|
37 | + * @param boolean $is_secure Currently ignored. |
|
38 | + */ |
|
39 | + function SimpleCookie($name, $value = false, $path = false, $expiry = false, $is_secure = false) { |
|
40 | + $this->_host = false; |
|
41 | + $this->_name = $name; |
|
42 | + $this->_value = $value; |
|
43 | + $this->_path = ($path ? $this->_fixPath($path) : "/"); |
|
44 | + $this->_expiry = false; |
|
45 | + if (is_string($expiry)) { |
|
46 | + $this->_expiry = strtotime($expiry); |
|
47 | + } elseif (is_integer($expiry)) { |
|
48 | + $this->_expiry = $expiry; |
|
49 | + } |
|
50 | + $this->_is_secure = $is_secure; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Sets the host. The cookie rules determine |
|
55 | - * that the first two parts are taken for |
|
56 | - * certain TLDs and three for others. If the |
|
57 | - * new host does not match these rules then the |
|
58 | - * call will fail. |
|
59 | - * @param string $host New hostname. |
|
60 | - * @return boolean True if hostname is valid. |
|
61 | - * @access public |
|
62 | - */ |
|
63 | - function setHost($host) { |
|
64 | - if ($host = $this->_truncateHost($host)) { |
|
65 | - $this->_host = $host; |
|
66 | - return true; |
|
67 | - } |
|
68 | - return false; |
|
69 | - } |
|
53 | + /** |
|
54 | + * Sets the host. The cookie rules determine |
|
55 | + * that the first two parts are taken for |
|
56 | + * certain TLDs and three for others. If the |
|
57 | + * new host does not match these rules then the |
|
58 | + * call will fail. |
|
59 | + * @param string $host New hostname. |
|
60 | + * @return boolean True if hostname is valid. |
|
61 | + * @access public |
|
62 | + */ |
|
63 | + function setHost($host) { |
|
64 | + if ($host = $this->_truncateHost($host)) { |
|
65 | + $this->_host = $host; |
|
66 | + return true; |
|
67 | + } |
|
68 | + return false; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Accessor for the truncated host to which this |
|
73 | - * cookie applies. |
|
74 | - * @return string Truncated hostname. |
|
75 | - * @access public |
|
76 | - */ |
|
77 | - function getHost() { |
|
78 | - return $this->_host; |
|
79 | - } |
|
71 | + /** |
|
72 | + * Accessor for the truncated host to which this |
|
73 | + * cookie applies. |
|
74 | + * @return string Truncated hostname. |
|
75 | + * @access public |
|
76 | + */ |
|
77 | + function getHost() { |
|
78 | + return $this->_host; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Test for a cookie being valid for a host name. |
|
83 | - * @param string $host Host to test against. |
|
84 | - * @return boolean True if the cookie would be valid |
|
85 | - * here. |
|
86 | - */ |
|
87 | - function isValidHost($host) { |
|
88 | - return ($this->_truncateHost($host) === $this->getHost()); |
|
89 | - } |
|
81 | + /** |
|
82 | + * Test for a cookie being valid for a host name. |
|
83 | + * @param string $host Host to test against. |
|
84 | + * @return boolean True if the cookie would be valid |
|
85 | + * here. |
|
86 | + */ |
|
87 | + function isValidHost($host) { |
|
88 | + return ($this->_truncateHost($host) === $this->getHost()); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Extracts just the domain part that determines a |
|
93 | - * cookie's host validity. |
|
94 | - * @param string $host Host name to truncate. |
|
95 | - * @return string Domain or false on a bad host. |
|
96 | - * @access private |
|
97 | - */ |
|
98 | - function _truncateHost($host) { |
|
99 | - $tlds = SimpleUrl::getAllTopLevelDomains(); |
|
100 | - if (preg_match('/[a-z\-]+\.(' . $tlds . ')$/i', $host, $matches)) { |
|
101 | - return $matches[0]; |
|
102 | - } elseif (preg_match('/[a-z\-]+\.[a-z\-]+\.[a-z\-]+$/i', $host, $matches)) { |
|
103 | - return $matches[0]; |
|
104 | - } |
|
105 | - return false; |
|
106 | - } |
|
91 | + /** |
|
92 | + * Extracts just the domain part that determines a |
|
93 | + * cookie's host validity. |
|
94 | + * @param string $host Host name to truncate. |
|
95 | + * @return string Domain or false on a bad host. |
|
96 | + * @access private |
|
97 | + */ |
|
98 | + function _truncateHost($host) { |
|
99 | + $tlds = SimpleUrl::getAllTopLevelDomains(); |
|
100 | + if (preg_match('/[a-z\-]+\.(' . $tlds . ')$/i', $host, $matches)) { |
|
101 | + return $matches[0]; |
|
102 | + } elseif (preg_match('/[a-z\-]+\.[a-z\-]+\.[a-z\-]+$/i', $host, $matches)) { |
|
103 | + return $matches[0]; |
|
104 | + } |
|
105 | + return false; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Accessor for name. |
|
110 | - * @return string Cookie key. |
|
111 | - * @access public |
|
112 | - */ |
|
113 | - function getName() { |
|
114 | - return $this->_name; |
|
115 | - } |
|
108 | + /** |
|
109 | + * Accessor for name. |
|
110 | + * @return string Cookie key. |
|
111 | + * @access public |
|
112 | + */ |
|
113 | + function getName() { |
|
114 | + return $this->_name; |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Accessor for value. A deleted cookie will |
|
119 | - * have an empty string for this. |
|
120 | - * @return string Cookie value. |
|
121 | - * @access public |
|
122 | - */ |
|
123 | - function getValue() { |
|
124 | - return $this->_value; |
|
125 | - } |
|
117 | + /** |
|
118 | + * Accessor for value. A deleted cookie will |
|
119 | + * have an empty string for this. |
|
120 | + * @return string Cookie value. |
|
121 | + * @access public |
|
122 | + */ |
|
123 | + function getValue() { |
|
124 | + return $this->_value; |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Accessor for path. |
|
129 | - * @return string Valid cookie path. |
|
130 | - * @access public |
|
131 | - */ |
|
132 | - function getPath() { |
|
133 | - return $this->_path; |
|
134 | - } |
|
127 | + /** |
|
128 | + * Accessor for path. |
|
129 | + * @return string Valid cookie path. |
|
130 | + * @access public |
|
131 | + */ |
|
132 | + function getPath() { |
|
133 | + return $this->_path; |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Tests a path to see if the cookie applies |
|
138 | - * there. The test path must be longer or |
|
139 | - * equal to the cookie path. |
|
140 | - * @param string $path Path to test against. |
|
141 | - * @return boolean True if cookie valid here. |
|
142 | - * @access public |
|
143 | - */ |
|
144 | - function isValidPath($path) { |
|
145 | - return (strncmp( |
|
146 | - $this->_fixPath($path), |
|
147 | - $this->getPath(), |
|
148 | - strlen($this->getPath())) == 0); |
|
149 | - } |
|
136 | + /** |
|
137 | + * Tests a path to see if the cookie applies |
|
138 | + * there. The test path must be longer or |
|
139 | + * equal to the cookie path. |
|
140 | + * @param string $path Path to test against. |
|
141 | + * @return boolean True if cookie valid here. |
|
142 | + * @access public |
|
143 | + */ |
|
144 | + function isValidPath($path) { |
|
145 | + return (strncmp( |
|
146 | + $this->_fixPath($path), |
|
147 | + $this->getPath(), |
|
148 | + strlen($this->getPath())) == 0); |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Accessor for expiry. |
|
153 | - * @return string Expiry string. |
|
154 | - * @access public |
|
155 | - */ |
|
156 | - function getExpiry() { |
|
157 | - if (! $this->_expiry) { |
|
158 | - return false; |
|
159 | - } |
|
160 | - return gmdate("D, d M Y H:i:s", $this->_expiry) . " GMT"; |
|
161 | - } |
|
151 | + /** |
|
152 | + * Accessor for expiry. |
|
153 | + * @return string Expiry string. |
|
154 | + * @access public |
|
155 | + */ |
|
156 | + function getExpiry() { |
|
157 | + if (! $this->_expiry) { |
|
158 | + return false; |
|
159 | + } |
|
160 | + return gmdate("D, d M Y H:i:s", $this->_expiry) . " GMT"; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Test to see if cookie is expired against |
|
165 | - * the cookie format time or timestamp. |
|
166 | - * Will give true for a session cookie. |
|
167 | - * @param integer/string $now Time to test against. Result |
|
168 | - * will be false if this time |
|
169 | - * is later than the cookie expiry. |
|
170 | - * Can be either a timestamp integer |
|
171 | - * or a cookie format date. |
|
172 | - * @access public |
|
173 | - */ |
|
174 | - function isExpired($now) { |
|
175 | - if (! $this->_expiry) { |
|
176 | - return true; |
|
177 | - } |
|
178 | - if (is_string($now)) { |
|
179 | - $now = strtotime($now); |
|
180 | - } |
|
181 | - return ($this->_expiry < $now); |
|
182 | - } |
|
163 | + /** |
|
164 | + * Test to see if cookie is expired against |
|
165 | + * the cookie format time or timestamp. |
|
166 | + * Will give true for a session cookie. |
|
167 | + * @param integer/string $now Time to test against. Result |
|
168 | + * will be false if this time |
|
169 | + * is later than the cookie expiry. |
|
170 | + * Can be either a timestamp integer |
|
171 | + * or a cookie format date. |
|
172 | + * @access public |
|
173 | + */ |
|
174 | + function isExpired($now) { |
|
175 | + if (! $this->_expiry) { |
|
176 | + return true; |
|
177 | + } |
|
178 | + if (is_string($now)) { |
|
179 | + $now = strtotime($now); |
|
180 | + } |
|
181 | + return ($this->_expiry < $now); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Ages the cookie by the specified number of |
|
186 | - * seconds. |
|
187 | - * @param integer $interval In seconds. |
|
188 | - * @public |
|
189 | - */ |
|
190 | - function agePrematurely($interval) { |
|
191 | - if ($this->_expiry) { |
|
192 | - $this->_expiry -= $interval; |
|
193 | - } |
|
194 | - } |
|
184 | + /** |
|
185 | + * Ages the cookie by the specified number of |
|
186 | + * seconds. |
|
187 | + * @param integer $interval In seconds. |
|
188 | + * @public |
|
189 | + */ |
|
190 | + function agePrematurely($interval) { |
|
191 | + if ($this->_expiry) { |
|
192 | + $this->_expiry -= $interval; |
|
193 | + } |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Accessor for the secure flag. |
|
198 | - * @return boolean True if cookie needs SSL. |
|
199 | - * @access public |
|
200 | - */ |
|
201 | - function isSecure() { |
|
202 | - return $this->_is_secure; |
|
203 | - } |
|
196 | + /** |
|
197 | + * Accessor for the secure flag. |
|
198 | + * @return boolean True if cookie needs SSL. |
|
199 | + * @access public |
|
200 | + */ |
|
201 | + function isSecure() { |
|
202 | + return $this->_is_secure; |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * Adds a trailing and leading slash to the path |
|
207 | - * if missing. |
|
208 | - * @param string $path Path to fix. |
|
209 | - * @access private |
|
210 | - */ |
|
211 | - function _fixPath($path) { |
|
212 | - if (substr($path, 0, 1) != '/') { |
|
213 | - $path = '/' . $path; |
|
214 | - } |
|
215 | - if (substr($path, -1, 1) != '/') { |
|
216 | - $path .= '/'; |
|
217 | - } |
|
218 | - return $path; |
|
219 | - } |
|
220 | - } |
|
205 | + /** |
|
206 | + * Adds a trailing and leading slash to the path |
|
207 | + * if missing. |
|
208 | + * @param string $path Path to fix. |
|
209 | + * @access private |
|
210 | + */ |
|
211 | + function _fixPath($path) { |
|
212 | + if (substr($path, 0, 1) != '/') { |
|
213 | + $path = '/' . $path; |
|
214 | + } |
|
215 | + if (substr($path, -1, 1) != '/') { |
|
216 | + $path .= '/'; |
|
217 | + } |
|
218 | + return $path; |
|
219 | + } |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
223 | - * Repository for cookies. This stuff is a |
|
224 | - * tiny bit browser dependent. |
|
222 | + /** |
|
223 | + * Repository for cookies. This stuff is a |
|
224 | + * tiny bit browser dependent. |
|
225 | 225 | * @package SimpleTest |
226 | 226 | * @subpackage WebTester |
227 | - */ |
|
228 | - class SimpleCookieJar { |
|
229 | - protected $_cookies; |
|
227 | + */ |
|
228 | + class SimpleCookieJar { |
|
229 | + protected $_cookies; |
|
230 | 230 | |
231 | - /** |
|
232 | - * Constructor. Jar starts empty. |
|
233 | - * @access public |
|
234 | - */ |
|
235 | - function SimpleCookieJar() { |
|
236 | - $this->_cookies = array(); |
|
237 | - } |
|
231 | + /** |
|
232 | + * Constructor. Jar starts empty. |
|
233 | + * @access public |
|
234 | + */ |
|
235 | + function SimpleCookieJar() { |
|
236 | + $this->_cookies = array(); |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * Removes expired and temporary cookies as if |
|
241 | - * the browser was closed and re-opened. |
|
242 | - * @param string/integer $now Time to test expiry against. |
|
243 | - * @access public |
|
244 | - */ |
|
245 | - function restartSession($date = false) { |
|
246 | - $surviving_cookies = array(); |
|
247 | - for ($i = 0; $i < count($this->_cookies); $i++) { |
|
248 | - if (! $this->_cookies[$i]->getValue()) { |
|
249 | - continue; |
|
250 | - } |
|
251 | - if (! $this->_cookies[$i]->getExpiry()) { |
|
252 | - continue; |
|
253 | - } |
|
254 | - if ($date && $this->_cookies[$i]->isExpired($date)) { |
|
255 | - continue; |
|
256 | - } |
|
257 | - $surviving_cookies[] = $this->_cookies[$i]; |
|
258 | - } |
|
259 | - $this->_cookies = $surviving_cookies; |
|
260 | - } |
|
239 | + /** |
|
240 | + * Removes expired and temporary cookies as if |
|
241 | + * the browser was closed and re-opened. |
|
242 | + * @param string/integer $now Time to test expiry against. |
|
243 | + * @access public |
|
244 | + */ |
|
245 | + function restartSession($date = false) { |
|
246 | + $surviving_cookies = array(); |
|
247 | + for ($i = 0; $i < count($this->_cookies); $i++) { |
|
248 | + if (! $this->_cookies[$i]->getValue()) { |
|
249 | + continue; |
|
250 | + } |
|
251 | + if (! $this->_cookies[$i]->getExpiry()) { |
|
252 | + continue; |
|
253 | + } |
|
254 | + if ($date && $this->_cookies[$i]->isExpired($date)) { |
|
255 | + continue; |
|
256 | + } |
|
257 | + $surviving_cookies[] = $this->_cookies[$i]; |
|
258 | + } |
|
259 | + $this->_cookies = $surviving_cookies; |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * Ages all cookies in the cookie jar. |
|
264 | - * @param integer $interval The old session is moved |
|
265 | - * into the past by this number |
|
266 | - * of seconds. Cookies now over |
|
267 | - * age will be removed. |
|
268 | - * @access public |
|
269 | - */ |
|
270 | - function agePrematurely($interval) { |
|
271 | - for ($i = 0; $i < count($this->_cookies); $i++) { |
|
272 | - $this->_cookies[$i]->agePrematurely($interval); |
|
273 | - } |
|
274 | - } |
|
262 | + /** |
|
263 | + * Ages all cookies in the cookie jar. |
|
264 | + * @param integer $interval The old session is moved |
|
265 | + * into the past by this number |
|
266 | + * of seconds. Cookies now over |
|
267 | + * age will be removed. |
|
268 | + * @access public |
|
269 | + */ |
|
270 | + function agePrematurely($interval) { |
|
271 | + for ($i = 0; $i < count($this->_cookies); $i++) { |
|
272 | + $this->_cookies[$i]->agePrematurely($interval); |
|
273 | + } |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * Sets an additional cookie. If a cookie has |
|
278 | - * the same name and path it is replaced. |
|
279 | - * @param string $name Cookie key. |
|
280 | - * @param string $value Value of cookie. |
|
281 | - * @param string $host Host upon which the cookie is valid. |
|
282 | - * @param string $path Cookie path if not host wide. |
|
283 | - * @param string $expiry Expiry date. |
|
284 | - * @access public |
|
285 | - */ |
|
286 | - function setCookie($name, $value, $host = false, $path = '/', $expiry = false) { |
|
287 | - $cookie = new SimpleCookie($name, $value, $path, $expiry); |
|
288 | - if ($host) { |
|
289 | - $cookie->setHost($host); |
|
290 | - } |
|
291 | - $this->_cookies[$this->_findFirstMatch($cookie)] = $cookie; |
|
292 | - } |
|
276 | + /** |
|
277 | + * Sets an additional cookie. If a cookie has |
|
278 | + * the same name and path it is replaced. |
|
279 | + * @param string $name Cookie key. |
|
280 | + * @param string $value Value of cookie. |
|
281 | + * @param string $host Host upon which the cookie is valid. |
|
282 | + * @param string $path Cookie path if not host wide. |
|
283 | + * @param string $expiry Expiry date. |
|
284 | + * @access public |
|
285 | + */ |
|
286 | + function setCookie($name, $value, $host = false, $path = '/', $expiry = false) { |
|
287 | + $cookie = new SimpleCookie($name, $value, $path, $expiry); |
|
288 | + if ($host) { |
|
289 | + $cookie->setHost($host); |
|
290 | + } |
|
291 | + $this->_cookies[$this->_findFirstMatch($cookie)] = $cookie; |
|
292 | + } |
|
293 | 293 | |
294 | - /** |
|
295 | - * Finds a matching cookie to write over or the |
|
296 | - * first empty slot if none. |
|
297 | - * @param SimpleCookie $cookie Cookie to write into jar. |
|
298 | - * @return integer Available slot. |
|
299 | - * @access private |
|
300 | - */ |
|
301 | - function _findFirstMatch($cookie) { |
|
302 | - for ($i = 0; $i < count($this->_cookies); $i++) { |
|
303 | - $is_match = $this->_isMatch( |
|
304 | - $cookie, |
|
305 | - $this->_cookies[$i]->getHost(), |
|
306 | - $this->_cookies[$i]->getPath(), |
|
307 | - $this->_cookies[$i]->getName()); |
|
308 | - if ($is_match) { |
|
309 | - return $i; |
|
310 | - } |
|
311 | - } |
|
312 | - return count($this->_cookies); |
|
313 | - } |
|
294 | + /** |
|
295 | + * Finds a matching cookie to write over or the |
|
296 | + * first empty slot if none. |
|
297 | + * @param SimpleCookie $cookie Cookie to write into jar. |
|
298 | + * @return integer Available slot. |
|
299 | + * @access private |
|
300 | + */ |
|
301 | + function _findFirstMatch($cookie) { |
|
302 | + for ($i = 0; $i < count($this->_cookies); $i++) { |
|
303 | + $is_match = $this->_isMatch( |
|
304 | + $cookie, |
|
305 | + $this->_cookies[$i]->getHost(), |
|
306 | + $this->_cookies[$i]->getPath(), |
|
307 | + $this->_cookies[$i]->getName()); |
|
308 | + if ($is_match) { |
|
309 | + return $i; |
|
310 | + } |
|
311 | + } |
|
312 | + return count($this->_cookies); |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
316 | - * Reads the most specific cookie value from the |
|
317 | - * browser cookies. Looks for the longest path that |
|
318 | - * matches. |
|
319 | - * @param string $host Host to search. |
|
320 | - * @param string $path Applicable path. |
|
321 | - * @param string $name Name of cookie to read. |
|
322 | - * @return string False if not present, else the |
|
323 | - * value as a string. |
|
324 | - * @access public |
|
325 | - */ |
|
326 | - function getCookieValue($host, $path, $name) { |
|
327 | - $longest_path = ''; |
|
328 | - foreach ($this->_cookies as $cookie) { |
|
329 | - if ($this->_isMatch($cookie, $host, $path, $name)) { |
|
330 | - if (strlen($cookie->getPath()) > strlen($longest_path)) { |
|
331 | - $value = $cookie->getValue(); |
|
332 | - $longest_path = $cookie->getPath(); |
|
333 | - } |
|
334 | - } |
|
335 | - } |
|
336 | - return (isset($value) ? $value : false); |
|
337 | - } |
|
315 | + /** |
|
316 | + * Reads the most specific cookie value from the |
|
317 | + * browser cookies. Looks for the longest path that |
|
318 | + * matches. |
|
319 | + * @param string $host Host to search. |
|
320 | + * @param string $path Applicable path. |
|
321 | + * @param string $name Name of cookie to read. |
|
322 | + * @return string False if not present, else the |
|
323 | + * value as a string. |
|
324 | + * @access public |
|
325 | + */ |
|
326 | + function getCookieValue($host, $path, $name) { |
|
327 | + $longest_path = ''; |
|
328 | + foreach ($this->_cookies as $cookie) { |
|
329 | + if ($this->_isMatch($cookie, $host, $path, $name)) { |
|
330 | + if (strlen($cookie->getPath()) > strlen($longest_path)) { |
|
331 | + $value = $cookie->getValue(); |
|
332 | + $longest_path = $cookie->getPath(); |
|
333 | + } |
|
334 | + } |
|
335 | + } |
|
336 | + return (isset($value) ? $value : false); |
|
337 | + } |
|
338 | 338 | |
339 | - /** |
|
340 | - * Tests cookie for matching against search |
|
341 | - * criteria. |
|
342 | - * @param SimpleTest $cookie Cookie to test. |
|
343 | - * @param string $host Host must match. |
|
344 | - * @param string $path Cookie path must be shorter than |
|
345 | - * this path. |
|
346 | - * @param string $name Name must match. |
|
347 | - * @return boolean True if matched. |
|
348 | - * @access private |
|
349 | - */ |
|
350 | - function _isMatch($cookie, $host, $path, $name) { |
|
351 | - if ($cookie->getName() != $name) { |
|
352 | - return false; |
|
353 | - } |
|
354 | - if ($host && $cookie->getHost() && ! $cookie->isValidHost($host)) { |
|
355 | - return false; |
|
356 | - } |
|
357 | - if (! $cookie->isValidPath($path)) { |
|
358 | - return false; |
|
359 | - } |
|
360 | - return true; |
|
361 | - } |
|
339 | + /** |
|
340 | + * Tests cookie for matching against search |
|
341 | + * criteria. |
|
342 | + * @param SimpleTest $cookie Cookie to test. |
|
343 | + * @param string $host Host must match. |
|
344 | + * @param string $path Cookie path must be shorter than |
|
345 | + * this path. |
|
346 | + * @param string $name Name must match. |
|
347 | + * @return boolean True if matched. |
|
348 | + * @access private |
|
349 | + */ |
|
350 | + function _isMatch($cookie, $host, $path, $name) { |
|
351 | + if ($cookie->getName() != $name) { |
|
352 | + return false; |
|
353 | + } |
|
354 | + if ($host && $cookie->getHost() && ! $cookie->isValidHost($host)) { |
|
355 | + return false; |
|
356 | + } |
|
357 | + if (! $cookie->isValidPath($path)) { |
|
358 | + return false; |
|
359 | + } |
|
360 | + return true; |
|
361 | + } |
|
362 | 362 | |
363 | - /** |
|
364 | - * Uses a URL to sift relevant cookies by host and |
|
365 | - * path. Results are list of strings of form "name=value". |
|
366 | - * @param SimpleUrl $url Url to select by. |
|
367 | - * @return array Valid name and value pairs. |
|
368 | - * @access public |
|
369 | - */ |
|
370 | - function selectAsPairs($url) { |
|
371 | - $pairs = array(); |
|
372 | - foreach ($this->_cookies as $cookie) { |
|
373 | - if ($this->_isMatch($cookie, $url->getHost(), $url->getPath(), $cookie->getName())) { |
|
374 | - $pairs[] = $cookie->getName() . '=' . $cookie->getValue(); |
|
375 | - } |
|
376 | - } |
|
377 | - return $pairs; |
|
378 | - } |
|
379 | - } |
|
380 | 363 | \ No newline at end of file |
364 | + /** |
|
365 | + * Uses a URL to sift relevant cookies by host and |
|
366 | + * path. Results are list of strings of form "name=value". |
|
367 | + * @param SimpleUrl $url Url to select by. |
|
368 | + * @return array Valid name and value pairs. |
|
369 | + * @access public |
|
370 | + */ |
|
371 | + function selectAsPairs($url) { |
|
372 | + $pairs = array(); |
|
373 | + foreach ($this->_cookies as $cookie) { |
|
374 | + if ($this->_isMatch($cookie, $url->getHost(), $url->getPath(), $cookie->getName())) { |
|
375 | + $pairs[] = $cookie->getName() . '=' . $cookie->getValue(); |
|
376 | + } |
|
377 | + } |
|
378 | + return $pairs; |
|
379 | + } |
|
380 | + } |
|
381 | 381 | \ No newline at end of file |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @access public |
155 | 155 | */ |
156 | 156 | function getExpiry() { |
157 | - if (! $this->_expiry) { |
|
157 | + if (!$this->_expiry) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | return gmdate("D, d M Y H:i:s", $this->_expiry) . " GMT"; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @access public |
173 | 173 | */ |
174 | 174 | function isExpired($now) { |
175 | - if (! $this->_expiry) { |
|
175 | + if (!$this->_expiry) { |
|
176 | 176 | return true; |
177 | 177 | } |
178 | 178 | if (is_string($now)) { |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | function restartSession($date = false) { |
246 | 246 | $surviving_cookies = array(); |
247 | 247 | for ($i = 0; $i < count($this->_cookies); $i++) { |
248 | - if (! $this->_cookies[$i]->getValue()) { |
|
248 | + if (!$this->_cookies[$i]->getValue()) { |
|
249 | 249 | continue; |
250 | 250 | } |
251 | - if (! $this->_cookies[$i]->getExpiry()) { |
|
251 | + if (!$this->_cookies[$i]->getExpiry()) { |
|
252 | 252 | continue; |
253 | 253 | } |
254 | 254 | if ($date && $this->_cookies[$i]->isExpired($date)) { |
@@ -351,10 +351,10 @@ discard block |
||
351 | 351 | if ($cookie->getName() != $name) { |
352 | 352 | return false; |
353 | 353 | } |
354 | - if ($host && $cookie->getHost() && ! $cookie->isValidHost($host)) { |
|
354 | + if ($host && $cookie->getHost() && !$cookie->isValidHost($host)) { |
|
355 | 355 | return false; |
356 | 356 | } |
357 | - if (! $cookie->isValidPath($path)) { |
|
357 | + if (!$cookie->isValidPath($path)) { |
|
358 | 358 | return false; |
359 | 359 | } |
360 | 360 | return true; |
@@ -248,7 +248,7 @@ |
||
248 | 248 | * form encoded packet. |
249 | 249 | * @param string $key Key to add value to. |
250 | 250 | * @param string $content Raw data. |
251 | - * @param hash $filename Original filename. |
|
251 | + * @param string $filename Original filename. |
|
252 | 252 | * @access public |
253 | 253 | */ |
254 | 254 | function attach($key, $content, $filename) { |
@@ -1,520 +1,520 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage WebTester |
|
6 | - * @version $Id: encoding.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: encoding.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__) . '/socket.php'); |
|
13 | - /**#@-*/ |
|
12 | + require_once(dirname(__FILE__) . '/socket.php'); |
|
13 | + /**#@-*/ |
|
14 | 14 | |
15 | - /** |
|
16 | - * Single post parameter. |
|
15 | + /** |
|
16 | + * Single post parameter. |
|
17 | 17 | * @package SimpleTest |
18 | 18 | * @subpackage WebTester |
19 | - */ |
|
20 | - class SimpleEncodedPair { |
|
21 | - protected $_key; |
|
22 | - protected $_value; |
|
23 | - |
|
24 | - /** |
|
25 | - * Stashes the data for rendering later. |
|
26 | - * @param string $key Form element name. |
|
27 | - * @param string $value Data to send. |
|
28 | - */ |
|
29 | - function SimpleEncodedPair($key, $value) { |
|
30 | - $this->_key = $key; |
|
31 | - $this->_value = $value; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * The pair as a single string. |
|
36 | - * @return string Encoded pair. |
|
37 | - * @access public |
|
38 | - */ |
|
39 | - function asRequest() { |
|
40 | - return $this->_key . '=' . urlencode($this->_value); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * The MIME part as a string. |
|
45 | - * @return string MIME part encoding. |
|
46 | - * @access public |
|
47 | - */ |
|
48 | - function asMime() { |
|
49 | - $part = 'Content-Disposition: form-data; '; |
|
50 | - $part .= "name=\"" . $this->_key . "\"\r\n"; |
|
51 | - $part .= "\r\n" . $this->_value; |
|
52 | - return $part; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Is this the value we are looking for? |
|
57 | - * @param string $key Identifier. |
|
58 | - * @return boolean True if matched. |
|
59 | - * @access public |
|
60 | - */ |
|
61 | - function isKey($key) { |
|
62 | - return $key == $this->_key; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Is this the value we are looking for? |
|
67 | - * @return string Identifier. |
|
68 | - * @access public |
|
69 | - */ |
|
70 | - function getKey() { |
|
71 | - return $this->_key; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Is this the value we are looking for? |
|
76 | - * @return string Content. |
|
77 | - * @access public |
|
78 | - */ |
|
79 | - function getValue() { |
|
80 | - return $this->_value; |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Single post parameter. |
|
19 | + */ |
|
20 | + class SimpleEncodedPair { |
|
21 | + protected $_key; |
|
22 | + protected $_value; |
|
23 | + |
|
24 | + /** |
|
25 | + * Stashes the data for rendering later. |
|
26 | + * @param string $key Form element name. |
|
27 | + * @param string $value Data to send. |
|
28 | + */ |
|
29 | + function SimpleEncodedPair($key, $value) { |
|
30 | + $this->_key = $key; |
|
31 | + $this->_value = $value; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * The pair as a single string. |
|
36 | + * @return string Encoded pair. |
|
37 | + * @access public |
|
38 | + */ |
|
39 | + function asRequest() { |
|
40 | + return $this->_key . '=' . urlencode($this->_value); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * The MIME part as a string. |
|
45 | + * @return string MIME part encoding. |
|
46 | + * @access public |
|
47 | + */ |
|
48 | + function asMime() { |
|
49 | + $part = 'Content-Disposition: form-data; '; |
|
50 | + $part .= "name=\"" . $this->_key . "\"\r\n"; |
|
51 | + $part .= "\r\n" . $this->_value; |
|
52 | + return $part; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Is this the value we are looking for? |
|
57 | + * @param string $key Identifier. |
|
58 | + * @return boolean True if matched. |
|
59 | + * @access public |
|
60 | + */ |
|
61 | + function isKey($key) { |
|
62 | + return $key == $this->_key; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Is this the value we are looking for? |
|
67 | + * @return string Identifier. |
|
68 | + * @access public |
|
69 | + */ |
|
70 | + function getKey() { |
|
71 | + return $this->_key; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Is this the value we are looking for? |
|
76 | + * @return string Content. |
|
77 | + * @access public |
|
78 | + */ |
|
79 | + function getValue() { |
|
80 | + return $this->_value; |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Single post parameter. |
|
86 | 86 | * @package SimpleTest |
87 | 87 | * @subpackage WebTester |
88 | - */ |
|
89 | - class SimpleAttachment { |
|
90 | - protected $_key; |
|
91 | - protected $_content; |
|
92 | - protected $_filename; |
|
93 | - |
|
94 | - /** |
|
95 | - * Stashes the data for rendering later. |
|
96 | - * @param string $key Key to add value to. |
|
97 | - * @param string $content Raw data. |
|
98 | - * @param hash $filename Original filename. |
|
99 | - */ |
|
100 | - function SimpleAttachment($key, $content, $filename) { |
|
101 | - $this->_key = $key; |
|
102 | - $this->_content = $content; |
|
103 | - $this->_filename = $filename; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * The pair as a single string. |
|
108 | - * @return string Encoded pair. |
|
109 | - * @access public |
|
110 | - */ |
|
111 | - function asRequest() { |
|
112 | - return ''; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * The MIME part as a string. |
|
117 | - * @return string MIME part encoding. |
|
118 | - * @access public |
|
119 | - */ |
|
120 | - function asMime() { |
|
121 | - $part = 'Content-Disposition: form-data; '; |
|
122 | - $part .= 'name="' . $this->_key . '"; '; |
|
123 | - $part .= 'filename="' . $this->_filename . '"'; |
|
124 | - $part .= "\r\nContent-Type: " . $this->_deduceMimeType(); |
|
125 | - $part .= "\r\n\r\n" . $this->_content; |
|
126 | - return $part; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Attempts to figure out the MIME type from the |
|
131 | - * file extension and the content. |
|
132 | - * @return string MIME type. |
|
133 | - * @access private |
|
134 | - */ |
|
135 | - function _deduceMimeType() { |
|
136 | - if ($this->_isOnlyAscii($this->_content)) { |
|
137 | - return 'text/plain'; |
|
138 | - } |
|
139 | - return 'application/octet-stream'; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Tests each character is in the range 0-127. |
|
144 | - * @param string $ascii String to test. |
|
145 | - * @access private |
|
146 | - */ |
|
147 | - function _isOnlyAscii($ascii) { |
|
148 | - for ($i = 0, $length = strlen($ascii); $i < $length; $i++) { |
|
149 | - if (ord($ascii[$i]) > 127) { |
|
150 | - return false; |
|
151 | - } |
|
152 | - } |
|
153 | - return true; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Is this the value we are looking for? |
|
158 | - * @param string $key Identifier. |
|
159 | - * @return boolean True if matched. |
|
160 | - * @access public |
|
161 | - */ |
|
162 | - function isKey($key) { |
|
163 | - return $key == $this->_key; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Is this the value we are looking for? |
|
168 | - * @return string Identifier. |
|
169 | - * @access public |
|
170 | - */ |
|
171 | - function getKey() { |
|
172 | - return $this->_key; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Is this the value we are looking for? |
|
177 | - * @return string Content. |
|
178 | - * @access public |
|
179 | - */ |
|
180 | - function getValue() { |
|
181 | - return $this->_filename; |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Bundle of GET/POST parameters. Can include |
|
187 | - * repeated parameters. |
|
88 | + */ |
|
89 | + class SimpleAttachment { |
|
90 | + protected $_key; |
|
91 | + protected $_content; |
|
92 | + protected $_filename; |
|
93 | + |
|
94 | + /** |
|
95 | + * Stashes the data for rendering later. |
|
96 | + * @param string $key Key to add value to. |
|
97 | + * @param string $content Raw data. |
|
98 | + * @param hash $filename Original filename. |
|
99 | + */ |
|
100 | + function SimpleAttachment($key, $content, $filename) { |
|
101 | + $this->_key = $key; |
|
102 | + $this->_content = $content; |
|
103 | + $this->_filename = $filename; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * The pair as a single string. |
|
108 | + * @return string Encoded pair. |
|
109 | + * @access public |
|
110 | + */ |
|
111 | + function asRequest() { |
|
112 | + return ''; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * The MIME part as a string. |
|
117 | + * @return string MIME part encoding. |
|
118 | + * @access public |
|
119 | + */ |
|
120 | + function asMime() { |
|
121 | + $part = 'Content-Disposition: form-data; '; |
|
122 | + $part .= 'name="' . $this->_key . '"; '; |
|
123 | + $part .= 'filename="' . $this->_filename . '"'; |
|
124 | + $part .= "\r\nContent-Type: " . $this->_deduceMimeType(); |
|
125 | + $part .= "\r\n\r\n" . $this->_content; |
|
126 | + return $part; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Attempts to figure out the MIME type from the |
|
131 | + * file extension and the content. |
|
132 | + * @return string MIME type. |
|
133 | + * @access private |
|
134 | + */ |
|
135 | + function _deduceMimeType() { |
|
136 | + if ($this->_isOnlyAscii($this->_content)) { |
|
137 | + return 'text/plain'; |
|
138 | + } |
|
139 | + return 'application/octet-stream'; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Tests each character is in the range 0-127. |
|
144 | + * @param string $ascii String to test. |
|
145 | + * @access private |
|
146 | + */ |
|
147 | + function _isOnlyAscii($ascii) { |
|
148 | + for ($i = 0, $length = strlen($ascii); $i < $length; $i++) { |
|
149 | + if (ord($ascii[$i]) > 127) { |
|
150 | + return false; |
|
151 | + } |
|
152 | + } |
|
153 | + return true; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Is this the value we are looking for? |
|
158 | + * @param string $key Identifier. |
|
159 | + * @return boolean True if matched. |
|
160 | + * @access public |
|
161 | + */ |
|
162 | + function isKey($key) { |
|
163 | + return $key == $this->_key; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Is this the value we are looking for? |
|
168 | + * @return string Identifier. |
|
169 | + * @access public |
|
170 | + */ |
|
171 | + function getKey() { |
|
172 | + return $this->_key; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Is this the value we are looking for? |
|
177 | + * @return string Content. |
|
178 | + * @access public |
|
179 | + */ |
|
180 | + function getValue() { |
|
181 | + return $this->_filename; |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Bundle of GET/POST parameters. Can include |
|
187 | + * repeated parameters. |
|
188 | 188 | * @package SimpleTest |
189 | 189 | * @subpackage WebTester |
190 | - */ |
|
191 | - class SimpleEncoding { |
|
192 | - protected $_request; |
|
193 | - |
|
194 | - /** |
|
195 | - * Starts empty. |
|
196 | - * @param array $query Hash of parameters. |
|
197 | - * Multiple values are |
|
198 | - * as lists on a single key. |
|
199 | - * @access public |
|
200 | - */ |
|
201 | - function SimpleEncoding($query = false) { |
|
202 | - if (! $query) { |
|
203 | - $query = array(); |
|
204 | - } |
|
205 | - $this->clear(); |
|
206 | - $this->merge($query); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Empties the request of parameters. |
|
211 | - * @access public |
|
212 | - */ |
|
213 | - function clear() { |
|
214 | - $this->_request = array(); |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Adds a parameter to the query. |
|
219 | - * @param string $key Key to add value to. |
|
220 | - * @param string/array $value New data. |
|
221 | - * @access public |
|
222 | - */ |
|
223 | - function add($key, $value) { |
|
224 | - if ($value === false) { |
|
225 | - return; |
|
226 | - } |
|
227 | - if (is_array($value)) { |
|
228 | - foreach ($value as $item) { |
|
229 | - $this->_addPair($key, $item); |
|
230 | - } |
|
231 | - } else { |
|
232 | - $this->_addPair($key, $value); |
|
233 | - } |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Adds a new value into the request. |
|
238 | - * @param string $key Key to add value to. |
|
239 | - * @param string/array $value New data. |
|
240 | - * @access private |
|
241 | - */ |
|
242 | - function _addPair($key, $value) { |
|
243 | - $this->_request[] = new SimpleEncodedPair($key, $value); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Adds a MIME part to the query. Does nothing for a |
|
248 | - * form encoded packet. |
|
249 | - * @param string $key Key to add value to. |
|
250 | - * @param string $content Raw data. |
|
251 | - * @param hash $filename Original filename. |
|
252 | - * @access public |
|
253 | - */ |
|
254 | - function attach($key, $content, $filename) { |
|
255 | - $this->_request[] = new SimpleAttachment($key, $content, $filename); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Adds a set of parameters to this query. |
|
260 | - * @param array/SimpleQueryString $query Multiple values are |
|
261 | - * as lists on a single key. |
|
262 | - * @access public |
|
263 | - */ |
|
264 | - function merge($query) { |
|
265 | - if (is_object($query)) { |
|
266 | - $this->_request = array_merge($this->_request, $query->getAll()); |
|
267 | - } elseif (is_array($query)) { |
|
268 | - foreach ($query as $key => $value) { |
|
269 | - $this->add($key, $value); |
|
270 | - } |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Accessor for single value. |
|
276 | - * @return string/array False if missing, string |
|
277 | - * if present and array if |
|
278 | - * multiple entries. |
|
279 | - * @access public |
|
280 | - */ |
|
281 | - function getValue($key) { |
|
282 | - $values = array(); |
|
283 | - foreach ($this->_request as $pair) { |
|
284 | - if ($pair->isKey($key)) { |
|
285 | - $values[] = $pair->getValue(); |
|
286 | - } |
|
287 | - } |
|
288 | - if (count($values) == 0) { |
|
289 | - return false; |
|
290 | - } elseif (count($values) == 1) { |
|
291 | - return $values[0]; |
|
292 | - } else { |
|
293 | - return $values; |
|
294 | - } |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Accessor for listing of pairs. |
|
299 | - * @return array All pair objects. |
|
300 | - * @access public |
|
301 | - */ |
|
302 | - function getAll() { |
|
303 | - return $this->_request; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Renders the query string as a URL encoded |
|
308 | - * request part. |
|
309 | - * @return string Part of URL. |
|
310 | - * @access protected |
|
311 | - */ |
|
312 | - function _encode() { |
|
313 | - $statements = array(); |
|
314 | - foreach ($this->_request as $pair) { |
|
315 | - if ($statement = $pair->asRequest()) { |
|
316 | - $statements[] = $statement; |
|
317 | - } |
|
318 | - } |
|
319 | - return implode('&', $statements); |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Bundle of GET parameters. Can include |
|
325 | - * repeated parameters. |
|
190 | + */ |
|
191 | + class SimpleEncoding { |
|
192 | + protected $_request; |
|
193 | + |
|
194 | + /** |
|
195 | + * Starts empty. |
|
196 | + * @param array $query Hash of parameters. |
|
197 | + * Multiple values are |
|
198 | + * as lists on a single key. |
|
199 | + * @access public |
|
200 | + */ |
|
201 | + function SimpleEncoding($query = false) { |
|
202 | + if (! $query) { |
|
203 | + $query = array(); |
|
204 | + } |
|
205 | + $this->clear(); |
|
206 | + $this->merge($query); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Empties the request of parameters. |
|
211 | + * @access public |
|
212 | + */ |
|
213 | + function clear() { |
|
214 | + $this->_request = array(); |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Adds a parameter to the query. |
|
219 | + * @param string $key Key to add value to. |
|
220 | + * @param string/array $value New data. |
|
221 | + * @access public |
|
222 | + */ |
|
223 | + function add($key, $value) { |
|
224 | + if ($value === false) { |
|
225 | + return; |
|
226 | + } |
|
227 | + if (is_array($value)) { |
|
228 | + foreach ($value as $item) { |
|
229 | + $this->_addPair($key, $item); |
|
230 | + } |
|
231 | + } else { |
|
232 | + $this->_addPair($key, $value); |
|
233 | + } |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Adds a new value into the request. |
|
238 | + * @param string $key Key to add value to. |
|
239 | + * @param string/array $value New data. |
|
240 | + * @access private |
|
241 | + */ |
|
242 | + function _addPair($key, $value) { |
|
243 | + $this->_request[] = new SimpleEncodedPair($key, $value); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Adds a MIME part to the query. Does nothing for a |
|
248 | + * form encoded packet. |
|
249 | + * @param string $key Key to add value to. |
|
250 | + * @param string $content Raw data. |
|
251 | + * @param hash $filename Original filename. |
|
252 | + * @access public |
|
253 | + */ |
|
254 | + function attach($key, $content, $filename) { |
|
255 | + $this->_request[] = new SimpleAttachment($key, $content, $filename); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Adds a set of parameters to this query. |
|
260 | + * @param array/SimpleQueryString $query Multiple values are |
|
261 | + * as lists on a single key. |
|
262 | + * @access public |
|
263 | + */ |
|
264 | + function merge($query) { |
|
265 | + if (is_object($query)) { |
|
266 | + $this->_request = array_merge($this->_request, $query->getAll()); |
|
267 | + } elseif (is_array($query)) { |
|
268 | + foreach ($query as $key => $value) { |
|
269 | + $this->add($key, $value); |
|
270 | + } |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Accessor for single value. |
|
276 | + * @return string/array False if missing, string |
|
277 | + * if present and array if |
|
278 | + * multiple entries. |
|
279 | + * @access public |
|
280 | + */ |
|
281 | + function getValue($key) { |
|
282 | + $values = array(); |
|
283 | + foreach ($this->_request as $pair) { |
|
284 | + if ($pair->isKey($key)) { |
|
285 | + $values[] = $pair->getValue(); |
|
286 | + } |
|
287 | + } |
|
288 | + if (count($values) == 0) { |
|
289 | + return false; |
|
290 | + } elseif (count($values) == 1) { |
|
291 | + return $values[0]; |
|
292 | + } else { |
|
293 | + return $values; |
|
294 | + } |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Accessor for listing of pairs. |
|
299 | + * @return array All pair objects. |
|
300 | + * @access public |
|
301 | + */ |
|
302 | + function getAll() { |
|
303 | + return $this->_request; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Renders the query string as a URL encoded |
|
308 | + * request part. |
|
309 | + * @return string Part of URL. |
|
310 | + * @access protected |
|
311 | + */ |
|
312 | + function _encode() { |
|
313 | + $statements = array(); |
|
314 | + foreach ($this->_request as $pair) { |
|
315 | + if ($statement = $pair->asRequest()) { |
|
316 | + $statements[] = $statement; |
|
317 | + } |
|
318 | + } |
|
319 | + return implode('&', $statements); |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Bundle of GET parameters. Can include |
|
325 | + * repeated parameters. |
|
326 | 326 | * @package SimpleTest |
327 | 327 | * @subpackage WebTester |
328 | - */ |
|
329 | - class SimpleGetEncoding extends SimpleEncoding { |
|
330 | - |
|
331 | - /** |
|
332 | - * Starts empty. |
|
333 | - * @param array $query Hash of parameters. |
|
334 | - * Multiple values are |
|
335 | - * as lists on a single key. |
|
336 | - * @access public |
|
337 | - */ |
|
338 | - function SimpleGetEncoding($query = false) { |
|
339 | - $this->SimpleEncoding($query); |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * HTTP request method. |
|
344 | - * @return string Always GET. |
|
345 | - * @access public |
|
346 | - */ |
|
347 | - function getMethod() { |
|
348 | - return 'GET'; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Writes no extra headers. |
|
353 | - * @param SimpleSocket $socket Socket to write to. |
|
354 | - * @access public |
|
355 | - */ |
|
356 | - function writeHeadersTo($socket) { |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * No data is sent to the socket as the data is encoded into |
|
361 | - * the URL. |
|
362 | - * @param SimpleSocket $socket Socket to write to. |
|
363 | - * @access public |
|
364 | - */ |
|
365 | - function writeTo($socket) { |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Renders the query string as a URL encoded |
|
370 | - * request part for attaching to a URL. |
|
371 | - * @return string Part of URL. |
|
372 | - * @access public |
|
373 | - */ |
|
374 | - function asUrlRequest() { |
|
375 | - return $this->_encode(); |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Bundle of URL parameters for a HEAD request. |
|
328 | + */ |
|
329 | + class SimpleGetEncoding extends SimpleEncoding { |
|
330 | + |
|
331 | + /** |
|
332 | + * Starts empty. |
|
333 | + * @param array $query Hash of parameters. |
|
334 | + * Multiple values are |
|
335 | + * as lists on a single key. |
|
336 | + * @access public |
|
337 | + */ |
|
338 | + function SimpleGetEncoding($query = false) { |
|
339 | + $this->SimpleEncoding($query); |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * HTTP request method. |
|
344 | + * @return string Always GET. |
|
345 | + * @access public |
|
346 | + */ |
|
347 | + function getMethod() { |
|
348 | + return 'GET'; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Writes no extra headers. |
|
353 | + * @param SimpleSocket $socket Socket to write to. |
|
354 | + * @access public |
|
355 | + */ |
|
356 | + function writeHeadersTo($socket) { |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * No data is sent to the socket as the data is encoded into |
|
361 | + * the URL. |
|
362 | + * @param SimpleSocket $socket Socket to write to. |
|
363 | + * @access public |
|
364 | + */ |
|
365 | + function writeTo($socket) { |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Renders the query string as a URL encoded |
|
370 | + * request part for attaching to a URL. |
|
371 | + * @return string Part of URL. |
|
372 | + * @access public |
|
373 | + */ |
|
374 | + function asUrlRequest() { |
|
375 | + return $this->_encode(); |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Bundle of URL parameters for a HEAD request. |
|
381 | 381 | * @package SimpleTest |
382 | 382 | * @subpackage WebTester |
383 | - */ |
|
384 | - class SimpleHeadEncoding extends SimpleGetEncoding { |
|
385 | - |
|
386 | - /** |
|
387 | - * Starts empty. |
|
388 | - * @param array $query Hash of parameters. |
|
389 | - * Multiple values are |
|
390 | - * as lists on a single key. |
|
391 | - * @access public |
|
392 | - */ |
|
393 | - function SimpleHeadEncoding($query = false) { |
|
394 | - $this->SimpleGetEncoding($query); |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * HTTP request method. |
|
399 | - * @return string Always HEAD. |
|
400 | - * @access public |
|
401 | - */ |
|
402 | - function getMethod() { |
|
403 | - return 'HEAD'; |
|
404 | - } |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Bundle of POST parameters. Can include |
|
409 | - * repeated parameters. |
|
383 | + */ |
|
384 | + class SimpleHeadEncoding extends SimpleGetEncoding { |
|
385 | + |
|
386 | + /** |
|
387 | + * Starts empty. |
|
388 | + * @param array $query Hash of parameters. |
|
389 | + * Multiple values are |
|
390 | + * as lists on a single key. |
|
391 | + * @access public |
|
392 | + */ |
|
393 | + function SimpleHeadEncoding($query = false) { |
|
394 | + $this->SimpleGetEncoding($query); |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * HTTP request method. |
|
399 | + * @return string Always HEAD. |
|
400 | + * @access public |
|
401 | + */ |
|
402 | + function getMethod() { |
|
403 | + return 'HEAD'; |
|
404 | + } |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Bundle of POST parameters. Can include |
|
409 | + * repeated parameters. |
|
410 | 410 | * @package SimpleTest |
411 | 411 | * @subpackage WebTester |
412 | - */ |
|
413 | - class SimplePostEncoding extends SimpleEncoding { |
|
414 | - |
|
415 | - /** |
|
416 | - * Starts empty. |
|
417 | - * @param array $query Hash of parameters. |
|
418 | - * Multiple values are |
|
419 | - * as lists on a single key. |
|
420 | - * @access public |
|
421 | - */ |
|
422 | - function SimplePostEncoding($query = false) { |
|
423 | - $this->SimpleEncoding($query); |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * HTTP request method. |
|
428 | - * @return string Always POST. |
|
429 | - * @access public |
|
430 | - */ |
|
431 | - function getMethod() { |
|
432 | - return 'POST'; |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * Dispatches the form headers down the socket. |
|
437 | - * @param SimpleSocket $socket Socket to write to. |
|
438 | - * @access public |
|
439 | - */ |
|
440 | - function writeHeadersTo($socket) { |
|
441 | - $socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n"); |
|
442 | - $socket->write("Content-Type: application/x-www-form-urlencoded\r\n"); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Dispatches the form data down the socket. |
|
447 | - * @param SimpleSocket $socket Socket to write to. |
|
448 | - * @access public |
|
449 | - */ |
|
450 | - function writeTo($socket) { |
|
451 | - $socket->write($this->_encode()); |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * Renders the query string as a URL encoded |
|
456 | - * request part for attaching to a URL. |
|
457 | - * @return string Part of URL. |
|
458 | - * @access public |
|
459 | - */ |
|
460 | - function asUrlRequest() { |
|
461 | - return ''; |
|
462 | - } |
|
463 | - } |
|
464 | - |
|
465 | - /** |
|
466 | - * Bundle of POST parameters in the multipart |
|
467 | - * format. Can include file uploads. |
|
412 | + */ |
|
413 | + class SimplePostEncoding extends SimpleEncoding { |
|
414 | + |
|
415 | + /** |
|
416 | + * Starts empty. |
|
417 | + * @param array $query Hash of parameters. |
|
418 | + * Multiple values are |
|
419 | + * as lists on a single key. |
|
420 | + * @access public |
|
421 | + */ |
|
422 | + function SimplePostEncoding($query = false) { |
|
423 | + $this->SimpleEncoding($query); |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * HTTP request method. |
|
428 | + * @return string Always POST. |
|
429 | + * @access public |
|
430 | + */ |
|
431 | + function getMethod() { |
|
432 | + return 'POST'; |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * Dispatches the form headers down the socket. |
|
437 | + * @param SimpleSocket $socket Socket to write to. |
|
438 | + * @access public |
|
439 | + */ |
|
440 | + function writeHeadersTo($socket) { |
|
441 | + $socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n"); |
|
442 | + $socket->write("Content-Type: application/x-www-form-urlencoded\r\n"); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Dispatches the form data down the socket. |
|
447 | + * @param SimpleSocket $socket Socket to write to. |
|
448 | + * @access public |
|
449 | + */ |
|
450 | + function writeTo($socket) { |
|
451 | + $socket->write($this->_encode()); |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * Renders the query string as a URL encoded |
|
456 | + * request part for attaching to a URL. |
|
457 | + * @return string Part of URL. |
|
458 | + * @access public |
|
459 | + */ |
|
460 | + function asUrlRequest() { |
|
461 | + return ''; |
|
462 | + } |
|
463 | + } |
|
464 | + |
|
465 | + /** |
|
466 | + * Bundle of POST parameters in the multipart |
|
467 | + * format. Can include file uploads. |
|
468 | 468 | * @package SimpleTest |
469 | 469 | * @subpackage WebTester |
470 | - */ |
|
471 | - class SimpleMultipartEncoding extends SimplePostEncoding { |
|
472 | - protected $_boundary; |
|
473 | - |
|
474 | - /** |
|
475 | - * Starts empty. |
|
476 | - * @param array $query Hash of parameters. |
|
477 | - * Multiple values are |
|
478 | - * as lists on a single key. |
|
479 | - * @access public |
|
480 | - */ |
|
481 | - function SimpleMultipartEncoding($query = false, $boundary = false) { |
|
482 | - $this->SimplePostEncoding($query); |
|
483 | - $this->_boundary = ($boundary === false ? uniqid('st') : $boundary); |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * Dispatches the form headers down the socket. |
|
488 | - * @param SimpleSocket $socket Socket to write to. |
|
489 | - * @access public |
|
490 | - */ |
|
491 | - function writeHeadersTo($socket) { |
|
492 | - $socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n"); |
|
493 | - $socket->write("Content-Type: multipart/form-data, boundary=" . $this->_boundary . "\r\n"); |
|
494 | - } |
|
495 | - |
|
496 | - /** |
|
497 | - * Dispatches the form data down the socket. |
|
498 | - * @param SimpleSocket $socket Socket to write to. |
|
499 | - * @access public |
|
500 | - */ |
|
501 | - function writeTo($socket) { |
|
502 | - $socket->write($this->_encode()); |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * Renders the query string as a URL encoded |
|
507 | - * request part. |
|
508 | - * @return string Part of URL. |
|
509 | - * @access public |
|
510 | - */ |
|
511 | - function _encode() { |
|
512 | - $stream = ''; |
|
513 | - foreach ($this->_request as $pair) { |
|
514 | - $stream .= "--" . $this->_boundary . "\r\n"; |
|
515 | - $stream .= $pair->asMime() . "\r\n"; |
|
516 | - } |
|
517 | - $stream .= "--" . $this->_boundary . "--\r\n"; |
|
518 | - return $stream; |
|
519 | - } |
|
520 | - } |
|
521 | 470 | \ No newline at end of file |
471 | + */ |
|
472 | + class SimpleMultipartEncoding extends SimplePostEncoding { |
|
473 | + protected $_boundary; |
|
474 | + |
|
475 | + /** |
|
476 | + * Starts empty. |
|
477 | + * @param array $query Hash of parameters. |
|
478 | + * Multiple values are |
|
479 | + * as lists on a single key. |
|
480 | + * @access public |
|
481 | + */ |
|
482 | + function SimpleMultipartEncoding($query = false, $boundary = false) { |
|
483 | + $this->SimplePostEncoding($query); |
|
484 | + $this->_boundary = ($boundary === false ? uniqid('st') : $boundary); |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * Dispatches the form headers down the socket. |
|
489 | + * @param SimpleSocket $socket Socket to write to. |
|
490 | + * @access public |
|
491 | + */ |
|
492 | + function writeHeadersTo($socket) { |
|
493 | + $socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n"); |
|
494 | + $socket->write("Content-Type: multipart/form-data, boundary=" . $this->_boundary . "\r\n"); |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * Dispatches the form data down the socket. |
|
499 | + * @param SimpleSocket $socket Socket to write to. |
|
500 | + * @access public |
|
501 | + */ |
|
502 | + function writeTo($socket) { |
|
503 | + $socket->write($this->_encode()); |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Renders the query string as a URL encoded |
|
508 | + * request part. |
|
509 | + * @return string Part of URL. |
|
510 | + * @access public |
|
511 | + */ |
|
512 | + function _encode() { |
|
513 | + $stream = ''; |
|
514 | + foreach ($this->_request as $pair) { |
|
515 | + $stream .= "--" . $this->_boundary . "\r\n"; |
|
516 | + $stream .= $pair->asMime() . "\r\n"; |
|
517 | + } |
|
518 | + $stream .= "--" . $this->_boundary . "--\r\n"; |
|
519 | + return $stream; |
|
520 | + } |
|
521 | + } |
|
522 | 522 | \ No newline at end of file |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @access public |
200 | 200 | */ |
201 | 201 | function SimpleEncoding($query = false) { |
202 | - if (! $query) { |
|
202 | + if (!$query) { |
|
203 | 203 | $query = array(); |
204 | 204 | } |
205 | 205 | $this->clear(); |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | * @access public |
439 | 439 | */ |
440 | 440 | function writeHeadersTo($socket) { |
441 | - $socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n"); |
|
441 | + $socket->write("Content-Length: " . (integer) strlen($this->_encode()) . "\r\n"); |
|
442 | 442 | $socket->write("Content-Type: application/x-www-form-urlencoded\r\n"); |
443 | 443 | } |
444 | 444 | |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | * @access public |
490 | 490 | */ |
491 | 491 | function writeHeadersTo($socket) { |
492 | - $socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n"); |
|
492 | + $socket->write("Content-Length: " . (integer) strlen($this->_encode()) . "\r\n"); |
|
493 | 493 | $socket->write("Content-Type: multipart/form-data, boundary=" . $this->_boundary . "\r\n"); |
494 | 494 | } |
495 | 495 |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | /** |
111 | 111 | * Tests to see if the queue is empty. |
112 | - * @return True if empty. |
|
112 | + * @return boolean if empty. |
|
113 | 113 | */ |
114 | 114 | function isEmpty() { |
115 | 115 | return (count($this->_queue) == 0); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | /** |
119 | 119 | * Global access to a single error queue. |
120 | - * @return Global error queue object. |
|
120 | + * @return SimpleErrorQueue error queue object. |
|
121 | 121 | * @access public |
122 | 122 | * @static |
123 | 123 | */ |
@@ -1,181 +1,181 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage UnitTester |
|
6 | - * @version $Id: errors.php 1606 2007-01-09 10:42:06Z wei $ |
|
7 | - */ |
|
2 | + /** |
|
3 | + * base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage UnitTester |
|
6 | + * @version $Id: errors.php 1606 2007-01-09 10:42:06Z wei $ |
|
7 | + */ |
|
8 | 8 | |
9 | - /** @ignore - PHP5 compatibility fix. */ |
|
10 | - if (! defined('E_STRICT')) { |
|
11 | - define('E_STRICT', 2048); |
|
12 | - } |
|
9 | + /** @ignore - PHP5 compatibility fix. */ |
|
10 | + if (! defined('E_STRICT')) { |
|
11 | + define('E_STRICT', 2048); |
|
12 | + } |
|
13 | 13 | |
14 | - /**#@+ |
|
14 | + /**#@+ |
|
15 | 15 | * Includes SimpleTest files. |
16 | 16 | */ |
17 | - require_once(dirname(__FILE__) . '/invoker.php'); |
|
17 | + require_once(dirname(__FILE__) . '/invoker.php'); |
|
18 | 18 | |
19 | - /** |
|
20 | - * Extension that traps errors into an error queue. |
|
19 | + /** |
|
20 | + * Extension that traps errors into an error queue. |
|
21 | 21 | * @package SimpleTest |
22 | 22 | * @subpackage UnitTester |
23 | - */ |
|
24 | - class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator { |
|
23 | + */ |
|
24 | + class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator { |
|
25 | 25 | |
26 | - /** |
|
27 | - * Stores the invoker to wrap. |
|
28 | - * @param SimpleInvoker $invoker Test method runner. |
|
29 | - */ |
|
30 | - function SimpleErrorTrappingInvoker($invoker) { |
|
31 | - $this->SimpleInvokerDecorator($invoker); |
|
32 | - } |
|
26 | + /** |
|
27 | + * Stores the invoker to wrap. |
|
28 | + * @param SimpleInvoker $invoker Test method runner. |
|
29 | + */ |
|
30 | + function SimpleErrorTrappingInvoker($invoker) { |
|
31 | + $this->SimpleInvokerDecorator($invoker); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Invokes a test method and dispatches any |
|
36 | - * untrapped errors. Called back from |
|
37 | - * the visiting runner. |
|
38 | - * @param string $method Test method to call. |
|
39 | - * @access public |
|
40 | - */ |
|
41 | - function invoke($method) { |
|
42 | - set_error_handler('simpleTestErrorHandler'); |
|
43 | - parent::invoke($method); |
|
44 | - $queue = SimpleErrorQueue::instance(); |
|
45 | - while (list($severity, $message, $file, $line, $globals) = $queue->extract()) { |
|
46 | - $severity = SimpleErrorQueue::getSeverityAsString($severity); |
|
47 | - $test_case = $this->getTestCase(); |
|
48 | - $test_case->error($severity, $message, $file, $line); |
|
49 | - } |
|
50 | - restore_error_handler(); |
|
51 | - } |
|
52 | - } |
|
34 | + /** |
|
35 | + * Invokes a test method and dispatches any |
|
36 | + * untrapped errors. Called back from |
|
37 | + * the visiting runner. |
|
38 | + * @param string $method Test method to call. |
|
39 | + * @access public |
|
40 | + */ |
|
41 | + function invoke($method) { |
|
42 | + set_error_handler('simpleTestErrorHandler'); |
|
43 | + parent::invoke($method); |
|
44 | + $queue = SimpleErrorQueue::instance(); |
|
45 | + while (list($severity, $message, $file, $line, $globals) = $queue->extract()) { |
|
46 | + $severity = SimpleErrorQueue::getSeverityAsString($severity); |
|
47 | + $test_case = $this->getTestCase(); |
|
48 | + $test_case->error($severity, $message, $file, $line); |
|
49 | + } |
|
50 | + restore_error_handler(); |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Singleton error queue used to record trapped |
|
56 | - * errors. |
|
54 | + /** |
|
55 | + * Singleton error queue used to record trapped |
|
56 | + * errors. |
|
57 | 57 | * @package SimpleTest |
58 | 58 | * @subpackage UnitTester |
59 | - */ |
|
60 | - class SimpleErrorQueue { |
|
61 | - protected $_queue; |
|
59 | + */ |
|
60 | + class SimpleErrorQueue { |
|
61 | + protected $_queue; |
|
62 | 62 | |
63 | - /** |
|
64 | - * Starts with an empty queue. |
|
65 | - * @access public |
|
66 | - */ |
|
67 | - function SimpleErrorQueue() { |
|
68 | - $this->clear(); |
|
69 | - } |
|
63 | + /** |
|
64 | + * Starts with an empty queue. |
|
65 | + * @access public |
|
66 | + */ |
|
67 | + function SimpleErrorQueue() { |
|
68 | + $this->clear(); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Adds an error to the front of the queue. |
|
73 | - * @param $severity PHP error code. |
|
74 | - * @param $message Text of error. |
|
75 | - * @param $filename File error occoured in. |
|
76 | - * @param $line Line number of error. |
|
77 | - * @param $super_globals Hash of PHP super global arrays. |
|
78 | - * @access public |
|
79 | - */ |
|
80 | - function add($severity, $message, $filename, $line, $super_globals) { |
|
81 | - array_push( |
|
82 | - $this->_queue, |
|
83 | - array($severity, $message, $filename, $line, $super_globals)); |
|
84 | - } |
|
71 | + /** |
|
72 | + * Adds an error to the front of the queue. |
|
73 | + * @param $severity PHP error code. |
|
74 | + * @param $message Text of error. |
|
75 | + * @param $filename File error occoured in. |
|
76 | + * @param $line Line number of error. |
|
77 | + * @param $super_globals Hash of PHP super global arrays. |
|
78 | + * @access public |
|
79 | + */ |
|
80 | + function add($severity, $message, $filename, $line, $super_globals) { |
|
81 | + array_push( |
|
82 | + $this->_queue, |
|
83 | + array($severity, $message, $filename, $line, $super_globals)); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Pulls the earliest error from the queue. |
|
88 | - * @return False if none, or a list of error |
|
89 | - * information. Elements are: severity |
|
90 | - * as the PHP error code, the error message, |
|
91 | - * the file with the error, the line number |
|
92 | - * and a list of PHP super global arrays. |
|
93 | - * @access public |
|
94 | - */ |
|
95 | - function extract() { |
|
96 | - if (count($this->_queue)) { |
|
97 | - return array_shift($this->_queue); |
|
98 | - } |
|
99 | - return false; |
|
100 | - } |
|
86 | + /** |
|
87 | + * Pulls the earliest error from the queue. |
|
88 | + * @return False if none, or a list of error |
|
89 | + * information. Elements are: severity |
|
90 | + * as the PHP error code, the error message, |
|
91 | + * the file with the error, the line number |
|
92 | + * and a list of PHP super global arrays. |
|
93 | + * @access public |
|
94 | + */ |
|
95 | + function extract() { |
|
96 | + if (count($this->_queue)) { |
|
97 | + return array_shift($this->_queue); |
|
98 | + } |
|
99 | + return false; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Discards the contents of the error queue. |
|
104 | - * @access public |
|
105 | - */ |
|
106 | - function clear() { |
|
107 | - $this->_queue = array(); |
|
108 | - } |
|
102 | + /** |
|
103 | + * Discards the contents of the error queue. |
|
104 | + * @access public |
|
105 | + */ |
|
106 | + function clear() { |
|
107 | + $this->_queue = array(); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Tests to see if the queue is empty. |
|
112 | - * @return True if empty. |
|
113 | - */ |
|
114 | - function isEmpty() { |
|
115 | - return (count($this->_queue) == 0); |
|
116 | - } |
|
110 | + /** |
|
111 | + * Tests to see if the queue is empty. |
|
112 | + * @return True if empty. |
|
113 | + */ |
|
114 | + function isEmpty() { |
|
115 | + return (count($this->_queue) == 0); |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * Global access to a single error queue. |
|
120 | - * @return Global error queue object. |
|
121 | - * @access public |
|
122 | - * @static |
|
123 | - */ |
|
124 | - static function instance() { |
|
125 | - static $queue = false; |
|
126 | - if (! $queue) { |
|
127 | - $queue = new SimpleErrorQueue(); |
|
128 | - } |
|
129 | - return $queue; |
|
130 | - } |
|
118 | + /** |
|
119 | + * Global access to a single error queue. |
|
120 | + * @return Global error queue object. |
|
121 | + * @access public |
|
122 | + * @static |
|
123 | + */ |
|
124 | + static function instance() { |
|
125 | + static $queue = false; |
|
126 | + if (! $queue) { |
|
127 | + $queue = new SimpleErrorQueue(); |
|
128 | + } |
|
129 | + return $queue; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Converst an error code into it's string |
|
134 | - * representation. |
|
135 | - * @param $severity PHP integer error code. |
|
136 | - * @return String version of error code. |
|
137 | - * @access public |
|
138 | - * @static |
|
139 | - */ |
|
140 | - static function getSeverityAsString($severity) { |
|
141 | - static $map = array( |
|
142 | - E_STRICT => 'E_STRICT', |
|
143 | - E_ERROR => 'E_ERROR', |
|
144 | - E_WARNING => 'E_WARNING', |
|
145 | - E_PARSE => 'E_PARSE', |
|
146 | - E_NOTICE => 'E_NOTICE', |
|
147 | - E_CORE_ERROR => 'E_CORE_ERROR', |
|
148 | - E_CORE_WARNING => 'E_CORE_WARNING', |
|
149 | - E_COMPILE_ERROR => 'E_COMPILE_ERROR', |
|
150 | - E_COMPILE_WARNING => 'E_COMPILE_WARNING', |
|
151 | - E_USER_ERROR => 'E_USER_ERROR', |
|
152 | - E_USER_WARNING => 'E_USER_WARNING', |
|
153 | - E_USER_NOTICE => 'E_USER_NOTICE', 4096 => 'E??'); |
|
154 | - return $map[$severity]; |
|
155 | - } |
|
156 | - } |
|
132 | + /** |
|
133 | + * Converst an error code into it's string |
|
134 | + * representation. |
|
135 | + * @param $severity PHP integer error code. |
|
136 | + * @return String version of error code. |
|
137 | + * @access public |
|
138 | + * @static |
|
139 | + */ |
|
140 | + static function getSeverityAsString($severity) { |
|
141 | + static $map = array( |
|
142 | + E_STRICT => 'E_STRICT', |
|
143 | + E_ERROR => 'E_ERROR', |
|
144 | + E_WARNING => 'E_WARNING', |
|
145 | + E_PARSE => 'E_PARSE', |
|
146 | + E_NOTICE => 'E_NOTICE', |
|
147 | + E_CORE_ERROR => 'E_CORE_ERROR', |
|
148 | + E_CORE_WARNING => 'E_CORE_WARNING', |
|
149 | + E_COMPILE_ERROR => 'E_COMPILE_ERROR', |
|
150 | + E_COMPILE_WARNING => 'E_COMPILE_WARNING', |
|
151 | + E_USER_ERROR => 'E_USER_ERROR', |
|
152 | + E_USER_WARNING => 'E_USER_WARNING', |
|
153 | + E_USER_NOTICE => 'E_USER_NOTICE', 4096 => 'E??'); |
|
154 | + return $map[$severity]; |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Error handler that simply stashes any errors into the global |
|
160 | - * error queue. Simulates the existing behaviour with respect to |
|
161 | - * logging errors, but this feature may be removed in future. |
|
162 | - * @param $severity PHP error code. |
|
163 | - * @param $message Text of error. |
|
164 | - * @param $filename File error occoured in. |
|
165 | - * @param $line Line number of error. |
|
166 | - * @param $super_globals Hash of PHP super global arrays. |
|
167 | - * @static |
|
168 | - * @access public |
|
169 | - */ |
|
170 | - function simpleTestErrorHandler($severity, $message, $filename, $line, $super_globals) { |
|
171 | - if ($severity = $severity & error_reporting()) { |
|
172 | - restore_error_handler(); |
|
173 | - if (ini_get('log_errors')) { |
|
174 | - $label = SimpleErrorQueue::getSeverityAsString($severity); |
|
175 | - error_log("$label: $message in $filename on line $line"); |
|
176 | - } |
|
177 | - $queue = SimpleErrorQueue::instance(); |
|
178 | - $queue->add($severity, $message, $filename, $line, $super_globals); |
|
179 | - set_error_handler('simpleTestErrorHandler'); |
|
180 | - } |
|
181 | - } |
|
182 | 158 | \ No newline at end of file |
159 | + /** |
|
160 | + * Error handler that simply stashes any errors into the global |
|
161 | + * error queue. Simulates the existing behaviour with respect to |
|
162 | + * logging errors, but this feature may be removed in future. |
|
163 | + * @param $severity PHP error code. |
|
164 | + * @param $message Text of error. |
|
165 | + * @param $filename File error occoured in. |
|
166 | + * @param $line Line number of error. |
|
167 | + * @param $super_globals Hash of PHP super global arrays. |
|
168 | + * @static |
|
169 | + * @access public |
|
170 | + */ |
|
171 | + function simpleTestErrorHandler($severity, $message, $filename, $line, $super_globals) { |
|
172 | + if ($severity = $severity & error_reporting()) { |
|
173 | + restore_error_handler(); |
|
174 | + if (ini_get('log_errors')) { |
|
175 | + $label = SimpleErrorQueue::getSeverityAsString($severity); |
|
176 | + error_log("$label: $message in $filename on line $line"); |
|
177 | + } |
|
178 | + $queue = SimpleErrorQueue::instance(); |
|
179 | + $queue->add($severity, $message, $filename, $line, $super_globals); |
|
180 | + set_error_handler('simpleTestErrorHandler'); |
|
181 | + } |
|
182 | + } |
|
183 | 183 | \ No newline at end of file |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | /** @ignore - PHP5 compatibility fix. */ |
10 | - if (! defined('E_STRICT')) { |
|
10 | + if (!defined('E_STRICT')) { |
|
11 | 11 | define('E_STRICT', 2048); |
12 | 12 | } |
13 | 13 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | static function instance() { |
125 | 125 | static $queue = false; |
126 | - if (! $queue) { |
|
126 | + if (!$queue) { |
|
127 | 127 | $queue = new SimpleErrorQueue(); |
128 | 128 | } |
129 | 129 | return $queue; |
@@ -37,7 +37,7 @@ |
||
37 | 37 | /** |
38 | 38 | * Tests the expectation. True if correct. |
39 | 39 | * @param mixed $compare Comparison value. |
40 | - * @return boolean True if correct. |
|
40 | + * @return boolean|null True if correct. |
|
41 | 41 | * @access public |
42 | 42 | * @abstract |
43 | 43 | */ |
@@ -1,719 +1,719 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage UnitTester |
|
6 | - * @version $Id: expectation.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: expectation.php 1532 2006-12-01 12:28:55Z xue $ |
|
7 | + */ |
|
8 | + |
|
9 | + /**#@+ |
|
10 | 10 | * include other SimpleTest class files |
11 | 11 | */ |
12 | - require_once(dirname(__FILE__) . '/dumper.php'); |
|
13 | - require_once(dirname(__FILE__) . '/compatibility.php'); |
|
14 | - /**#@-*/ |
|
15 | - |
|
16 | - /** |
|
17 | - * Assertion that can display failure information. |
|
18 | - * Also includes various helper methods. |
|
19 | - * @package SimpleTest |
|
20 | - * @subpackage UnitTester |
|
21 | - * @abstract |
|
22 | - */ |
|
23 | - class SimpleExpectation { |
|
24 | - protected $_dumper; |
|
25 | - protected $_message; |
|
26 | - |
|
27 | - /** |
|
28 | - * Creates a dumper for displaying values and sets |
|
29 | - * the test message. |
|
30 | - * @param string $message Customised message on failure. |
|
31 | - */ |
|
32 | - function SimpleExpectation($message = '%s') { |
|
33 | - $this->_dumper = new SimpleDumper(); |
|
34 | - $this->_message = $message; |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Tests the expectation. True if correct. |
|
39 | - * @param mixed $compare Comparison value. |
|
40 | - * @return boolean True if correct. |
|
41 | - * @access public |
|
42 | - * @abstract |
|
43 | - */ |
|
44 | - function test($compare) { |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Returns a human readable test message. |
|
49 | - * @param mixed $compare Comparison value. |
|
50 | - * @return string Description of success |
|
51 | - * or failure. |
|
52 | - * @access public |
|
53 | - * @abstract |
|
54 | - */ |
|
55 | - function testMessage($compare) { |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Overlays the generated message onto the stored user |
|
60 | - * message. An additional message can be interjected. |
|
61 | - * @param mixed $compare Comparison value. |
|
62 | - * @return string Description of success |
|
63 | - * or failure. |
|
64 | - * @access public |
|
65 | - */ |
|
66 | - function overlayMessage($compare) { |
|
67 | - return sprintf($this->_message, $this->testMessage($compare)); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Accessor for the dumper. |
|
72 | - * @return SimpleDumper Current value dumper. |
|
73 | - * @access protected |
|
74 | - */ |
|
75 | - function &_getDumper() { |
|
76 | - return $this->_dumper; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Test to see if a value is an expectation object. |
|
81 | - * A useful utility method. |
|
82 | - * @param mixed $expectation Hopefully an Epectation |
|
83 | - * class. |
|
84 | - * @return boolean True if descended from |
|
85 | - * this class. |
|
86 | - * @access public |
|
87 | - * @static |
|
88 | - */ |
|
89 | - static function isExpectation($expectation) { |
|
90 | - return is_object($expectation) && |
|
91 | - SimpleTestCompatibility::isA($expectation, 'SimpleExpectation'); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Test for equality. |
|
97 | - * @package SimpleTest |
|
98 | - * @subpackage UnitTester |
|
99 | - */ |
|
100 | - class EqualExpectation extends SimpleExpectation { |
|
101 | - protected $_value; |
|
102 | - |
|
103 | - /** |
|
104 | - * Sets the value to compare against. |
|
105 | - * @param mixed $value Test value to match. |
|
106 | - * @param string $message Customised message on failure. |
|
107 | - * @access public |
|
108 | - */ |
|
109 | - function EqualExpectation($value, $message = '%s') { |
|
110 | - $this->SimpleExpectation($message); |
|
111 | - $this->_value = $value; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Tests the expectation. True if it matches the |
|
116 | - * held value. |
|
117 | - * @param mixed $compare Comparison value. |
|
118 | - * @return boolean True if correct. |
|
119 | - * @access public |
|
120 | - */ |
|
121 | - function test($compare) { |
|
122 | - return (($this->_value == $compare) && ($compare == $this->_value)); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Returns a human readable test message. |
|
127 | - * @param mixed $compare Comparison value. |
|
128 | - * @return string Description of success |
|
129 | - * or failure. |
|
130 | - * @access public |
|
131 | - */ |
|
132 | - function testMessage($compare) { |
|
133 | - if ($this->test($compare)) { |
|
134 | - return "Equal expectation [" . $this->_dumper->describeValue($this->_value) . "]"; |
|
135 | - } else { |
|
136 | - return "Equal expectation fails " . |
|
137 | - $this->_dumper->describeDifference($this->_value, $compare); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Accessor for comparison value. |
|
143 | - * @return mixed Held value to compare with. |
|
144 | - * @access protected |
|
145 | - */ |
|
146 | - function _getValue() { |
|
147 | - return $this->_value; |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Test for inequality. |
|
153 | - * @package SimpleTest |
|
154 | - * @subpackage UnitTester |
|
155 | - */ |
|
156 | - class NotEqualExpectation extends EqualExpectation { |
|
157 | - |
|
158 | - /** |
|
159 | - * Sets the value to compare against. |
|
160 | - * @param mixed $value Test value to match. |
|
161 | - * @param string $message Customised message on failure. |
|
162 | - * @access public |
|
163 | - */ |
|
164 | - function NotEqualExpectation($value, $message = '%s') { |
|
165 | - $this->EqualExpectation($value, $message); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Tests the expectation. True if it differs from the |
|
170 | - * held value. |
|
171 | - * @param mixed $compare Comparison value. |
|
172 | - * @return boolean True if correct. |
|
173 | - * @access public |
|
174 | - */ |
|
175 | - function test($compare) { |
|
176 | - return ! parent::test($compare); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Returns a human readable test message. |
|
181 | - * @param mixed $compare Comparison value. |
|
182 | - * @return string Description of success |
|
183 | - * or failure. |
|
184 | - * @access public |
|
185 | - */ |
|
186 | - function testMessage($compare) { |
|
187 | - $dumper = $this->_getDumper(); |
|
188 | - if ($this->test($compare)) { |
|
189 | - return "Not equal expectation passes " . |
|
190 | - $dumper->describeDifference($this->_getValue(), $compare); |
|
191 | - } else { |
|
192 | - return "Not equal expectation fails [" . |
|
193 | - $dumper->describeValue($this->_getValue()) . |
|
194 | - "] matches"; |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Test for being within a range. |
|
201 | - * @package SimpleTest |
|
202 | - * @subpackage UnitTester |
|
203 | - */ |
|
204 | - class WithinMarginExpectation extends SimpleExpectation { |
|
205 | - protected $_upper; |
|
206 | - protected $_lower; |
|
207 | - |
|
208 | - /** |
|
209 | - * Sets the value to compare against and the fuzziness of |
|
210 | - * the match. Used for comparing floating point values. |
|
211 | - * @param mixed $value Test value to match. |
|
212 | - * @param mixed $margin Fuzziness of match. |
|
213 | - * @param string $message Customised message on failure. |
|
214 | - * @access public |
|
215 | - */ |
|
216 | - function WithinMarginExpectation($value, $margin, $message = '%s') { |
|
217 | - $this->SimpleExpectation($message); |
|
218 | - $this->_upper = $value + $margin; |
|
219 | - $this->_lower = $value - $margin; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Tests the expectation. True if it matches the |
|
224 | - * held value. |
|
225 | - * @param mixed $compare Comparison value. |
|
226 | - * @return boolean True if correct. |
|
227 | - * @access public |
|
228 | - */ |
|
229 | - function test($compare) { |
|
230 | - return (($compare <= $this->_upper) && ($compare >= $this->_lower)); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Returns a human readable test message. |
|
235 | - * @param mixed $compare Comparison value. |
|
236 | - * @return string Description of success |
|
237 | - * or failure. |
|
238 | - * @access public |
|
239 | - */ |
|
240 | - function testMessage($compare) { |
|
241 | - if ($this->test($compare)) { |
|
242 | - return $this->_withinMessage($compare); |
|
243 | - } else { |
|
244 | - return $this->_outsideMessage($compare); |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Creates a the message for being within the range. |
|
250 | - * @param mixed $compare Value being tested. |
|
251 | - * @access private |
|
252 | - */ |
|
253 | - function _withinMessage($compare) { |
|
254 | - return "Within expectation [" . $this->_dumper->describeValue($this->_lower) . "] and [" . |
|
255 | - $this->_dumper->describeValue($this->_upper) . "]"; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Creates a the message for being within the range. |
|
260 | - * @param mixed $compare Value being tested. |
|
261 | - * @access private |
|
262 | - */ |
|
263 | - function _outsideMessage($compare) { |
|
264 | - if ($compare > $this->_upper) { |
|
265 | - return "Outside expectation " . |
|
266 | - $this->_dumper->describeDifference($compare, $this->_upper); |
|
267 | - } else { |
|
268 | - return "Outside expectation " . |
|
269 | - $this->_dumper->describeDifference($compare, $this->_lower); |
|
270 | - } |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Test for being outside of a range. |
|
276 | - * @package SimpleTest |
|
277 | - * @subpackage UnitTester |
|
278 | - */ |
|
279 | - class OutsideMarginExpectation extends WithinMarginExpectation { |
|
280 | - |
|
281 | - /** |
|
282 | - * Sets the value to compare against and the fuzziness of |
|
283 | - * the match. Used for comparing floating point values. |
|
284 | - * @param mixed $value Test value to not match. |
|
285 | - * @param mixed $margin Fuzziness of match. |
|
286 | - * @param string $message Customised message on failure. |
|
287 | - * @access public |
|
288 | - */ |
|
289 | - function OutsideMarginExpectation($value, $margin, $message = '%s') { |
|
290 | - $this->WithinMarginExpectation($value, $margin, $message); |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Tests the expectation. True if it matches the |
|
295 | - * held value. |
|
296 | - * @param mixed $compare Comparison value. |
|
297 | - * @return boolean True if correct. |
|
298 | - * @access public |
|
299 | - */ |
|
300 | - function test($compare) { |
|
301 | - return ! parent::test($compare); |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Returns a human readable test message. |
|
306 | - * @param mixed $compare Comparison value. |
|
307 | - * @return string Description of success |
|
308 | - * or failure. |
|
309 | - * @access public |
|
310 | - */ |
|
311 | - function testMessage($compare) { |
|
312 | - if (! $this->test($compare)) { |
|
313 | - return $this->_withinMessage($compare); |
|
314 | - } else { |
|
315 | - return $this->_outsideMessage($compare); |
|
316 | - } |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Test for identity. |
|
322 | - * @package SimpleTest |
|
323 | - * @subpackage UnitTester |
|
324 | - */ |
|
325 | - class IdenticalExpectation extends EqualExpectation { |
|
326 | - |
|
327 | - /** |
|
328 | - * Sets the value to compare against. |
|
329 | - * @param mixed $value Test value to match. |
|
330 | - * @param string $message Customised message on failure. |
|
331 | - * @access public |
|
332 | - */ |
|
333 | - function IdenticalExpectation($value, $message = '%s') { |
|
334 | - $this->EqualExpectation($value, $message); |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Tests the expectation. True if it exactly |
|
339 | - * matches the held value. |
|
340 | - * @param mixed $compare Comparison value. |
|
341 | - * @return boolean True if correct. |
|
342 | - * @access public |
|
343 | - */ |
|
344 | - function test($compare) { |
|
345 | - return SimpleTestCompatibility::isIdentical($this->_getValue(), $compare); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Returns a human readable test message. |
|
350 | - * @param mixed $compare Comparison value. |
|
351 | - * @return string Description of success |
|
352 | - * or failure. |
|
353 | - * @access public |
|
354 | - */ |
|
355 | - function testMessage($compare) { |
|
356 | - $dumper = $this->_getDumper(); |
|
357 | - if ($this->test($compare)) { |
|
358 | - return "Identical expectation [" . $dumper->describeValue($this->_getValue()) . "]"; |
|
359 | - } else { |
|
360 | - return "Identical expectation [" . $dumper->describeValue($this->_getValue()) . |
|
361 | - "] fails with [" . |
|
362 | - $dumper->describeValue($compare) . "] " . |
|
363 | - $dumper->describeDifference($this->_getValue(), $compare, TYPE_MATTERS); |
|
364 | - } |
|
365 | - } |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Test for non-identity. |
|
370 | - * @package SimpleTest |
|
371 | - * @subpackage UnitTester |
|
372 | - */ |
|
373 | - class NotIdenticalExpectation extends IdenticalExpectation { |
|
374 | - |
|
375 | - /** |
|
376 | - * Sets the value to compare against. |
|
377 | - * @param mixed $value Test value to match. |
|
378 | - * @param string $message Customised message on failure. |
|
379 | - * @access public |
|
380 | - */ |
|
381 | - function NotIdenticalExpectation($value, $message = '%s') { |
|
382 | - $this->IdenticalExpectation($value, $message); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Tests the expectation. True if it differs from the |
|
387 | - * held value. |
|
388 | - * @param mixed $compare Comparison value. |
|
389 | - * @return boolean True if correct. |
|
390 | - * @access public |
|
391 | - */ |
|
392 | - function test($compare) { |
|
393 | - return ! parent::test($compare); |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * Returns a human readable test message. |
|
398 | - * @param mixed $compare Comparison value. |
|
399 | - * @return string Description of success |
|
400 | - * or failure. |
|
401 | - * @access public |
|
402 | - */ |
|
403 | - function testMessage($compare) { |
|
404 | - $dumper = $this->_getDumper(); |
|
405 | - if ($this->test($compare)) { |
|
406 | - return "Not identical expectation passes " . |
|
407 | - $dumper->describeDifference($this->_getValue(), $compare, TYPE_MATTERS); |
|
408 | - } else { |
|
409 | - return "Not identical expectation [" . $dumper->describeValue($this->_getValue()) . "] matches"; |
|
410 | - } |
|
411 | - } |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Test for a pattern using Perl regex rules. |
|
416 | - * @package SimpleTest |
|
417 | - * @subpackage UnitTester |
|
418 | - */ |
|
419 | - class PatternExpectation extends SimpleExpectation { |
|
420 | - protected $_pattern; |
|
421 | - |
|
422 | - /** |
|
423 | - * Sets the value to compare against. |
|
424 | - * @param string $pattern Pattern to search for. |
|
425 | - * @param string $message Customised message on failure. |
|
426 | - * @access public |
|
427 | - */ |
|
428 | - function PatternExpectation($pattern, $message = '%s') { |
|
429 | - $this->SimpleExpectation($message); |
|
430 | - $this->_pattern = $pattern; |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Accessor for the pattern. |
|
435 | - * @return string Perl regex as string. |
|
436 | - * @access protected |
|
437 | - */ |
|
438 | - function _getPattern() { |
|
439 | - return $this->_pattern; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Tests the expectation. True if the Perl regex |
|
444 | - * matches the comparison value. |
|
445 | - * @param string $compare Comparison value. |
|
446 | - * @return boolean True if correct. |
|
447 | - * @access public |
|
448 | - */ |
|
449 | - function test($compare) { |
|
450 | - return (boolean)preg_match($this->_getPattern(), $compare); |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Returns a human readable test message. |
|
455 | - * @param mixed $compare Comparison value. |
|
456 | - * @return string Description of success |
|
457 | - * or failure. |
|
458 | - * @access public |
|
459 | - */ |
|
460 | - function testMessage($compare) { |
|
461 | - if ($this->test($compare)) { |
|
462 | - return $this->_describePatternMatch($this->_getPattern(), $compare); |
|
463 | - } else { |
|
464 | - $dumper = $this->_getDumper(); |
|
465 | - return "Pattern [" . $this->_getPattern() . |
|
466 | - "] not detected in [" . |
|
467 | - $dumper->describeValue($compare) . "]"; |
|
468 | - } |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * Describes a pattern match including the string |
|
473 | - * found and it's position. |
|
474 | - * @package SimpleTest |
|
475 | - * @subpackage UnitTester |
|
476 | - * @param string $pattern Regex to match against. |
|
477 | - * @param string $subject Subject to search. |
|
478 | - * @access protected |
|
479 | - */ |
|
480 | - function _describePatternMatch($pattern, $subject) { |
|
481 | - preg_match($pattern, $subject, $matches); |
|
482 | - $position = strpos($subject, $matches[0]); |
|
483 | - $dumper = $this->_getDumper(); |
|
484 | - return "Pattern [$pattern] detected at character [$position] in [" . |
|
485 | - $dumper->describeValue($subject) . "] as [" . |
|
486 | - $matches[0] . "] in region [" . |
|
487 | - $dumper->clipString($subject, 100, $position) . "]"; |
|
488 | - } |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * @deprecated |
|
493 | - */ |
|
494 | - class WantedPatternExpectation extends PatternExpectation { |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * Fail if a pattern is detected within the |
|
499 | - * comparison. |
|
500 | - * @package SimpleTest |
|
501 | - * @subpackage UnitTester |
|
502 | - */ |
|
503 | - class NoPatternExpectation extends PatternExpectation { |
|
504 | - |
|
505 | - /** |
|
506 | - * Sets the reject pattern |
|
507 | - * @param string $pattern Pattern to search for. |
|
508 | - * @param string $message Customised message on failure. |
|
509 | - * @access public |
|
510 | - */ |
|
511 | - function NoPatternExpectation($pattern, $message = '%s') { |
|
512 | - $this->PatternExpectation($pattern, $message); |
|
513 | - } |
|
514 | - |
|
515 | - /** |
|
516 | - * Tests the expectation. False if the Perl regex |
|
517 | - * matches the comparison value. |
|
518 | - * @param string $compare Comparison value. |
|
519 | - * @return boolean True if correct. |
|
520 | - * @access public |
|
521 | - */ |
|
522 | - function test($compare) { |
|
523 | - return ! parent::test($compare); |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Returns a human readable test message. |
|
528 | - * @param string $compare Comparison value. |
|
529 | - * @return string Description of success |
|
530 | - * or failure. |
|
531 | - * @access public |
|
532 | - */ |
|
533 | - function testMessage($compare) { |
|
534 | - if ($this->test($compare)) { |
|
535 | - $dumper = $this->_getDumper(); |
|
536 | - return "Pattern [" . $this->_getPattern() . |
|
537 | - "] not detected in [" . |
|
538 | - $dumper->describeValue($compare) . "]"; |
|
539 | - } else { |
|
540 | - return $this->_describePatternMatch($this->_getPattern(), $compare); |
|
541 | - } |
|
542 | - } |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * @package SimpleTest |
|
547 | - * @subpackage UnitTester |
|
548 | - * @deprecated |
|
549 | - */ |
|
550 | - class UnwantedPatternExpectation extends NoPatternExpectation { |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Tests either type or class name if it's an object. |
|
555 | - * @package SimpleTest |
|
556 | - * @subpackage UnitTester |
|
557 | - */ |
|
558 | - class IsAExpectation extends SimpleExpectation { |
|
559 | - protected $_type; |
|
560 | - |
|
561 | - /** |
|
562 | - * Sets the type to compare with. |
|
563 | - * @param string $type Type or class name. |
|
564 | - * @param string $message Customised message on failure. |
|
565 | - * @access public |
|
566 | - */ |
|
567 | - function IsAExpectation($type, $message = '%s') { |
|
568 | - $this->SimpleExpectation($message); |
|
569 | - $this->_type = $type; |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Accessor for type to check against. |
|
574 | - * @return string Type or class name. |
|
575 | - * @access protected |
|
576 | - */ |
|
577 | - function _getType() { |
|
578 | - return $this->_type; |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * Tests the expectation. True if the type or |
|
583 | - * class matches the string value. |
|
584 | - * @param string $compare Comparison value. |
|
585 | - * @return boolean True if correct. |
|
586 | - * @access public |
|
587 | - */ |
|
588 | - function test($compare) { |
|
589 | - if (is_object($compare)) { |
|
590 | - return SimpleTestCompatibility::isA($compare, $this->_type); |
|
591 | - } else { |
|
592 | - return (strtolower(gettype($compare)) == $this->_canonicalType($this->_type)); |
|
593 | - } |
|
594 | - } |
|
595 | - |
|
596 | - /** |
|
597 | - * Coerces type name into a gettype() match. |
|
598 | - * @param string $type User type. |
|
599 | - * @return string Simpler type. |
|
600 | - * @access private |
|
601 | - */ |
|
602 | - function _canonicalType($type) { |
|
603 | - $type = strtolower($type); |
|
604 | - $map = array( |
|
605 | - 'bool' => 'boolean', |
|
606 | - 'float' => 'double', |
|
607 | - 'real' => 'double', |
|
608 | - 'int' => 'integer'); |
|
609 | - if (isset($map[$type])) { |
|
610 | - $type = $map[$type]; |
|
611 | - } |
|
612 | - return $type; |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Returns a human readable test message. |
|
617 | - * @param mixed $compare Comparison value. |
|
618 | - * @return string Description of success |
|
619 | - * or failure. |
|
620 | - * @access public |
|
621 | - */ |
|
622 | - function testMessage($compare) { |
|
623 | - $dumper = $this->_getDumper(); |
|
624 | - return "Value [" . $dumper->describeValue($compare) . |
|
625 | - "] should be type [" . $this->_type . "]"; |
|
626 | - } |
|
627 | - } |
|
628 | - |
|
629 | - /** |
|
630 | - * Tests either type or class name if it's an object. |
|
631 | - * Will succeed if the type does not match. |
|
632 | - * @package SimpleTest |
|
633 | - * @subpackage UnitTester |
|
634 | - */ |
|
635 | - class NotAExpectation extends IsAExpectation { |
|
636 | - protected $_type; |
|
637 | - |
|
638 | - /** |
|
639 | - * Sets the type to compare with. |
|
640 | - * @param string $type Type or class name. |
|
641 | - * @param string $message Customised message on failure. |
|
642 | - * @access public |
|
643 | - */ |
|
644 | - function NotAExpectation($type, $message = '%s') { |
|
645 | - $this->IsAExpectation($type, $message); |
|
646 | - } |
|
647 | - |
|
648 | - /** |
|
649 | - * Tests the expectation. False if the type or |
|
650 | - * class matches the string value. |
|
651 | - * @param string $compare Comparison value. |
|
652 | - * @return boolean True if different. |
|
653 | - * @access public |
|
654 | - */ |
|
655 | - function test($compare) { |
|
656 | - return ! parent::test($compare); |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Returns a human readable test message. |
|
661 | - * @param mixed $compare Comparison value. |
|
662 | - * @return string Description of success |
|
663 | - * or failure. |
|
664 | - * @access public |
|
665 | - */ |
|
666 | - function testMessage($compare) { |
|
667 | - $dumper = $this->_getDumper(); |
|
668 | - return "Value [" . $dumper->describeValue($compare) . |
|
669 | - "] should not be type [" . $this->_getType() . "]"; |
|
670 | - } |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * Tests for existance of a method in an object |
|
675 | - * @package SimpleTest |
|
676 | - * @subpackage UnitTester |
|
677 | - */ |
|
678 | - class MethodExistsExpectation extends SimpleExpectation { |
|
679 | - protected $_method; |
|
680 | - |
|
681 | - /** |
|
682 | - * Sets the value to compare against. |
|
683 | - * @param string $method Method to check. |
|
684 | - * @param string $message Customised message on failure. |
|
685 | - * @access public |
|
686 | - * @return void |
|
687 | - */ |
|
688 | - function MethodExistsExpectation($method, $message = '%s') { |
|
689 | - $this->SimpleExpectation($message); |
|
690 | - $this->_method = $method; |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * Tests the expectation. True if the method exists in the test object. |
|
695 | - * @param string $compare Comparison method name. |
|
696 | - * @return boolean True if correct. |
|
697 | - * @access public |
|
698 | - */ |
|
699 | - function test($compare) { |
|
700 | - return (boolean)(is_object($compare) && method_exists($compare, $this->_method)); |
|
701 | - } |
|
702 | - |
|
703 | - /** |
|
704 | - * Returns a human readable test message. |
|
705 | - * @param mixed $compare Comparison value. |
|
706 | - * @return string Description of success |
|
707 | - * or failure. |
|
708 | - * @access public |
|
709 | - */ |
|
710 | - function testMessage($compare) { |
|
711 | - $dumper = $this->_getDumper(); |
|
712 | - if (! is_object($compare)) { |
|
713 | - return 'No method on non-object [' . $dumper->describeValue($compare) . ']'; |
|
714 | - } |
|
715 | - $method = $this->_method; |
|
716 | - return "Object [" . $dumper->describeValue($compare) . |
|
717 | - "] should contain method [$method]"; |
|
718 | - } |
|
719 | - } |
|
12 | + require_once(dirname(__FILE__) . '/dumper.php'); |
|
13 | + require_once(dirname(__FILE__) . '/compatibility.php'); |
|
14 | + /**#@-*/ |
|
15 | + |
|
16 | + /** |
|
17 | + * Assertion that can display failure information. |
|
18 | + * Also includes various helper methods. |
|
19 | + * @package SimpleTest |
|
20 | + * @subpackage UnitTester |
|
21 | + * @abstract |
|
22 | + */ |
|
23 | + class SimpleExpectation { |
|
24 | + protected $_dumper; |
|
25 | + protected $_message; |
|
26 | + |
|
27 | + /** |
|
28 | + * Creates a dumper for displaying values and sets |
|
29 | + * the test message. |
|
30 | + * @param string $message Customised message on failure. |
|
31 | + */ |
|
32 | + function SimpleExpectation($message = '%s') { |
|
33 | + $this->_dumper = new SimpleDumper(); |
|
34 | + $this->_message = $message; |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Tests the expectation. True if correct. |
|
39 | + * @param mixed $compare Comparison value. |
|
40 | + * @return boolean True if correct. |
|
41 | + * @access public |
|
42 | + * @abstract |
|
43 | + */ |
|
44 | + function test($compare) { |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Returns a human readable test message. |
|
49 | + * @param mixed $compare Comparison value. |
|
50 | + * @return string Description of success |
|
51 | + * or failure. |
|
52 | + * @access public |
|
53 | + * @abstract |
|
54 | + */ |
|
55 | + function testMessage($compare) { |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Overlays the generated message onto the stored user |
|
60 | + * message. An additional message can be interjected. |
|
61 | + * @param mixed $compare Comparison value. |
|
62 | + * @return string Description of success |
|
63 | + * or failure. |
|
64 | + * @access public |
|
65 | + */ |
|
66 | + function overlayMessage($compare) { |
|
67 | + return sprintf($this->_message, $this->testMessage($compare)); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Accessor for the dumper. |
|
72 | + * @return SimpleDumper Current value dumper. |
|
73 | + * @access protected |
|
74 | + */ |
|
75 | + function &_getDumper() { |
|
76 | + return $this->_dumper; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Test to see if a value is an expectation object. |
|
81 | + * A useful utility method. |
|
82 | + * @param mixed $expectation Hopefully an Epectation |
|
83 | + * class. |
|
84 | + * @return boolean True if descended from |
|
85 | + * this class. |
|
86 | + * @access public |
|
87 | + * @static |
|
88 | + */ |
|
89 | + static function isExpectation($expectation) { |
|
90 | + return is_object($expectation) && |
|
91 | + SimpleTestCompatibility::isA($expectation, 'SimpleExpectation'); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Test for equality. |
|
97 | + * @package SimpleTest |
|
98 | + * @subpackage UnitTester |
|
99 | + */ |
|
100 | + class EqualExpectation extends SimpleExpectation { |
|
101 | + protected $_value; |
|
102 | + |
|
103 | + /** |
|
104 | + * Sets the value to compare against. |
|
105 | + * @param mixed $value Test value to match. |
|
106 | + * @param string $message Customised message on failure. |
|
107 | + * @access public |
|
108 | + */ |
|
109 | + function EqualExpectation($value, $message = '%s') { |
|
110 | + $this->SimpleExpectation($message); |
|
111 | + $this->_value = $value; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Tests the expectation. True if it matches the |
|
116 | + * held value. |
|
117 | + * @param mixed $compare Comparison value. |
|
118 | + * @return boolean True if correct. |
|
119 | + * @access public |
|
120 | + */ |
|
121 | + function test($compare) { |
|
122 | + return (($this->_value == $compare) && ($compare == $this->_value)); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Returns a human readable test message. |
|
127 | + * @param mixed $compare Comparison value. |
|
128 | + * @return string Description of success |
|
129 | + * or failure. |
|
130 | + * @access public |
|
131 | + */ |
|
132 | + function testMessage($compare) { |
|
133 | + if ($this->test($compare)) { |
|
134 | + return "Equal expectation [" . $this->_dumper->describeValue($this->_value) . "]"; |
|
135 | + } else { |
|
136 | + return "Equal expectation fails " . |
|
137 | + $this->_dumper->describeDifference($this->_value, $compare); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Accessor for comparison value. |
|
143 | + * @return mixed Held value to compare with. |
|
144 | + * @access protected |
|
145 | + */ |
|
146 | + function _getValue() { |
|
147 | + return $this->_value; |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Test for inequality. |
|
153 | + * @package SimpleTest |
|
154 | + * @subpackage UnitTester |
|
155 | + */ |
|
156 | + class NotEqualExpectation extends EqualExpectation { |
|
157 | + |
|
158 | + /** |
|
159 | + * Sets the value to compare against. |
|
160 | + * @param mixed $value Test value to match. |
|
161 | + * @param string $message Customised message on failure. |
|
162 | + * @access public |
|
163 | + */ |
|
164 | + function NotEqualExpectation($value, $message = '%s') { |
|
165 | + $this->EqualExpectation($value, $message); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Tests the expectation. True if it differs from the |
|
170 | + * held value. |
|
171 | + * @param mixed $compare Comparison value. |
|
172 | + * @return boolean True if correct. |
|
173 | + * @access public |
|
174 | + */ |
|
175 | + function test($compare) { |
|
176 | + return ! parent::test($compare); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Returns a human readable test message. |
|
181 | + * @param mixed $compare Comparison value. |
|
182 | + * @return string Description of success |
|
183 | + * or failure. |
|
184 | + * @access public |
|
185 | + */ |
|
186 | + function testMessage($compare) { |
|
187 | + $dumper = $this->_getDumper(); |
|
188 | + if ($this->test($compare)) { |
|
189 | + return "Not equal expectation passes " . |
|
190 | + $dumper->describeDifference($this->_getValue(), $compare); |
|
191 | + } else { |
|
192 | + return "Not equal expectation fails [" . |
|
193 | + $dumper->describeValue($this->_getValue()) . |
|
194 | + "] matches"; |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Test for being within a range. |
|
201 | + * @package SimpleTest |
|
202 | + * @subpackage UnitTester |
|
203 | + */ |
|
204 | + class WithinMarginExpectation extends SimpleExpectation { |
|
205 | + protected $_upper; |
|
206 | + protected $_lower; |
|
207 | + |
|
208 | + /** |
|
209 | + * Sets the value to compare against and the fuzziness of |
|
210 | + * the match. Used for comparing floating point values. |
|
211 | + * @param mixed $value Test value to match. |
|
212 | + * @param mixed $margin Fuzziness of match. |
|
213 | + * @param string $message Customised message on failure. |
|
214 | + * @access public |
|
215 | + */ |
|
216 | + function WithinMarginExpectation($value, $margin, $message = '%s') { |
|
217 | + $this->SimpleExpectation($message); |
|
218 | + $this->_upper = $value + $margin; |
|
219 | + $this->_lower = $value - $margin; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Tests the expectation. True if it matches the |
|
224 | + * held value. |
|
225 | + * @param mixed $compare Comparison value. |
|
226 | + * @return boolean True if correct. |
|
227 | + * @access public |
|
228 | + */ |
|
229 | + function test($compare) { |
|
230 | + return (($compare <= $this->_upper) && ($compare >= $this->_lower)); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Returns a human readable test message. |
|
235 | + * @param mixed $compare Comparison value. |
|
236 | + * @return string Description of success |
|
237 | + * or failure. |
|
238 | + * @access public |
|
239 | + */ |
|
240 | + function testMessage($compare) { |
|
241 | + if ($this->test($compare)) { |
|
242 | + return $this->_withinMessage($compare); |
|
243 | + } else { |
|
244 | + return $this->_outsideMessage($compare); |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Creates a the message for being within the range. |
|
250 | + * @param mixed $compare Value being tested. |
|
251 | + * @access private |
|
252 | + */ |
|
253 | + function _withinMessage($compare) { |
|
254 | + return "Within expectation [" . $this->_dumper->describeValue($this->_lower) . "] and [" . |
|
255 | + $this->_dumper->describeValue($this->_upper) . "]"; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Creates a the message for being within the range. |
|
260 | + * @param mixed $compare Value being tested. |
|
261 | + * @access private |
|
262 | + */ |
|
263 | + function _outsideMessage($compare) { |
|
264 | + if ($compare > $this->_upper) { |
|
265 | + return "Outside expectation " . |
|
266 | + $this->_dumper->describeDifference($compare, $this->_upper); |
|
267 | + } else { |
|
268 | + return "Outside expectation " . |
|
269 | + $this->_dumper->describeDifference($compare, $this->_lower); |
|
270 | + } |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Test for being outside of a range. |
|
276 | + * @package SimpleTest |
|
277 | + * @subpackage UnitTester |
|
278 | + */ |
|
279 | + class OutsideMarginExpectation extends WithinMarginExpectation { |
|
280 | + |
|
281 | + /** |
|
282 | + * Sets the value to compare against and the fuzziness of |
|
283 | + * the match. Used for comparing floating point values. |
|
284 | + * @param mixed $value Test value to not match. |
|
285 | + * @param mixed $margin Fuzziness of match. |
|
286 | + * @param string $message Customised message on failure. |
|
287 | + * @access public |
|
288 | + */ |
|
289 | + function OutsideMarginExpectation($value, $margin, $message = '%s') { |
|
290 | + $this->WithinMarginExpectation($value, $margin, $message); |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Tests the expectation. True if it matches the |
|
295 | + * held value. |
|
296 | + * @param mixed $compare Comparison value. |
|
297 | + * @return boolean True if correct. |
|
298 | + * @access public |
|
299 | + */ |
|
300 | + function test($compare) { |
|
301 | + return ! parent::test($compare); |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Returns a human readable test message. |
|
306 | + * @param mixed $compare Comparison value. |
|
307 | + * @return string Description of success |
|
308 | + * or failure. |
|
309 | + * @access public |
|
310 | + */ |
|
311 | + function testMessage($compare) { |
|
312 | + if (! $this->test($compare)) { |
|
313 | + return $this->_withinMessage($compare); |
|
314 | + } else { |
|
315 | + return $this->_outsideMessage($compare); |
|
316 | + } |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Test for identity. |
|
322 | + * @package SimpleTest |
|
323 | + * @subpackage UnitTester |
|
324 | + */ |
|
325 | + class IdenticalExpectation extends EqualExpectation { |
|
326 | + |
|
327 | + /** |
|
328 | + * Sets the value to compare against. |
|
329 | + * @param mixed $value Test value to match. |
|
330 | + * @param string $message Customised message on failure. |
|
331 | + * @access public |
|
332 | + */ |
|
333 | + function IdenticalExpectation($value, $message = '%s') { |
|
334 | + $this->EqualExpectation($value, $message); |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Tests the expectation. True if it exactly |
|
339 | + * matches the held value. |
|
340 | + * @param mixed $compare Comparison value. |
|
341 | + * @return boolean True if correct. |
|
342 | + * @access public |
|
343 | + */ |
|
344 | + function test($compare) { |
|
345 | + return SimpleTestCompatibility::isIdentical($this->_getValue(), $compare); |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Returns a human readable test message. |
|
350 | + * @param mixed $compare Comparison value. |
|
351 | + * @return string Description of success |
|
352 | + * or failure. |
|
353 | + * @access public |
|
354 | + */ |
|
355 | + function testMessage($compare) { |
|
356 | + $dumper = $this->_getDumper(); |
|
357 | + if ($this->test($compare)) { |
|
358 | + return "Identical expectation [" . $dumper->describeValue($this->_getValue()) . "]"; |
|
359 | + } else { |
|
360 | + return "Identical expectation [" . $dumper->describeValue($this->_getValue()) . |
|
361 | + "] fails with [" . |
|
362 | + $dumper->describeValue($compare) . "] " . |
|
363 | + $dumper->describeDifference($this->_getValue(), $compare, TYPE_MATTERS); |
|
364 | + } |
|
365 | + } |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Test for non-identity. |
|
370 | + * @package SimpleTest |
|
371 | + * @subpackage UnitTester |
|
372 | + */ |
|
373 | + class NotIdenticalExpectation extends IdenticalExpectation { |
|
374 | + |
|
375 | + /** |
|
376 | + * Sets the value to compare against. |
|
377 | + * @param mixed $value Test value to match. |
|
378 | + * @param string $message Customised message on failure. |
|
379 | + * @access public |
|
380 | + */ |
|
381 | + function NotIdenticalExpectation($value, $message = '%s') { |
|
382 | + $this->IdenticalExpectation($value, $message); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Tests the expectation. True if it differs from the |
|
387 | + * held value. |
|
388 | + * @param mixed $compare Comparison value. |
|
389 | + * @return boolean True if correct. |
|
390 | + * @access public |
|
391 | + */ |
|
392 | + function test($compare) { |
|
393 | + return ! parent::test($compare); |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * Returns a human readable test message. |
|
398 | + * @param mixed $compare Comparison value. |
|
399 | + * @return string Description of success |
|
400 | + * or failure. |
|
401 | + * @access public |
|
402 | + */ |
|
403 | + function testMessage($compare) { |
|
404 | + $dumper = $this->_getDumper(); |
|
405 | + if ($this->test($compare)) { |
|
406 | + return "Not identical expectation passes " . |
|
407 | + $dumper->describeDifference($this->_getValue(), $compare, TYPE_MATTERS); |
|
408 | + } else { |
|
409 | + return "Not identical expectation [" . $dumper->describeValue($this->_getValue()) . "] matches"; |
|
410 | + } |
|
411 | + } |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Test for a pattern using Perl regex rules. |
|
416 | + * @package SimpleTest |
|
417 | + * @subpackage UnitTester |
|
418 | + */ |
|
419 | + class PatternExpectation extends SimpleExpectation { |
|
420 | + protected $_pattern; |
|
421 | + |
|
422 | + /** |
|
423 | + * Sets the value to compare against. |
|
424 | + * @param string $pattern Pattern to search for. |
|
425 | + * @param string $message Customised message on failure. |
|
426 | + * @access public |
|
427 | + */ |
|
428 | + function PatternExpectation($pattern, $message = '%s') { |
|
429 | + $this->SimpleExpectation($message); |
|
430 | + $this->_pattern = $pattern; |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * Accessor for the pattern. |
|
435 | + * @return string Perl regex as string. |
|
436 | + * @access protected |
|
437 | + */ |
|
438 | + function _getPattern() { |
|
439 | + return $this->_pattern; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Tests the expectation. True if the Perl regex |
|
444 | + * matches the comparison value. |
|
445 | + * @param string $compare Comparison value. |
|
446 | + * @return boolean True if correct. |
|
447 | + * @access public |
|
448 | + */ |
|
449 | + function test($compare) { |
|
450 | + return (boolean)preg_match($this->_getPattern(), $compare); |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Returns a human readable test message. |
|
455 | + * @param mixed $compare Comparison value. |
|
456 | + * @return string Description of success |
|
457 | + * or failure. |
|
458 | + * @access public |
|
459 | + */ |
|
460 | + function testMessage($compare) { |
|
461 | + if ($this->test($compare)) { |
|
462 | + return $this->_describePatternMatch($this->_getPattern(), $compare); |
|
463 | + } else { |
|
464 | + $dumper = $this->_getDumper(); |
|
465 | + return "Pattern [" . $this->_getPattern() . |
|
466 | + "] not detected in [" . |
|
467 | + $dumper->describeValue($compare) . "]"; |
|
468 | + } |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * Describes a pattern match including the string |
|
473 | + * found and it's position. |
|
474 | + * @package SimpleTest |
|
475 | + * @subpackage UnitTester |
|
476 | + * @param string $pattern Regex to match against. |
|
477 | + * @param string $subject Subject to search. |
|
478 | + * @access protected |
|
479 | + */ |
|
480 | + function _describePatternMatch($pattern, $subject) { |
|
481 | + preg_match($pattern, $subject, $matches); |
|
482 | + $position = strpos($subject, $matches[0]); |
|
483 | + $dumper = $this->_getDumper(); |
|
484 | + return "Pattern [$pattern] detected at character [$position] in [" . |
|
485 | + $dumper->describeValue($subject) . "] as [" . |
|
486 | + $matches[0] . "] in region [" . |
|
487 | + $dumper->clipString($subject, 100, $position) . "]"; |
|
488 | + } |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * @deprecated |
|
493 | + */ |
|
494 | + class WantedPatternExpectation extends PatternExpectation { |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * Fail if a pattern is detected within the |
|
499 | + * comparison. |
|
500 | + * @package SimpleTest |
|
501 | + * @subpackage UnitTester |
|
502 | + */ |
|
503 | + class NoPatternExpectation extends PatternExpectation { |
|
504 | + |
|
505 | + /** |
|
506 | + * Sets the reject pattern |
|
507 | + * @param string $pattern Pattern to search for. |
|
508 | + * @param string $message Customised message on failure. |
|
509 | + * @access public |
|
510 | + */ |
|
511 | + function NoPatternExpectation($pattern, $message = '%s') { |
|
512 | + $this->PatternExpectation($pattern, $message); |
|
513 | + } |
|
514 | + |
|
515 | + /** |
|
516 | + * Tests the expectation. False if the Perl regex |
|
517 | + * matches the comparison value. |
|
518 | + * @param string $compare Comparison value. |
|
519 | + * @return boolean True if correct. |
|
520 | + * @access public |
|
521 | + */ |
|
522 | + function test($compare) { |
|
523 | + return ! parent::test($compare); |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Returns a human readable test message. |
|
528 | + * @param string $compare Comparison value. |
|
529 | + * @return string Description of success |
|
530 | + * or failure. |
|
531 | + * @access public |
|
532 | + */ |
|
533 | + function testMessage($compare) { |
|
534 | + if ($this->test($compare)) { |
|
535 | + $dumper = $this->_getDumper(); |
|
536 | + return "Pattern [" . $this->_getPattern() . |
|
537 | + "] not detected in [" . |
|
538 | + $dumper->describeValue($compare) . "]"; |
|
539 | + } else { |
|
540 | + return $this->_describePatternMatch($this->_getPattern(), $compare); |
|
541 | + } |
|
542 | + } |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * @package SimpleTest |
|
547 | + * @subpackage UnitTester |
|
548 | + * @deprecated |
|
549 | + */ |
|
550 | + class UnwantedPatternExpectation extends NoPatternExpectation { |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Tests either type or class name if it's an object. |
|
555 | + * @package SimpleTest |
|
556 | + * @subpackage UnitTester |
|
557 | + */ |
|
558 | + class IsAExpectation extends SimpleExpectation { |
|
559 | + protected $_type; |
|
560 | + |
|
561 | + /** |
|
562 | + * Sets the type to compare with. |
|
563 | + * @param string $type Type or class name. |
|
564 | + * @param string $message Customised message on failure. |
|
565 | + * @access public |
|
566 | + */ |
|
567 | + function IsAExpectation($type, $message = '%s') { |
|
568 | + $this->SimpleExpectation($message); |
|
569 | + $this->_type = $type; |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Accessor for type to check against. |
|
574 | + * @return string Type or class name. |
|
575 | + * @access protected |
|
576 | + */ |
|
577 | + function _getType() { |
|
578 | + return $this->_type; |
|
579 | + } |
|
580 | + |
|
581 | + /** |
|
582 | + * Tests the expectation. True if the type or |
|
583 | + * class matches the string value. |
|
584 | + * @param string $compare Comparison value. |
|
585 | + * @return boolean True if correct. |
|
586 | + * @access public |
|
587 | + */ |
|
588 | + function test($compare) { |
|
589 | + if (is_object($compare)) { |
|
590 | + return SimpleTestCompatibility::isA($compare, $this->_type); |
|
591 | + } else { |
|
592 | + return (strtolower(gettype($compare)) == $this->_canonicalType($this->_type)); |
|
593 | + } |
|
594 | + } |
|
595 | + |
|
596 | + /** |
|
597 | + * Coerces type name into a gettype() match. |
|
598 | + * @param string $type User type. |
|
599 | + * @return string Simpler type. |
|
600 | + * @access private |
|
601 | + */ |
|
602 | + function _canonicalType($type) { |
|
603 | + $type = strtolower($type); |
|
604 | + $map = array( |
|
605 | + 'bool' => 'boolean', |
|
606 | + 'float' => 'double', |
|
607 | + 'real' => 'double', |
|
608 | + 'int' => 'integer'); |
|
609 | + if (isset($map[$type])) { |
|
610 | + $type = $map[$type]; |
|
611 | + } |
|
612 | + return $type; |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Returns a human readable test message. |
|
617 | + * @param mixed $compare Comparison value. |
|
618 | + * @return string Description of success |
|
619 | + * or failure. |
|
620 | + * @access public |
|
621 | + */ |
|
622 | + function testMessage($compare) { |
|
623 | + $dumper = $this->_getDumper(); |
|
624 | + return "Value [" . $dumper->describeValue($compare) . |
|
625 | + "] should be type [" . $this->_type . "]"; |
|
626 | + } |
|
627 | + } |
|
628 | + |
|
629 | + /** |
|
630 | + * Tests either type or class name if it's an object. |
|
631 | + * Will succeed if the type does not match. |
|
632 | + * @package SimpleTest |
|
633 | + * @subpackage UnitTester |
|
634 | + */ |
|
635 | + class NotAExpectation extends IsAExpectation { |
|
636 | + protected $_type; |
|
637 | + |
|
638 | + /** |
|
639 | + * Sets the type to compare with. |
|
640 | + * @param string $type Type or class name. |
|
641 | + * @param string $message Customised message on failure. |
|
642 | + * @access public |
|
643 | + */ |
|
644 | + function NotAExpectation($type, $message = '%s') { |
|
645 | + $this->IsAExpectation($type, $message); |
|
646 | + } |
|
647 | + |
|
648 | + /** |
|
649 | + * Tests the expectation. False if the type or |
|
650 | + * class matches the string value. |
|
651 | + * @param string $compare Comparison value. |
|
652 | + * @return boolean True if different. |
|
653 | + * @access public |
|
654 | + */ |
|
655 | + function test($compare) { |
|
656 | + return ! parent::test($compare); |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Returns a human readable test message. |
|
661 | + * @param mixed $compare Comparison value. |
|
662 | + * @return string Description of success |
|
663 | + * or failure. |
|
664 | + * @access public |
|
665 | + */ |
|
666 | + function testMessage($compare) { |
|
667 | + $dumper = $this->_getDumper(); |
|
668 | + return "Value [" . $dumper->describeValue($compare) . |
|
669 | + "] should not be type [" . $this->_getType() . "]"; |
|
670 | + } |
|
671 | + } |
|
672 | + |
|
673 | + /** |
|
674 | + * Tests for existance of a method in an object |
|
675 | + * @package SimpleTest |
|
676 | + * @subpackage UnitTester |
|
677 | + */ |
|
678 | + class MethodExistsExpectation extends SimpleExpectation { |
|
679 | + protected $_method; |
|
680 | + |
|
681 | + /** |
|
682 | + * Sets the value to compare against. |
|
683 | + * @param string $method Method to check. |
|
684 | + * @param string $message Customised message on failure. |
|
685 | + * @access public |
|
686 | + * @return void |
|
687 | + */ |
|
688 | + function MethodExistsExpectation($method, $message = '%s') { |
|
689 | + $this->SimpleExpectation($message); |
|
690 | + $this->_method = $method; |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * Tests the expectation. True if the method exists in the test object. |
|
695 | + * @param string $compare Comparison method name. |
|
696 | + * @return boolean True if correct. |
|
697 | + * @access public |
|
698 | + */ |
|
699 | + function test($compare) { |
|
700 | + return (boolean)(is_object($compare) && method_exists($compare, $this->_method)); |
|
701 | + } |
|
702 | + |
|
703 | + /** |
|
704 | + * Returns a human readable test message. |
|
705 | + * @param mixed $compare Comparison value. |
|
706 | + * @return string Description of success |
|
707 | + * or failure. |
|
708 | + * @access public |
|
709 | + */ |
|
710 | + function testMessage($compare) { |
|
711 | + $dumper = $this->_getDumper(); |
|
712 | + if (! is_object($compare)) { |
|
713 | + return 'No method on non-object [' . $dumper->describeValue($compare) . ']'; |
|
714 | + } |
|
715 | + $method = $this->_method; |
|
716 | + return "Object [" . $dumper->describeValue($compare) . |
|
717 | + "] should contain method [$method]"; |
|
718 | + } |
|
719 | + } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @access public |
174 | 174 | */ |
175 | 175 | function test($compare) { |
176 | - return ! parent::test($compare); |
|
176 | + return !parent::test($compare); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * @access public |
299 | 299 | */ |
300 | 300 | function test($compare) { |
301 | - return ! parent::test($compare); |
|
301 | + return !parent::test($compare); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * @access public |
310 | 310 | */ |
311 | 311 | function testMessage($compare) { |
312 | - if (! $this->test($compare)) { |
|
312 | + if (!$this->test($compare)) { |
|
313 | 313 | return $this->_withinMessage($compare); |
314 | 314 | } else { |
315 | 315 | return $this->_outsideMessage($compare); |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | * @access public |
391 | 391 | */ |
392 | 392 | function test($compare) { |
393 | - return ! parent::test($compare); |
|
393 | + return !parent::test($compare); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | * @access public |
448 | 448 | */ |
449 | 449 | function test($compare) { |
450 | - return (boolean)preg_match($this->_getPattern(), $compare); |
|
450 | + return (boolean) preg_match($this->_getPattern(), $compare); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | * @access public |
521 | 521 | */ |
522 | 522 | function test($compare) { |
523 | - return ! parent::test($compare); |
|
523 | + return !parent::test($compare); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | * @access public |
654 | 654 | */ |
655 | 655 | function test($compare) { |
656 | - return ! parent::test($compare); |
|
656 | + return !parent::test($compare); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | * @access public |
698 | 698 | */ |
699 | 699 | function test($compare) { |
700 | - return (boolean)(is_object($compare) && method_exists($compare, $this->_method)); |
|
700 | + return (boolean) (is_object($compare) && method_exists($compare, $this->_method)); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | /** |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | */ |
710 | 710 | function testMessage($compare) { |
711 | 711 | $dumper = $this->_getDumper(); |
712 | - if (! is_object($compare)) { |
|
712 | + if (!is_object($compare)) { |
|
713 | 713 | return 'No method on non-object [' . $dumper->describeValue($compare) . ']'; |
714 | 714 | } |
715 | 715 | $method = $this->_method; |
@@ -342,7 +342,7 @@ |
||
342 | 342 | * Simply submits the form without the submit button |
343 | 343 | * value. Used when there is only one button or it |
344 | 344 | * is unimportant. |
345 | - * @return hash Submitted values. |
|
345 | + * @return SimpleEncoding Submitted values. |
|
346 | 346 | * @access public |
347 | 347 | */ |
348 | 348 | function submit() { |
@@ -1,351 +1,351 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * Base include file for SimpleTest. |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage WebTester |
|
6 | - * @version $Id: form.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | - */ |
|
2 | + /** |
|
3 | + * Base include file for SimpleTest. |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage WebTester |
|
6 | + * @version $Id: form.php 1398 2006-09-08 19:31:03Z xue $ |
|
7 | + */ |
|
8 | 8 | |
9 | - /**#@+ |
|
9 | + /**#@+ |
|
10 | 10 | * include SimpleTest files |
11 | 11 | */ |
12 | - require_once(dirname(__FILE__) . '/tag.php'); |
|
13 | - require_once(dirname(__FILE__) . '/encoding.php'); |
|
14 | - require_once(dirname(__FILE__) . '/selector.php'); |
|
15 | - /**#@-*/ |
|
12 | + require_once(dirname(__FILE__) . '/tag.php'); |
|
13 | + require_once(dirname(__FILE__) . '/encoding.php'); |
|
14 | + require_once(dirname(__FILE__) . '/selector.php'); |
|
15 | + /**#@-*/ |
|
16 | 16 | |
17 | - /** |
|
18 | - * Form tag class to hold widget values. |
|
17 | + /** |
|
18 | + * Form tag class to hold widget values. |
|
19 | 19 | * @package SimpleTest |
20 | 20 | * @subpackage WebTester |
21 | - */ |
|
22 | - class SimpleForm { |
|
23 | - protected $_method; |
|
24 | - protected $_action; |
|
25 | - protected $_encoding; |
|
26 | - protected $_default_target; |
|
27 | - protected $_id; |
|
28 | - protected $_buttons; |
|
29 | - protected $_images; |
|
30 | - protected $_widgets; |
|
31 | - protected $_radios; |
|
32 | - protected $_checkboxes; |
|
21 | + */ |
|
22 | + class SimpleForm { |
|
23 | + protected $_method; |
|
24 | + protected $_action; |
|
25 | + protected $_encoding; |
|
26 | + protected $_default_target; |
|
27 | + protected $_id; |
|
28 | + protected $_buttons; |
|
29 | + protected $_images; |
|
30 | + protected $_widgets; |
|
31 | + protected $_radios; |
|
32 | + protected $_checkboxes; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Starts with no held controls/widgets. |
|
36 | - * @param SimpleTag $tag Form tag to read. |
|
37 | - * @param SimpleUrl $url Location of holding page. |
|
38 | - */ |
|
39 | - function SimpleForm($tag, $url) { |
|
40 | - $this->_method = $tag->getAttribute('method'); |
|
41 | - $this->_action = $this->_createAction($tag->getAttribute('action'), $url); |
|
42 | - $this->_encoding = $this->_setEncodingClass($tag); |
|
43 | - $this->_default_target = false; |
|
44 | - $this->_id = $tag->getAttribute('id'); |
|
45 | - $this->_buttons = array(); |
|
46 | - $this->_images = array(); |
|
47 | - $this->_widgets = array(); |
|
48 | - $this->_radios = array(); |
|
49 | - $this->_checkboxes = array(); |
|
50 | - } |
|
34 | + /** |
|
35 | + * Starts with no held controls/widgets. |
|
36 | + * @param SimpleTag $tag Form tag to read. |
|
37 | + * @param SimpleUrl $url Location of holding page. |
|
38 | + */ |
|
39 | + function SimpleForm($tag, $url) { |
|
40 | + $this->_method = $tag->getAttribute('method'); |
|
41 | + $this->_action = $this->_createAction($tag->getAttribute('action'), $url); |
|
42 | + $this->_encoding = $this->_setEncodingClass($tag); |
|
43 | + $this->_default_target = false; |
|
44 | + $this->_id = $tag->getAttribute('id'); |
|
45 | + $this->_buttons = array(); |
|
46 | + $this->_images = array(); |
|
47 | + $this->_widgets = array(); |
|
48 | + $this->_radios = array(); |
|
49 | + $this->_checkboxes = array(); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Creates the request packet to be sent by the form. |
|
54 | - * @param SimpleTag $tag Form tag to read. |
|
55 | - * @return string Packet class. |
|
56 | - * @access private |
|
57 | - */ |
|
58 | - function _setEncodingClass($tag) { |
|
59 | - if (strtolower($tag->getAttribute('method')) == 'post') { |
|
60 | - if (strtolower($tag->getAttribute('enctype')) == 'multipart/form-data') { |
|
61 | - return 'SimpleMultipartEncoding'; |
|
62 | - } |
|
63 | - return 'SimplePostEncoding'; |
|
64 | - } |
|
65 | - return 'SimpleGetEncoding'; |
|
66 | - } |
|
52 | + /** |
|
53 | + * Creates the request packet to be sent by the form. |
|
54 | + * @param SimpleTag $tag Form tag to read. |
|
55 | + * @return string Packet class. |
|
56 | + * @access private |
|
57 | + */ |
|
58 | + function _setEncodingClass($tag) { |
|
59 | + if (strtolower($tag->getAttribute('method')) == 'post') { |
|
60 | + if (strtolower($tag->getAttribute('enctype')) == 'multipart/form-data') { |
|
61 | + return 'SimpleMultipartEncoding'; |
|
62 | + } |
|
63 | + return 'SimplePostEncoding'; |
|
64 | + } |
|
65 | + return 'SimpleGetEncoding'; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Sets the frame target within a frameset. |
|
70 | - * @param string $frame Name of frame. |
|
71 | - * @access public |
|
72 | - */ |
|
73 | - function setDefaultTarget($frame) { |
|
74 | - $this->_default_target = $frame; |
|
75 | - } |
|
68 | + /** |
|
69 | + * Sets the frame target within a frameset. |
|
70 | + * @param string $frame Name of frame. |
|
71 | + * @access public |
|
72 | + */ |
|
73 | + function setDefaultTarget($frame) { |
|
74 | + $this->_default_target = $frame; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Accessor for method of form submission. |
|
79 | - * @return string Either get or post. |
|
80 | - * @access public |
|
81 | - */ |
|
82 | - function getMethod() { |
|
83 | - return ($this->_method ? strtolower($this->_method) : 'get'); |
|
84 | - } |
|
77 | + /** |
|
78 | + * Accessor for method of form submission. |
|
79 | + * @return string Either get or post. |
|
80 | + * @access public |
|
81 | + */ |
|
82 | + function getMethod() { |
|
83 | + return ($this->_method ? strtolower($this->_method) : 'get'); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Combined action attribute with current location |
|
88 | - * to get an absolute form target. |
|
89 | - * @param string $action Action attribute from form tag. |
|
90 | - * @param SimpleUrl $base Page location. |
|
91 | - * @return SimpleUrl Absolute form target. |
|
92 | - */ |
|
93 | - function _createAction($action, $base) { |
|
94 | - if (($action === '') || ($action === false)) { |
|
95 | - return $base; |
|
96 | - } |
|
97 | - $url = new SimpleUrl($action); |
|
98 | - return $url->makeAbsolute($base); |
|
99 | - } |
|
86 | + /** |
|
87 | + * Combined action attribute with current location |
|
88 | + * to get an absolute form target. |
|
89 | + * @param string $action Action attribute from form tag. |
|
90 | + * @param SimpleUrl $base Page location. |
|
91 | + * @return SimpleUrl Absolute form target. |
|
92 | + */ |
|
93 | + function _createAction($action, $base) { |
|
94 | + if (($action === '') || ($action === false)) { |
|
95 | + return $base; |
|
96 | + } |
|
97 | + $url = new SimpleUrl($action); |
|
98 | + return $url->makeAbsolute($base); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Absolute URL of the target. |
|
103 | - * @return SimpleUrl URL target. |
|
104 | - * @access public |
|
105 | - */ |
|
106 | - function getAction() { |
|
107 | - $url = $this->_action; |
|
108 | - if ($this->_default_target && ! $url->getTarget()) { |
|
109 | - $url->setTarget($this->_default_target); |
|
110 | - } |
|
111 | - return $url; |
|
112 | - } |
|
101 | + /** |
|
102 | + * Absolute URL of the target. |
|
103 | + * @return SimpleUrl URL target. |
|
104 | + * @access public |
|
105 | + */ |
|
106 | + function getAction() { |
|
107 | + $url = $this->_action; |
|
108 | + if ($this->_default_target && ! $url->getTarget()) { |
|
109 | + $url->setTarget($this->_default_target); |
|
110 | + } |
|
111 | + return $url; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Creates the encoding for the current values in the |
|
116 | - * form. |
|
117 | - * @return SimpleFormEncoding Request to submit. |
|
118 | - * @access private |
|
119 | - */ |
|
120 | - function _encode() { |
|
121 | - $class = $this->_encoding; |
|
122 | - $encoding = new $class(); |
|
123 | - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { |
|
124 | - $this->_widgets[$i]->write($encoding); |
|
125 | - } |
|
126 | - return $encoding; |
|
127 | - } |
|
114 | + /** |
|
115 | + * Creates the encoding for the current values in the |
|
116 | + * form. |
|
117 | + * @return SimpleFormEncoding Request to submit. |
|
118 | + * @access private |
|
119 | + */ |
|
120 | + function _encode() { |
|
121 | + $class = $this->_encoding; |
|
122 | + $encoding = new $class(); |
|
123 | + for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { |
|
124 | + $this->_widgets[$i]->write($encoding); |
|
125 | + } |
|
126 | + return $encoding; |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * ID field of form for unique identification. |
|
131 | - * @return string Unique tag ID. |
|
132 | - * @access public |
|
133 | - */ |
|
134 | - function getId() { |
|
135 | - return $this->_id; |
|
136 | - } |
|
129 | + /** |
|
130 | + * ID field of form for unique identification. |
|
131 | + * @return string Unique tag ID. |
|
132 | + * @access public |
|
133 | + */ |
|
134 | + function getId() { |
|
135 | + return $this->_id; |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * Adds a tag contents to the form. |
|
140 | - * @param SimpleWidget $tag Input tag to add. |
|
141 | - * @access public |
|
142 | - */ |
|
143 | - function addWidget($tag) { |
|
144 | - if (strtolower($tag->getAttribute('type')) == 'submit') { |
|
145 | - $this->_buttons[] = $tag; |
|
146 | - } elseif (strtolower($tag->getAttribute('type')) == 'image') { |
|
147 | - $this->_images[] = $tag; |
|
148 | - } elseif ($tag->getName()) { |
|
149 | - $this->_setWidget($tag); |
|
150 | - } |
|
151 | - } |
|
138 | + /** |
|
139 | + * Adds a tag contents to the form. |
|
140 | + * @param SimpleWidget $tag Input tag to add. |
|
141 | + * @access public |
|
142 | + */ |
|
143 | + function addWidget($tag) { |
|
144 | + if (strtolower($tag->getAttribute('type')) == 'submit') { |
|
145 | + $this->_buttons[] = $tag; |
|
146 | + } elseif (strtolower($tag->getAttribute('type')) == 'image') { |
|
147 | + $this->_images[] = $tag; |
|
148 | + } elseif ($tag->getName()) { |
|
149 | + $this->_setWidget($tag); |
|
150 | + } |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * Sets the widget into the form, grouping radio |
|
155 | - * buttons if any. |
|
156 | - * @param SimpleWidget $tag Incoming form control. |
|
157 | - * @access private |
|
158 | - */ |
|
159 | - function _setWidget($tag) { |
|
160 | - if (strtolower($tag->getAttribute('type')) == 'radio') { |
|
161 | - $this->_addRadioButton($tag); |
|
162 | - } elseif (strtolower($tag->getAttribute('type')) == 'checkbox') { |
|
163 | - $this->_addCheckbox($tag); |
|
164 | - } else { |
|
165 | - $this->_widgets[] = $tag; |
|
166 | - } |
|
167 | - } |
|
153 | + /** |
|
154 | + * Sets the widget into the form, grouping radio |
|
155 | + * buttons if any. |
|
156 | + * @param SimpleWidget $tag Incoming form control. |
|
157 | + * @access private |
|
158 | + */ |
|
159 | + function _setWidget($tag) { |
|
160 | + if (strtolower($tag->getAttribute('type')) == 'radio') { |
|
161 | + $this->_addRadioButton($tag); |
|
162 | + } elseif (strtolower($tag->getAttribute('type')) == 'checkbox') { |
|
163 | + $this->_addCheckbox($tag); |
|
164 | + } else { |
|
165 | + $this->_widgets[] = $tag; |
|
166 | + } |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Adds a radio button, building a group if necessary. |
|
171 | - * @param SimpleRadioButtonTag $tag Incoming form control. |
|
172 | - * @access private |
|
173 | - */ |
|
174 | - function _addRadioButton($tag) { |
|
175 | - if (! isset($this->_radios[$tag->getName()])) { |
|
176 | - $this->_widgets[] = new SimpleRadioGroup(); |
|
177 | - $this->_radios[$tag->getName()] = count($this->_widgets) - 1; |
|
178 | - } |
|
179 | - $this->_widgets[$this->_radios[$tag->getName()]]->addWidget($tag); |
|
180 | - } |
|
169 | + /** |
|
170 | + * Adds a radio button, building a group if necessary. |
|
171 | + * @param SimpleRadioButtonTag $tag Incoming form control. |
|
172 | + * @access private |
|
173 | + */ |
|
174 | + function _addRadioButton($tag) { |
|
175 | + if (! isset($this->_radios[$tag->getName()])) { |
|
176 | + $this->_widgets[] = new SimpleRadioGroup(); |
|
177 | + $this->_radios[$tag->getName()] = count($this->_widgets) - 1; |
|
178 | + } |
|
179 | + $this->_widgets[$this->_radios[$tag->getName()]]->addWidget($tag); |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * Adds a checkbox, making it a group on a repeated name. |
|
184 | - * @param SimpleCheckboxTag $tag Incoming form control. |
|
185 | - * @access private |
|
186 | - */ |
|
187 | - function _addCheckbox($tag) { |
|
188 | - if (! isset($this->_checkboxes[$tag->getName()])) { |
|
189 | - $this->_widgets[] = $tag; |
|
190 | - $this->_checkboxes[$tag->getName()] = count($this->_widgets) - 1; |
|
191 | - } else { |
|
192 | - $index = $this->_checkboxes[$tag->getName()]; |
|
193 | - if (! SimpleTestCompatibility::isA($this->_widgets[$index], 'SimpleCheckboxGroup')) { |
|
194 | - $previous = $this->_widgets[$index]; |
|
195 | - $this->_widgets[$index] = new SimpleCheckboxGroup(); |
|
196 | - $this->_widgets[$index]->addWidget($previous); |
|
197 | - } |
|
198 | - $this->_widgets[$index]->addWidget($tag); |
|
199 | - } |
|
200 | - } |
|
182 | + /** |
|
183 | + * Adds a checkbox, making it a group on a repeated name. |
|
184 | + * @param SimpleCheckboxTag $tag Incoming form control. |
|
185 | + * @access private |
|
186 | + */ |
|
187 | + function _addCheckbox($tag) { |
|
188 | + if (! isset($this->_checkboxes[$tag->getName()])) { |
|
189 | + $this->_widgets[] = $tag; |
|
190 | + $this->_checkboxes[$tag->getName()] = count($this->_widgets) - 1; |
|
191 | + } else { |
|
192 | + $index = $this->_checkboxes[$tag->getName()]; |
|
193 | + if (! SimpleTestCompatibility::isA($this->_widgets[$index], 'SimpleCheckboxGroup')) { |
|
194 | + $previous = $this->_widgets[$index]; |
|
195 | + $this->_widgets[$index] = new SimpleCheckboxGroup(); |
|
196 | + $this->_widgets[$index]->addWidget($previous); |
|
197 | + } |
|
198 | + $this->_widgets[$index]->addWidget($tag); |
|
199 | + } |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Extracts current value from form. |
|
204 | - * @param SimpleSelector $selector Criteria to apply. |
|
205 | - * @return string/array Value(s) as string or null |
|
206 | - * if not set. |
|
207 | - * @access public |
|
208 | - */ |
|
209 | - function getValue($selector) { |
|
210 | - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { |
|
211 | - if ($selector->isMatch($this->_widgets[$i])) { |
|
212 | - return $this->_widgets[$i]->getValue(); |
|
213 | - } |
|
214 | - } |
|
215 | - foreach ($this->_buttons as $button) { |
|
216 | - if ($selector->isMatch($button)) { |
|
217 | - return $button->getValue(); |
|
218 | - } |
|
219 | - } |
|
220 | - return null; |
|
221 | - } |
|
202 | + /** |
|
203 | + * Extracts current value from form. |
|
204 | + * @param SimpleSelector $selector Criteria to apply. |
|
205 | + * @return string/array Value(s) as string or null |
|
206 | + * if not set. |
|
207 | + * @access public |
|
208 | + */ |
|
209 | + function getValue($selector) { |
|
210 | + for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { |
|
211 | + if ($selector->isMatch($this->_widgets[$i])) { |
|
212 | + return $this->_widgets[$i]->getValue(); |
|
213 | + } |
|
214 | + } |
|
215 | + foreach ($this->_buttons as $button) { |
|
216 | + if ($selector->isMatch($button)) { |
|
217 | + return $button->getValue(); |
|
218 | + } |
|
219 | + } |
|
220 | + return null; |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * Sets a widget value within the form. |
|
225 | - * @param SimpleSelector $selector Criteria to apply. |
|
226 | - * @param string $value Value to input into the widget. |
|
227 | - * @return boolean True if value is legal, false |
|
228 | - * otherwise. If the field is not |
|
229 | - * present, nothing will be set. |
|
230 | - * @access public |
|
231 | - */ |
|
232 | - function setField($selector, $value) { |
|
233 | - $success = false; |
|
234 | - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { |
|
235 | - if ($selector->isMatch($this->_widgets[$i])) { |
|
236 | - if ($this->_widgets[$i]->setValue($value)) { |
|
237 | - $success = true; |
|
238 | - } |
|
239 | - } |
|
240 | - } |
|
241 | - return $success; |
|
242 | - } |
|
223 | + /** |
|
224 | + * Sets a widget value within the form. |
|
225 | + * @param SimpleSelector $selector Criteria to apply. |
|
226 | + * @param string $value Value to input into the widget. |
|
227 | + * @return boolean True if value is legal, false |
|
228 | + * otherwise. If the field is not |
|
229 | + * present, nothing will be set. |
|
230 | + * @access public |
|
231 | + */ |
|
232 | + function setField($selector, $value) { |
|
233 | + $success = false; |
|
234 | + for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { |
|
235 | + if ($selector->isMatch($this->_widgets[$i])) { |
|
236 | + if ($this->_widgets[$i]->setValue($value)) { |
|
237 | + $success = true; |
|
238 | + } |
|
239 | + } |
|
240 | + } |
|
241 | + return $success; |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * Used by the page object to set widgets labels to |
|
246 | - * external label tags. |
|
247 | - * @param SimpleSelector $selector Criteria to apply. |
|
248 | - * @access public |
|
249 | - */ |
|
250 | - function attachLabelBySelector($selector, $label) { |
|
251 | - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { |
|
252 | - if ($selector->isMatch($this->_widgets[$i])) { |
|
253 | - if (method_exists($this->_widgets[$i], 'setLabel')) { |
|
254 | - $this->_widgets[$i]->setLabel($label); |
|
255 | - return; |
|
256 | - } |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
244 | + /** |
|
245 | + * Used by the page object to set widgets labels to |
|
246 | + * external label tags. |
|
247 | + * @param SimpleSelector $selector Criteria to apply. |
|
248 | + * @access public |
|
249 | + */ |
|
250 | + function attachLabelBySelector($selector, $label) { |
|
251 | + for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { |
|
252 | + if ($selector->isMatch($this->_widgets[$i])) { |
|
253 | + if (method_exists($this->_widgets[$i], 'setLabel')) { |
|
254 | + $this->_widgets[$i]->setLabel($label); |
|
255 | + return; |
|
256 | + } |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | - /** |
|
262 | - * Test to see if a form has a submit button. |
|
263 | - * @param SimpleSelector $selector Criteria to apply. |
|
264 | - * @return boolean True if present. |
|
265 | - * @access public |
|
266 | - */ |
|
267 | - function hasSubmit($selector) { |
|
268 | - foreach ($this->_buttons as $button) { |
|
269 | - if ($selector->isMatch($button)) { |
|
270 | - return true; |
|
271 | - } |
|
272 | - } |
|
273 | - return false; |
|
274 | - } |
|
261 | + /** |
|
262 | + * Test to see if a form has a submit button. |
|
263 | + * @param SimpleSelector $selector Criteria to apply. |
|
264 | + * @return boolean True if present. |
|
265 | + * @access public |
|
266 | + */ |
|
267 | + function hasSubmit($selector) { |
|
268 | + foreach ($this->_buttons as $button) { |
|
269 | + if ($selector->isMatch($button)) { |
|
270 | + return true; |
|
271 | + } |
|
272 | + } |
|
273 | + return false; |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * Test to see if a form has an image control. |
|
278 | - * @param SimpleSelector $selector Criteria to apply. |
|
279 | - * @return boolean True if present. |
|
280 | - * @access public |
|
281 | - */ |
|
282 | - function hasImage($selector) { |
|
283 | - foreach ($this->_images as $image) { |
|
284 | - if ($selector->isMatch($image)) { |
|
285 | - return true; |
|
286 | - } |
|
287 | - } |
|
288 | - return false; |
|
289 | - } |
|
276 | + /** |
|
277 | + * Test to see if a form has an image control. |
|
278 | + * @param SimpleSelector $selector Criteria to apply. |
|
279 | + * @return boolean True if present. |
|
280 | + * @access public |
|
281 | + */ |
|
282 | + function hasImage($selector) { |
|
283 | + foreach ($this->_images as $image) { |
|
284 | + if ($selector->isMatch($image)) { |
|
285 | + return true; |
|
286 | + } |
|
287 | + } |
|
288 | + return false; |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Gets the submit values for a selected button. |
|
293 | - * @param SimpleSelector $selector Criteria to apply. |
|
294 | - * @param hash $additional Additional data for the form. |
|
295 | - * @return SimpleEncoding Submitted values or false |
|
296 | - * if there is no such button |
|
297 | - * in the form. |
|
298 | - * @access public |
|
299 | - */ |
|
300 | - function submitButton($selector, $additional = false) { |
|
301 | - $additional = $additional ? $additional : array(); |
|
302 | - foreach ($this->_buttons as $button) { |
|
303 | - if ($selector->isMatch($button)) { |
|
304 | - $encoding = $this->_encode(); |
|
305 | - $button->write($encoding); |
|
306 | - if ($additional) { |
|
307 | - $encoding->merge($additional); |
|
308 | - } |
|
309 | - return $encoding; |
|
310 | - } |
|
311 | - } |
|
312 | - return false; |
|
313 | - } |
|
291 | + /** |
|
292 | + * Gets the submit values for a selected button. |
|
293 | + * @param SimpleSelector $selector Criteria to apply. |
|
294 | + * @param hash $additional Additional data for the form. |
|
295 | + * @return SimpleEncoding Submitted values or false |
|
296 | + * if there is no such button |
|
297 | + * in the form. |
|
298 | + * @access public |
|
299 | + */ |
|
300 | + function submitButton($selector, $additional = false) { |
|
301 | + $additional = $additional ? $additional : array(); |
|
302 | + foreach ($this->_buttons as $button) { |
|
303 | + if ($selector->isMatch($button)) { |
|
304 | + $encoding = $this->_encode(); |
|
305 | + $button->write($encoding); |
|
306 | + if ($additional) { |
|
307 | + $encoding->merge($additional); |
|
308 | + } |
|
309 | + return $encoding; |
|
310 | + } |
|
311 | + } |
|
312 | + return false; |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
316 | - * Gets the submit values for an image. |
|
317 | - * @param SimpleSelector $selector Criteria to apply. |
|
318 | - * @param integer $x X-coordinate of click. |
|
319 | - * @param integer $y Y-coordinate of click. |
|
320 | - * @param hash $additional Additional data for the form. |
|
321 | - * @return SimpleEncoding Submitted values or false |
|
322 | - * if there is no such button in the |
|
323 | - * form. |
|
324 | - * @access public |
|
325 | - */ |
|
326 | - function submitImage($selector, $x, $y, $additional = false) { |
|
327 | - $additional = $additional ? $additional : array(); |
|
328 | - foreach ($this->_images as $image) { |
|
329 | - if ($selector->isMatch($image)) { |
|
330 | - $encoding = $this->_encode(); |
|
331 | - $image->write($encoding, $x, $y); |
|
332 | - if ($additional) { |
|
333 | - $encoding->merge($additional); |
|
334 | - } |
|
335 | - return $encoding; |
|
336 | - } |
|
337 | - } |
|
338 | - return false; |
|
339 | - } |
|
315 | + /** |
|
316 | + * Gets the submit values for an image. |
|
317 | + * @param SimpleSelector $selector Criteria to apply. |
|
318 | + * @param integer $x X-coordinate of click. |
|
319 | + * @param integer $y Y-coordinate of click. |
|
320 | + * @param hash $additional Additional data for the form. |
|
321 | + * @return SimpleEncoding Submitted values or false |
|
322 | + * if there is no such button in the |
|
323 | + * form. |
|
324 | + * @access public |
|
325 | + */ |
|
326 | + function submitImage($selector, $x, $y, $additional = false) { |
|
327 | + $additional = $additional ? $additional : array(); |
|
328 | + foreach ($this->_images as $image) { |
|
329 | + if ($selector->isMatch($image)) { |
|
330 | + $encoding = $this->_encode(); |
|
331 | + $image->write($encoding, $x, $y); |
|
332 | + if ($additional) { |
|
333 | + $encoding->merge($additional); |
|
334 | + } |
|
335 | + return $encoding; |
|
336 | + } |
|
337 | + } |
|
338 | + return false; |
|
339 | + } |
|
340 | 340 | |
341 | - /** |
|
342 | - * Simply submits the form without the submit button |
|
343 | - * value. Used when there is only one button or it |
|
344 | - * is unimportant. |
|
345 | - * @return hash Submitted values. |
|
346 | - * @access public |
|
347 | - */ |
|
348 | - function submit() { |
|
349 | - return $this->_encode(); |
|
350 | - } |
|
351 | - } |
|
341 | + /** |
|
342 | + * Simply submits the form without the submit button |
|
343 | + * value. Used when there is only one button or it |
|
344 | + * is unimportant. |
|
345 | + * @return hash Submitted values. |
|
346 | + * @access public |
|
347 | + */ |
|
348 | + function submit() { |
|
349 | + return $this->_encode(); |
|
350 | + } |
|
351 | + } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | function getAction() { |
107 | 107 | $url = $this->_action; |
108 | - if ($this->_default_target && ! $url->getTarget()) { |
|
108 | + if ($this->_default_target && !$url->getTarget()) { |
|
109 | 109 | $url->setTarget($this->_default_target); |
110 | 110 | } |
111 | 111 | return $url; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @access private |
173 | 173 | */ |
174 | 174 | function _addRadioButton($tag) { |
175 | - if (! isset($this->_radios[$tag->getName()])) { |
|
175 | + if (!isset($this->_radios[$tag->getName()])) { |
|
176 | 176 | $this->_widgets[] = new SimpleRadioGroup(); |
177 | 177 | $this->_radios[$tag->getName()] = count($this->_widgets) - 1; |
178 | 178 | } |
@@ -185,12 +185,12 @@ discard block |
||
185 | 185 | * @access private |
186 | 186 | */ |
187 | 187 | function _addCheckbox($tag) { |
188 | - if (! isset($this->_checkboxes[$tag->getName()])) { |
|
188 | + if (!isset($this->_checkboxes[$tag->getName()])) { |
|
189 | 189 | $this->_widgets[] = $tag; |
190 | 190 | $this->_checkboxes[$tag->getName()] = count($this->_widgets) - 1; |
191 | 191 | } else { |
192 | 192 | $index = $this->_checkboxes[$tag->getName()]; |
193 | - if (! SimpleTestCompatibility::isA($this->_widgets[$index], 'SimpleCheckboxGroup')) { |
|
193 | + if (!SimpleTestCompatibility::isA($this->_widgets[$index], 'SimpleCheckboxGroup')) { |
|
194 | 194 | $previous = $this->_widgets[$index]; |
195 | 195 | $this->_widgets[$index] = new SimpleCheckboxGroup(); |
196 | 196 | $this->_widgets[$index]->addWidget($previous); |
@@ -554,7 +554,7 @@ |
||
554 | 554 | * available. |
555 | 555 | * @param SimpleSelector $selector Field finder. |
556 | 556 | * @param string $value Value to set field to. |
557 | - * @return boolean True if value is valid. |
|
557 | + * @return boolean|null True if value is valid. |
|
558 | 558 | * @access public |
559 | 559 | */ |
560 | 560 | function setField($selector, $value) { |
@@ -1,587 +1,587 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * Base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage WebTester |
|
6 | - * @version $Id: frames.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: frames.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__) . '/page.php'); |
|
13 | - require_once(dirname(__FILE__) . '/user_agent.php'); |
|
14 | - /**#@-*/ |
|
15 | - |
|
16 | - /** |
|
17 | - * A composite page. Wraps a frameset page and |
|
18 | - * adds subframes. The original page will be |
|
19 | - * mostly ignored. Implements the SimplePage |
|
20 | - * interface so as to be interchangeable. |
|
12 | + require_once(dirname(__FILE__) . '/page.php'); |
|
13 | + require_once(dirname(__FILE__) . '/user_agent.php'); |
|
14 | + /**#@-*/ |
|
15 | + |
|
16 | + /** |
|
17 | + * A composite page. Wraps a frameset page and |
|
18 | + * adds subframes. The original page will be |
|
19 | + * mostly ignored. Implements the SimplePage |
|
20 | + * interface so as to be interchangeable. |
|
21 | 21 | * @package SimpleTest |
22 | 22 | * @subpackage WebTester |
23 | - */ |
|
24 | - class SimpleFrameset { |
|
25 | - protected $_frameset; |
|
26 | - protected $_frames; |
|
27 | - protected $_focus; |
|
28 | - protected $_names; |
|
29 | - |
|
30 | - /** |
|
31 | - * Stashes the frameset page. Will make use of the |
|
32 | - * browser to fetch the sub frames recursively. |
|
33 | - * @param SimplePage $page Frameset page. |
|
34 | - */ |
|
35 | - function SimpleFrameset($page) { |
|
36 | - $this->_frameset = $page; |
|
37 | - $this->_frames = array(); |
|
38 | - $this->_focus = false; |
|
39 | - $this->_names = array(); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Adds a parsed page to the frameset. |
|
44 | - * @param SimplePage $page Frame page. |
|
45 | - * @param string $name Name of frame in frameset. |
|
46 | - * @access public |
|
47 | - */ |
|
48 | - function addFrame($page, $name = false) { |
|
49 | - $this->_frames[] = $page; |
|
50 | - if ($name) { |
|
51 | - $this->_names[$name] = count($this->_frames) - 1; |
|
52 | - } |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Replaces existing frame with another. If the |
|
57 | - * frame is nested, then the call is passed down |
|
58 | - * one level. |
|
59 | - * @param array $path Path of frame in frameset. |
|
60 | - * @param SimplePage $page Frame source. |
|
61 | - * @access public |
|
62 | - */ |
|
63 | - function setFrame($path, $page) { |
|
64 | - $name = array_shift($path); |
|
65 | - if (isset($this->_names[$name])) { |
|
66 | - $index = $this->_names[$name]; |
|
67 | - } else { |
|
68 | - $index = $name - 1; |
|
69 | - } |
|
70 | - if (count($path) == 0) { |
|
71 | - $this->_frames[$index] = $page; |
|
72 | - return; |
|
73 | - } |
|
74 | - $this->_frames[$index]->setFrame($path, $page); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Accessor for current frame focus. Will be |
|
79 | - * false if no frame has focus. Will have the nested |
|
80 | - * frame focus if any. |
|
81 | - * @return array Labels or indexes of nested frames. |
|
82 | - * @access public |
|
83 | - */ |
|
84 | - function getFrameFocus() { |
|
85 | - if ($this->_focus === false) { |
|
86 | - return array(); |
|
87 | - } |
|
88 | - return array_merge( |
|
89 | - array($this->_getPublicNameFromIndex($this->_focus)), |
|
90 | - $this->_frames[$this->_focus]->getFrameFocus()); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Turns an internal array index into the frames list |
|
95 | - * into a public name, or if none, then a one offset |
|
96 | - * index. |
|
97 | - * @param integer $subject Internal index. |
|
98 | - * @return integer/string Public name. |
|
99 | - * @access private |
|
100 | - */ |
|
101 | - function _getPublicNameFromIndex($subject) { |
|
102 | - foreach ($this->_names as $name => $index) { |
|
103 | - if ($subject == $index) { |
|
104 | - return $name; |
|
105 | - } |
|
106 | - } |
|
107 | - return $subject + 1; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Sets the focus by index. The integer index starts from 1. |
|
112 | - * If already focused and the target frame also has frames, |
|
113 | - * then the nested frame will be focused. |
|
114 | - * @param integer $choice Chosen frame. |
|
115 | - * @return boolean True if frame exists. |
|
116 | - * @access public |
|
117 | - */ |
|
118 | - function setFrameFocusByIndex($choice) { |
|
119 | - if (is_integer($this->_focus)) { |
|
120 | - if ($this->_frames[$this->_focus]->hasFrames()) { |
|
121 | - return $this->_frames[$this->_focus]->setFrameFocusByIndex($choice); |
|
122 | - } |
|
123 | - } |
|
124 | - if (($choice < 1) || ($choice > count($this->_frames))) { |
|
125 | - return false; |
|
126 | - } |
|
127 | - $this->_focus = $choice - 1; |
|
128 | - return true; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Sets the focus by name. If already focused and the |
|
133 | - * target frame also has frames, then the nested frame |
|
134 | - * will be focused. |
|
135 | - * @param string $name Chosen frame. |
|
136 | - * @return boolean True if frame exists. |
|
137 | - * @access public |
|
138 | - */ |
|
139 | - function setFrameFocus($name) { |
|
140 | - if (is_integer($this->_focus)) { |
|
141 | - if ($this->_frames[$this->_focus]->hasFrames()) { |
|
142 | - return $this->_frames[$this->_focus]->setFrameFocus($name); |
|
143 | - } |
|
144 | - } |
|
145 | - if (in_array($name, array_keys($this->_names))) { |
|
146 | - $this->_focus = $this->_names[$name]; |
|
147 | - return true; |
|
148 | - } |
|
149 | - return false; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Clears the frame focus. |
|
154 | - * @access public |
|
155 | - */ |
|
156 | - function clearFrameFocus() { |
|
157 | - $this->_focus = false; |
|
158 | - $this->_clearNestedFramesFocus(); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Clears the frame focus for any nested frames. |
|
163 | - * @access private |
|
164 | - */ |
|
165 | - function _clearNestedFramesFocus() { |
|
166 | - for ($i = 0; $i < count($this->_frames); $i++) { |
|
167 | - $this->_frames[$i]->clearFrameFocus(); |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Test for the presence of a frameset. |
|
173 | - * @return boolean Always true. |
|
174 | - * @access public |
|
175 | - */ |
|
176 | - function hasFrames() { |
|
177 | - return true; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Accessor for frames information. |
|
182 | - * @return array/string Recursive hash of frame URL strings. |
|
183 | - * The key is either a numerical |
|
184 | - * index or the name attribute. |
|
185 | - * @access public |
|
186 | - */ |
|
187 | - function getFrames() { |
|
188 | - $report = array(); |
|
189 | - for ($i = 0; $i < count($this->_frames); $i++) { |
|
190 | - $report[$this->_getPublicNameFromIndex($i)] = |
|
191 | - $this->_frames[$i]->getFrames(); |
|
192 | - } |
|
193 | - return $report; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Accessor for raw text of either all the pages or |
|
198 | - * the frame in focus. |
|
199 | - * @return string Raw unparsed content. |
|
200 | - * @access public |
|
201 | - */ |
|
202 | - function getRaw() { |
|
203 | - if (is_integer($this->_focus)) { |
|
204 | - return $this->_frames[$this->_focus]->getRaw(); |
|
205 | - } |
|
206 | - $raw = ''; |
|
207 | - for ($i = 0; $i < count($this->_frames); $i++) { |
|
208 | - $raw .= $this->_frames[$i]->getRaw(); |
|
209 | - } |
|
210 | - return $raw; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Accessor for plain text of either all the pages or |
|
215 | - * the frame in focus. |
|
216 | - * @return string Plain text content. |
|
217 | - * @access public |
|
218 | - */ |
|
219 | - function getText() { |
|
220 | - if (is_integer($this->_focus)) { |
|
221 | - return $this->_frames[$this->_focus]->getText(); |
|
222 | - } |
|
223 | - $raw = ''; |
|
224 | - for ($i = 0; $i < count($this->_frames); $i++) { |
|
225 | - $raw .= ' ' . $this->_frames[$i]->getText(); |
|
226 | - } |
|
227 | - return trim($raw); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Accessor for last error. |
|
232 | - * @return string Error from last response. |
|
233 | - * @access public |
|
234 | - */ |
|
235 | - function getTransportError() { |
|
236 | - if (is_integer($this->_focus)) { |
|
237 | - return $this->_frames[$this->_focus]->getTransportError(); |
|
238 | - } |
|
239 | - return $this->_frameset->getTransportError(); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Request method used to fetch this frame. |
|
244 | - * @return string GET, POST or HEAD. |
|
245 | - * @access public |
|
246 | - */ |
|
247 | - function getMethod() { |
|
248 | - if (is_integer($this->_focus)) { |
|
249 | - return $this->_frames[$this->_focus]->getMethod(); |
|
250 | - } |
|
251 | - return $this->_frameset->getMethod(); |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Original resource name. |
|
256 | - * @return SimpleUrl Current url. |
|
257 | - * @access public |
|
258 | - */ |
|
259 | - function getUrl() { |
|
260 | - if (is_integer($this->_focus)) { |
|
261 | - $url = $this->_frames[$this->_focus]->getUrl(); |
|
262 | - $url->setTarget($this->_getPublicNameFromIndex($this->_focus)); |
|
263 | - } else { |
|
264 | - $url = $this->_frameset->getUrl(); |
|
265 | - } |
|
266 | - return $url; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * Original request data. |
|
271 | - * @return mixed Sent content. |
|
272 | - * @access public |
|
273 | - */ |
|
274 | - function getRequestData() { |
|
275 | - if (is_integer($this->_focus)) { |
|
276 | - return $this->_frames[$this->_focus]->getRequestData(); |
|
277 | - } |
|
278 | - return $this->_frameset->getRequestData(); |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Accessor for current MIME type. |
|
283 | - * @return string MIME type as string; e.g. 'text/html' |
|
284 | - * @access public |
|
285 | - */ |
|
286 | - function getMimeType() { |
|
287 | - if (is_integer($this->_focus)) { |
|
288 | - return $this->_frames[$this->_focus]->getMimeType(); |
|
289 | - } |
|
290 | - return $this->_frameset->getMimeType(); |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Accessor for last response code. |
|
295 | - * @return integer Last HTTP response code received. |
|
296 | - * @access public |
|
297 | - */ |
|
298 | - function getResponseCode() { |
|
299 | - if (is_integer($this->_focus)) { |
|
300 | - return $this->_frames[$this->_focus]->getResponseCode(); |
|
301 | - } |
|
302 | - return $this->_frameset->getResponseCode(); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Accessor for last Authentication type. Only valid |
|
307 | - * straight after a challenge (401). |
|
308 | - * @return string Description of challenge type. |
|
309 | - * @access public |
|
310 | - */ |
|
311 | - function getAuthentication() { |
|
312 | - if (is_integer($this->_focus)) { |
|
313 | - return $this->_frames[$this->_focus]->getAuthentication(); |
|
314 | - } |
|
315 | - return $this->_frameset->getAuthentication(); |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Accessor for last Authentication realm. Only valid |
|
320 | - * straight after a challenge (401). |
|
321 | - * @return string Name of security realm. |
|
322 | - * @access public |
|
323 | - */ |
|
324 | - function getRealm() { |
|
325 | - if (is_integer($this->_focus)) { |
|
326 | - return $this->_frames[$this->_focus]->getRealm(); |
|
327 | - } |
|
328 | - return $this->_frameset->getRealm(); |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Accessor for outgoing header information. |
|
333 | - * @return string Header block. |
|
334 | - * @access public |
|
335 | - */ |
|
336 | - function getRequest() { |
|
337 | - if (is_integer($this->_focus)) { |
|
338 | - return $this->_frames[$this->_focus]->getRequest(); |
|
339 | - } |
|
340 | - return $this->_frameset->getRequest(); |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Accessor for raw header information. |
|
345 | - * @return string Header block. |
|
346 | - * @access public |
|
347 | - */ |
|
348 | - function getHeaders() { |
|
349 | - if (is_integer($this->_focus)) { |
|
350 | - return $this->_frames[$this->_focus]->getHeaders(); |
|
351 | - } |
|
352 | - return $this->_frameset->getHeaders(); |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Accessor for parsed title. |
|
357 | - * @return string Title or false if no title is present. |
|
358 | - * @access public |
|
359 | - */ |
|
360 | - function getTitle() { |
|
361 | - return $this->_frameset->getTitle(); |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Accessor for a list of all fixed links. |
|
366 | - * @return array List of urls with scheme of |
|
367 | - * http or https and hostname. |
|
368 | - * @access public |
|
369 | - */ |
|
370 | - function getAbsoluteUrls() { |
|
371 | - if (is_integer($this->_focus)) { |
|
372 | - return $this->_frames[$this->_focus]->getAbsoluteUrls(); |
|
373 | - } |
|
374 | - $urls = array(); |
|
375 | - foreach ($this->_frames as $frame) { |
|
376 | - $urls = array_merge($urls, $frame->getAbsoluteUrls()); |
|
377 | - } |
|
378 | - return array_values(array_unique($urls)); |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Accessor for a list of all relative links. |
|
383 | - * @return array List of urls without hostname. |
|
384 | - * @access public |
|
385 | - */ |
|
386 | - function getRelativeUrls() { |
|
387 | - if (is_integer($this->_focus)) { |
|
388 | - return $this->_frames[$this->_focus]->getRelativeUrls(); |
|
389 | - } |
|
390 | - $urls = array(); |
|
391 | - foreach ($this->_frames as $frame) { |
|
392 | - $urls = array_merge($urls, $frame->getRelativeUrls()); |
|
393 | - } |
|
394 | - return array_values(array_unique($urls)); |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Accessor for URLs by the link label. Label will match |
|
399 | - * regardess of whitespace issues and case. |
|
400 | - * @param string $label Text of link. |
|
401 | - * @return array List of links with that label. |
|
402 | - * @access public |
|
403 | - */ |
|
404 | - function getUrlsByLabel($label) { |
|
405 | - if (is_integer($this->_focus)) { |
|
406 | - return $this->_tagUrlsWithFrame( |
|
407 | - $this->_frames[$this->_focus]->getUrlsByLabel($label), |
|
408 | - $this->_focus); |
|
409 | - } |
|
410 | - $urls = array(); |
|
411 | - foreach ($this->_frames as $index => $frame) { |
|
412 | - $urls = array_merge( |
|
413 | - $urls, |
|
414 | - $this->_tagUrlsWithFrame( |
|
415 | - $frame->getUrlsByLabel($label), |
|
416 | - $index)); |
|
417 | - } |
|
418 | - return $urls; |
|
419 | - } |
|
420 | - |
|
421 | - /** |
|
422 | - * Accessor for a URL by the id attribute. If in a frameset |
|
423 | - * then the first link found with that ID attribute is |
|
424 | - * returned only. Focus on a frame if you want one from |
|
425 | - * a specific part of the frameset. |
|
426 | - * @param string $id Id attribute of link. |
|
427 | - * @return string URL with that id. |
|
428 | - * @access public |
|
429 | - */ |
|
430 | - function getUrlById($id) { |
|
431 | - foreach ($this->_frames as $index => $frame) { |
|
432 | - if ($url = $frame->getUrlById($id)) { |
|
433 | - if (! $url->gettarget()) { |
|
434 | - $url->setTarget($this->_getPublicNameFromIndex($index)); |
|
435 | - } |
|
436 | - return $url; |
|
437 | - } |
|
438 | - } |
|
439 | - return false; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Attaches the intended frame index to a list of URLs. |
|
444 | - * @param array $urls List of SimpleUrls. |
|
445 | - * @param string $frame Name of frame or index. |
|
446 | - * @return array List of tagged URLs. |
|
447 | - * @access private |
|
448 | - */ |
|
449 | - function _tagUrlsWithFrame($urls, $frame) { |
|
450 | - $tagged = array(); |
|
451 | - foreach ($urls as $url) { |
|
452 | - if (! $url->getTarget()) { |
|
453 | - $url->setTarget($this->_getPublicNameFromIndex($frame)); |
|
454 | - } |
|
455 | - $tagged[] = $url; |
|
456 | - } |
|
457 | - return $tagged; |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * Finds a held form by button label. Will only |
|
462 | - * search correctly built forms. |
|
463 | - * @param SimpleSelector $selector Button finder. |
|
464 | - * @return SimpleForm Form object containing |
|
465 | - * the button. |
|
466 | - * @access public |
|
467 | - */ |
|
468 | - function &getFormBySubmit($selector) { |
|
469 | - $form = $this->_findForm('getFormBySubmit', $selector); |
|
470 | - return $form; |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Finds a held form by image using a selector. |
|
475 | - * Will only search correctly built forms. The first |
|
476 | - * form found either within the focused frame, or |
|
477 | - * across frames, will be the one returned. |
|
478 | - * @param SimpleSelector $selector Image finder. |
|
479 | - * @return SimpleForm Form object containing |
|
480 | - * the image. |
|
481 | - * @access public |
|
482 | - */ |
|
483 | - function &getFormByImage($selector) { |
|
484 | - $form = $this->_findForm('getFormByImage', $selector); |
|
485 | - return $form; |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Finds a held form by the form ID. A way of |
|
490 | - * identifying a specific form when we have control |
|
491 | - * of the HTML code. The first form found |
|
492 | - * either within the focused frame, or across frames, |
|
493 | - * will be the one returned. |
|
494 | - * @param string $id Form label. |
|
495 | - * @return SimpleForm Form object containing the matching ID. |
|
496 | - * @access public |
|
497 | - */ |
|
498 | - function &getFormById($id) { |
|
499 | - $form = $this->_findForm('getFormById', $id); |
|
500 | - return $form; |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * General form finder. Will search all the frames or |
|
505 | - * just the one in focus. |
|
506 | - * @param string $method Method to use to find in a page. |
|
507 | - * @param string $attribute Label, name or ID. |
|
508 | - * @return SimpleForm Form object containing the matching ID. |
|
509 | - * @access private |
|
510 | - */ |
|
511 | - function &_findForm($method, $attribute) { |
|
512 | - if (is_integer($this->_focus)) { |
|
513 | - $form = $this->_findFormInFrame( |
|
514 | - $this->_frames[$this->_focus], |
|
515 | - $this->_focus, |
|
516 | - $method, |
|
517 | - $attribute); |
|
518 | - return $form; |
|
519 | - } |
|
520 | - for ($i = 0; $i < count($this->_frames); $i++) { |
|
521 | - $form = $this->_findFormInFrame( |
|
522 | - $this->_frames[$i], |
|
523 | - $i, |
|
524 | - $method, |
|
525 | - $attribute); |
|
526 | - if ($form) { |
|
527 | - return $form; |
|
528 | - } |
|
529 | - } |
|
530 | - $null = null; |
|
531 | - return $null; |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * Finds a form in a page using a form finding method. Will |
|
536 | - * also tag the form with the frame name it belongs in. |
|
537 | - * @param SimplePage $page Page content of frame. |
|
538 | - * @param integer $index Internal frame representation. |
|
539 | - * @param string $method Method to use to find in a page. |
|
540 | - * @param string $attribute Label, name or ID. |
|
541 | - * @return SimpleForm Form object containing the matching ID. |
|
542 | - * @access private |
|
543 | - */ |
|
544 | - function &_findFormInFrame($page, $index, $method, $attribute) { |
|
545 | - $form = $this->_frames[$index]->$method($attribute); |
|
546 | - if (isset($form)) { |
|
547 | - $form->setDefaultTarget($this->_getPublicNameFromIndex($index)); |
|
548 | - } |
|
549 | - return $form; |
|
550 | - } |
|
551 | - |
|
552 | - /** |
|
553 | - * Sets a field on each form in which the field is |
|
554 | - * available. |
|
555 | - * @param SimpleSelector $selector Field finder. |
|
556 | - * @param string $value Value to set field to. |
|
557 | - * @return boolean True if value is valid. |
|
558 | - * @access public |
|
559 | - */ |
|
560 | - function setField($selector, $value) { |
|
561 | - if (is_integer($this->_focus)) { |
|
562 | - $this->_frames[$this->_focus]->setField($selector, $value); |
|
563 | - } else { |
|
564 | - for ($i = 0; $i < count($this->_frames); $i++) { |
|
565 | - $this->_frames[$i]->setField($selector, $value); |
|
566 | - } |
|
567 | - } |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Accessor for a form element value within a page. |
|
572 | - * @param SimpleSelector $selector Field finder. |
|
573 | - * @return string/boolean A string if the field is |
|
574 | - * present, false if unchecked |
|
575 | - * and null if missing. |
|
576 | - * @access public |
|
577 | - */ |
|
578 | - function getField($selector) { |
|
579 | - for ($i = 0; $i < count($this->_frames); $i++) { |
|
580 | - $value = $this->_frames[$i]->getField($selector); |
|
581 | - if (isset($value)) { |
|
582 | - return $value; |
|
583 | - } |
|
584 | - } |
|
585 | - return null; |
|
586 | - } |
|
587 | - } |
|
588 | 23 | \ No newline at end of file |
24 | + */ |
|
25 | + class SimpleFrameset { |
|
26 | + protected $_frameset; |
|
27 | + protected $_frames; |
|
28 | + protected $_focus; |
|
29 | + protected $_names; |
|
30 | + |
|
31 | + /** |
|
32 | + * Stashes the frameset page. Will make use of the |
|
33 | + * browser to fetch the sub frames recursively. |
|
34 | + * @param SimplePage $page Frameset page. |
|
35 | + */ |
|
36 | + function SimpleFrameset($page) { |
|
37 | + $this->_frameset = $page; |
|
38 | + $this->_frames = array(); |
|
39 | + $this->_focus = false; |
|
40 | + $this->_names = array(); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Adds a parsed page to the frameset. |
|
45 | + * @param SimplePage $page Frame page. |
|
46 | + * @param string $name Name of frame in frameset. |
|
47 | + * @access public |
|
48 | + */ |
|
49 | + function addFrame($page, $name = false) { |
|
50 | + $this->_frames[] = $page; |
|
51 | + if ($name) { |
|
52 | + $this->_names[$name] = count($this->_frames) - 1; |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Replaces existing frame with another. If the |
|
58 | + * frame is nested, then the call is passed down |
|
59 | + * one level. |
|
60 | + * @param array $path Path of frame in frameset. |
|
61 | + * @param SimplePage $page Frame source. |
|
62 | + * @access public |
|
63 | + */ |
|
64 | + function setFrame($path, $page) { |
|
65 | + $name = array_shift($path); |
|
66 | + if (isset($this->_names[$name])) { |
|
67 | + $index = $this->_names[$name]; |
|
68 | + } else { |
|
69 | + $index = $name - 1; |
|
70 | + } |
|
71 | + if (count($path) == 0) { |
|
72 | + $this->_frames[$index] = $page; |
|
73 | + return; |
|
74 | + } |
|
75 | + $this->_frames[$index]->setFrame($path, $page); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Accessor for current frame focus. Will be |
|
80 | + * false if no frame has focus. Will have the nested |
|
81 | + * frame focus if any. |
|
82 | + * @return array Labels or indexes of nested frames. |
|
83 | + * @access public |
|
84 | + */ |
|
85 | + function getFrameFocus() { |
|
86 | + if ($this->_focus === false) { |
|
87 | + return array(); |
|
88 | + } |
|
89 | + return array_merge( |
|
90 | + array($this->_getPublicNameFromIndex($this->_focus)), |
|
91 | + $this->_frames[$this->_focus]->getFrameFocus()); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Turns an internal array index into the frames list |
|
96 | + * into a public name, or if none, then a one offset |
|
97 | + * index. |
|
98 | + * @param integer $subject Internal index. |
|
99 | + * @return integer/string Public name. |
|
100 | + * @access private |
|
101 | + */ |
|
102 | + function _getPublicNameFromIndex($subject) { |
|
103 | + foreach ($this->_names as $name => $index) { |
|
104 | + if ($subject == $index) { |
|
105 | + return $name; |
|
106 | + } |
|
107 | + } |
|
108 | + return $subject + 1; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Sets the focus by index. The integer index starts from 1. |
|
113 | + * If already focused and the target frame also has frames, |
|
114 | + * then the nested frame will be focused. |
|
115 | + * @param integer $choice Chosen frame. |
|
116 | + * @return boolean True if frame exists. |
|
117 | + * @access public |
|
118 | + */ |
|
119 | + function setFrameFocusByIndex($choice) { |
|
120 | + if (is_integer($this->_focus)) { |
|
121 | + if ($this->_frames[$this->_focus]->hasFrames()) { |
|
122 | + return $this->_frames[$this->_focus]->setFrameFocusByIndex($choice); |
|
123 | + } |
|
124 | + } |
|
125 | + if (($choice < 1) || ($choice > count($this->_frames))) { |
|
126 | + return false; |
|
127 | + } |
|
128 | + $this->_focus = $choice - 1; |
|
129 | + return true; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Sets the focus by name. If already focused and the |
|
134 | + * target frame also has frames, then the nested frame |
|
135 | + * will be focused. |
|
136 | + * @param string $name Chosen frame. |
|
137 | + * @return boolean True if frame exists. |
|
138 | + * @access public |
|
139 | + */ |
|
140 | + function setFrameFocus($name) { |
|
141 | + if (is_integer($this->_focus)) { |
|
142 | + if ($this->_frames[$this->_focus]->hasFrames()) { |
|
143 | + return $this->_frames[$this->_focus]->setFrameFocus($name); |
|
144 | + } |
|
145 | + } |
|
146 | + if (in_array($name, array_keys($this->_names))) { |
|
147 | + $this->_focus = $this->_names[$name]; |
|
148 | + return true; |
|
149 | + } |
|
150 | + return false; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Clears the frame focus. |
|
155 | + * @access public |
|
156 | + */ |
|
157 | + function clearFrameFocus() { |
|
158 | + $this->_focus = false; |
|
159 | + $this->_clearNestedFramesFocus(); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Clears the frame focus for any nested frames. |
|
164 | + * @access private |
|
165 | + */ |
|
166 | + function _clearNestedFramesFocus() { |
|
167 | + for ($i = 0; $i < count($this->_frames); $i++) { |
|
168 | + $this->_frames[$i]->clearFrameFocus(); |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Test for the presence of a frameset. |
|
174 | + * @return boolean Always true. |
|
175 | + * @access public |
|
176 | + */ |
|
177 | + function hasFrames() { |
|
178 | + return true; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Accessor for frames information. |
|
183 | + * @return array/string Recursive hash of frame URL strings. |
|
184 | + * The key is either a numerical |
|
185 | + * index or the name attribute. |
|
186 | + * @access public |
|
187 | + */ |
|
188 | + function getFrames() { |
|
189 | + $report = array(); |
|
190 | + for ($i = 0; $i < count($this->_frames); $i++) { |
|
191 | + $report[$this->_getPublicNameFromIndex($i)] = |
|
192 | + $this->_frames[$i]->getFrames(); |
|
193 | + } |
|
194 | + return $report; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Accessor for raw text of either all the pages or |
|
199 | + * the frame in focus. |
|
200 | + * @return string Raw unparsed content. |
|
201 | + * @access public |
|
202 | + */ |
|
203 | + function getRaw() { |
|
204 | + if (is_integer($this->_focus)) { |
|
205 | + return $this->_frames[$this->_focus]->getRaw(); |
|
206 | + } |
|
207 | + $raw = ''; |
|
208 | + for ($i = 0; $i < count($this->_frames); $i++) { |
|
209 | + $raw .= $this->_frames[$i]->getRaw(); |
|
210 | + } |
|
211 | + return $raw; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Accessor for plain text of either all the pages or |
|
216 | + * the frame in focus. |
|
217 | + * @return string Plain text content. |
|
218 | + * @access public |
|
219 | + */ |
|
220 | + function getText() { |
|
221 | + if (is_integer($this->_focus)) { |
|
222 | + return $this->_frames[$this->_focus]->getText(); |
|
223 | + } |
|
224 | + $raw = ''; |
|
225 | + for ($i = 0; $i < count($this->_frames); $i++) { |
|
226 | + $raw .= ' ' . $this->_frames[$i]->getText(); |
|
227 | + } |
|
228 | + return trim($raw); |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Accessor for last error. |
|
233 | + * @return string Error from last response. |
|
234 | + * @access public |
|
235 | + */ |
|
236 | + function getTransportError() { |
|
237 | + if (is_integer($this->_focus)) { |
|
238 | + return $this->_frames[$this->_focus]->getTransportError(); |
|
239 | + } |
|
240 | + return $this->_frameset->getTransportError(); |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Request method used to fetch this frame. |
|
245 | + * @return string GET, POST or HEAD. |
|
246 | + * @access public |
|
247 | + */ |
|
248 | + function getMethod() { |
|
249 | + if (is_integer($this->_focus)) { |
|
250 | + return $this->_frames[$this->_focus]->getMethod(); |
|
251 | + } |
|
252 | + return $this->_frameset->getMethod(); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Original resource name. |
|
257 | + * @return SimpleUrl Current url. |
|
258 | + * @access public |
|
259 | + */ |
|
260 | + function getUrl() { |
|
261 | + if (is_integer($this->_focus)) { |
|
262 | + $url = $this->_frames[$this->_focus]->getUrl(); |
|
263 | + $url->setTarget($this->_getPublicNameFromIndex($this->_focus)); |
|
264 | + } else { |
|
265 | + $url = $this->_frameset->getUrl(); |
|
266 | + } |
|
267 | + return $url; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Original request data. |
|
272 | + * @return mixed Sent content. |
|
273 | + * @access public |
|
274 | + */ |
|
275 | + function getRequestData() { |
|
276 | + if (is_integer($this->_focus)) { |
|
277 | + return $this->_frames[$this->_focus]->getRequestData(); |
|
278 | + } |
|
279 | + return $this->_frameset->getRequestData(); |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Accessor for current MIME type. |
|
284 | + * @return string MIME type as string; e.g. 'text/html' |
|
285 | + * @access public |
|
286 | + */ |
|
287 | + function getMimeType() { |
|
288 | + if (is_integer($this->_focus)) { |
|
289 | + return $this->_frames[$this->_focus]->getMimeType(); |
|
290 | + } |
|
291 | + return $this->_frameset->getMimeType(); |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Accessor for last response code. |
|
296 | + * @return integer Last HTTP response code received. |
|
297 | + * @access public |
|
298 | + */ |
|
299 | + function getResponseCode() { |
|
300 | + if (is_integer($this->_focus)) { |
|
301 | + return $this->_frames[$this->_focus]->getResponseCode(); |
|
302 | + } |
|
303 | + return $this->_frameset->getResponseCode(); |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Accessor for last Authentication type. Only valid |
|
308 | + * straight after a challenge (401). |
|
309 | + * @return string Description of challenge type. |
|
310 | + * @access public |
|
311 | + */ |
|
312 | + function getAuthentication() { |
|
313 | + if (is_integer($this->_focus)) { |
|
314 | + return $this->_frames[$this->_focus]->getAuthentication(); |
|
315 | + } |
|
316 | + return $this->_frameset->getAuthentication(); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Accessor for last Authentication realm. Only valid |
|
321 | + * straight after a challenge (401). |
|
322 | + * @return string Name of security realm. |
|
323 | + * @access public |
|
324 | + */ |
|
325 | + function getRealm() { |
|
326 | + if (is_integer($this->_focus)) { |
|
327 | + return $this->_frames[$this->_focus]->getRealm(); |
|
328 | + } |
|
329 | + return $this->_frameset->getRealm(); |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Accessor for outgoing header information. |
|
334 | + * @return string Header block. |
|
335 | + * @access public |
|
336 | + */ |
|
337 | + function getRequest() { |
|
338 | + if (is_integer($this->_focus)) { |
|
339 | + return $this->_frames[$this->_focus]->getRequest(); |
|
340 | + } |
|
341 | + return $this->_frameset->getRequest(); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Accessor for raw header information. |
|
346 | + * @return string Header block. |
|
347 | + * @access public |
|
348 | + */ |
|
349 | + function getHeaders() { |
|
350 | + if (is_integer($this->_focus)) { |
|
351 | + return $this->_frames[$this->_focus]->getHeaders(); |
|
352 | + } |
|
353 | + return $this->_frameset->getHeaders(); |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Accessor for parsed title. |
|
358 | + * @return string Title or false if no title is present. |
|
359 | + * @access public |
|
360 | + */ |
|
361 | + function getTitle() { |
|
362 | + return $this->_frameset->getTitle(); |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Accessor for a list of all fixed links. |
|
367 | + * @return array List of urls with scheme of |
|
368 | + * http or https and hostname. |
|
369 | + * @access public |
|
370 | + */ |
|
371 | + function getAbsoluteUrls() { |
|
372 | + if (is_integer($this->_focus)) { |
|
373 | + return $this->_frames[$this->_focus]->getAbsoluteUrls(); |
|
374 | + } |
|
375 | + $urls = array(); |
|
376 | + foreach ($this->_frames as $frame) { |
|
377 | + $urls = array_merge($urls, $frame->getAbsoluteUrls()); |
|
378 | + } |
|
379 | + return array_values(array_unique($urls)); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Accessor for a list of all relative links. |
|
384 | + * @return array List of urls without hostname. |
|
385 | + * @access public |
|
386 | + */ |
|
387 | + function getRelativeUrls() { |
|
388 | + if (is_integer($this->_focus)) { |
|
389 | + return $this->_frames[$this->_focus]->getRelativeUrls(); |
|
390 | + } |
|
391 | + $urls = array(); |
|
392 | + foreach ($this->_frames as $frame) { |
|
393 | + $urls = array_merge($urls, $frame->getRelativeUrls()); |
|
394 | + } |
|
395 | + return array_values(array_unique($urls)); |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Accessor for URLs by the link label. Label will match |
|
400 | + * regardess of whitespace issues and case. |
|
401 | + * @param string $label Text of link. |
|
402 | + * @return array List of links with that label. |
|
403 | + * @access public |
|
404 | + */ |
|
405 | + function getUrlsByLabel($label) { |
|
406 | + if (is_integer($this->_focus)) { |
|
407 | + return $this->_tagUrlsWithFrame( |
|
408 | + $this->_frames[$this->_focus]->getUrlsByLabel($label), |
|
409 | + $this->_focus); |
|
410 | + } |
|
411 | + $urls = array(); |
|
412 | + foreach ($this->_frames as $index => $frame) { |
|
413 | + $urls = array_merge( |
|
414 | + $urls, |
|
415 | + $this->_tagUrlsWithFrame( |
|
416 | + $frame->getUrlsByLabel($label), |
|
417 | + $index)); |
|
418 | + } |
|
419 | + return $urls; |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Accessor for a URL by the id attribute. If in a frameset |
|
424 | + * then the first link found with that ID attribute is |
|
425 | + * returned only. Focus on a frame if you want one from |
|
426 | + * a specific part of the frameset. |
|
427 | + * @param string $id Id attribute of link. |
|
428 | + * @return string URL with that id. |
|
429 | + * @access public |
|
430 | + */ |
|
431 | + function getUrlById($id) { |
|
432 | + foreach ($this->_frames as $index => $frame) { |
|
433 | + if ($url = $frame->getUrlById($id)) { |
|
434 | + if (! $url->gettarget()) { |
|
435 | + $url->setTarget($this->_getPublicNameFromIndex($index)); |
|
436 | + } |
|
437 | + return $url; |
|
438 | + } |
|
439 | + } |
|
440 | + return false; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Attaches the intended frame index to a list of URLs. |
|
445 | + * @param array $urls List of SimpleUrls. |
|
446 | + * @param string $frame Name of frame or index. |
|
447 | + * @return array List of tagged URLs. |
|
448 | + * @access private |
|
449 | + */ |
|
450 | + function _tagUrlsWithFrame($urls, $frame) { |
|
451 | + $tagged = array(); |
|
452 | + foreach ($urls as $url) { |
|
453 | + if (! $url->getTarget()) { |
|
454 | + $url->setTarget($this->_getPublicNameFromIndex($frame)); |
|
455 | + } |
|
456 | + $tagged[] = $url; |
|
457 | + } |
|
458 | + return $tagged; |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * Finds a held form by button label. Will only |
|
463 | + * search correctly built forms. |
|
464 | + * @param SimpleSelector $selector Button finder. |
|
465 | + * @return SimpleForm Form object containing |
|
466 | + * the button. |
|
467 | + * @access public |
|
468 | + */ |
|
469 | + function &getFormBySubmit($selector) { |
|
470 | + $form = $this->_findForm('getFormBySubmit', $selector); |
|
471 | + return $form; |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * Finds a held form by image using a selector. |
|
476 | + * Will only search correctly built forms. The first |
|
477 | + * form found either within the focused frame, or |
|
478 | + * across frames, will be the one returned. |
|
479 | + * @param SimpleSelector $selector Image finder. |
|
480 | + * @return SimpleForm Form object containing |
|
481 | + * the image. |
|
482 | + * @access public |
|
483 | + */ |
|
484 | + function &getFormByImage($selector) { |
|
485 | + $form = $this->_findForm('getFormByImage', $selector); |
|
486 | + return $form; |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Finds a held form by the form ID. A way of |
|
491 | + * identifying a specific form when we have control |
|
492 | + * of the HTML code. The first form found |
|
493 | + * either within the focused frame, or across frames, |
|
494 | + * will be the one returned. |
|
495 | + * @param string $id Form label. |
|
496 | + * @return SimpleForm Form object containing the matching ID. |
|
497 | + * @access public |
|
498 | + */ |
|
499 | + function &getFormById($id) { |
|
500 | + $form = $this->_findForm('getFormById', $id); |
|
501 | + return $form; |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * General form finder. Will search all the frames or |
|
506 | + * just the one in focus. |
|
507 | + * @param string $method Method to use to find in a page. |
|
508 | + * @param string $attribute Label, name or ID. |
|
509 | + * @return SimpleForm Form object containing the matching ID. |
|
510 | + * @access private |
|
511 | + */ |
|
512 | + function &_findForm($method, $attribute) { |
|
513 | + if (is_integer($this->_focus)) { |
|
514 | + $form = $this->_findFormInFrame( |
|
515 | + $this->_frames[$this->_focus], |
|
516 | + $this->_focus, |
|
517 | + $method, |
|
518 | + $attribute); |
|
519 | + return $form; |
|
520 | + } |
|
521 | + for ($i = 0; $i < count($this->_frames); $i++) { |
|
522 | + $form = $this->_findFormInFrame( |
|
523 | + $this->_frames[$i], |
|
524 | + $i, |
|
525 | + $method, |
|
526 | + $attribute); |
|
527 | + if ($form) { |
|
528 | + return $form; |
|
529 | + } |
|
530 | + } |
|
531 | + $null = null; |
|
532 | + return $null; |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Finds a form in a page using a form finding method. Will |
|
537 | + * also tag the form with the frame name it belongs in. |
|
538 | + * @param SimplePage $page Page content of frame. |
|
539 | + * @param integer $index Internal frame representation. |
|
540 | + * @param string $method Method to use to find in a page. |
|
541 | + * @param string $attribute Label, name or ID. |
|
542 | + * @return SimpleForm Form object containing the matching ID. |
|
543 | + * @access private |
|
544 | + */ |
|
545 | + function &_findFormInFrame($page, $index, $method, $attribute) { |
|
546 | + $form = $this->_frames[$index]->$method($attribute); |
|
547 | + if (isset($form)) { |
|
548 | + $form->setDefaultTarget($this->_getPublicNameFromIndex($index)); |
|
549 | + } |
|
550 | + return $form; |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Sets a field on each form in which the field is |
|
555 | + * available. |
|
556 | + * @param SimpleSelector $selector Field finder. |
|
557 | + * @param string $value Value to set field to. |
|
558 | + * @return boolean True if value is valid. |
|
559 | + * @access public |
|
560 | + */ |
|
561 | + function setField($selector, $value) { |
|
562 | + if (is_integer($this->_focus)) { |
|
563 | + $this->_frames[$this->_focus]->setField($selector, $value); |
|
564 | + } else { |
|
565 | + for ($i = 0; $i < count($this->_frames); $i++) { |
|
566 | + $this->_frames[$i]->setField($selector, $value); |
|
567 | + } |
|
568 | + } |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Accessor for a form element value within a page. |
|
573 | + * @param SimpleSelector $selector Field finder. |
|
574 | + * @return string/boolean A string if the field is |
|
575 | + * present, false if unchecked |
|
576 | + * and null if missing. |
|
577 | + * @access public |
|
578 | + */ |
|
579 | + function getField($selector) { |
|
580 | + for ($i = 0; $i < count($this->_frames); $i++) { |
|
581 | + $value = $this->_frames[$i]->getField($selector); |
|
582 | + if (isset($value)) { |
|
583 | + return $value; |
|
584 | + } |
|
585 | + } |
|
586 | + return null; |
|
587 | + } |
|
588 | + } |
|
589 | 589 | \ No newline at end of file |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | function getUrlById($id) { |
431 | 431 | foreach ($this->_frames as $index => $frame) { |
432 | 432 | if ($url = $frame->getUrlById($id)) { |
433 | - if (! $url->gettarget()) { |
|
433 | + if (!$url->gettarget()) { |
|
434 | 434 | $url->setTarget($this->_getPublicNameFromIndex($index)); |
435 | 435 | } |
436 | 436 | return $url; |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | function _tagUrlsWithFrame($urls, $frame) { |
450 | 450 | $tagged = array(); |
451 | 451 | foreach ($urls as $url) { |
452 | - if (! $url->getTarget()) { |
|
452 | + if (!$url->getTarget()) { |
|
453 | 453 | $url->setTarget($this->_getPublicNameFromIndex($frame)); |
454 | 454 | } |
455 | 455 | $tagged[] = $url; |
@@ -141,6 +141,9 @@ |
||
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | + /** |
|
145 | + * @param string $file |
|
146 | + */ |
|
144 | 147 | function constructURL($file, $coverage) |
145 | 148 | { |
146 | 149 | $file = rawurlencode($file); |
@@ -19,10 +19,10 @@ discard block |
||
19 | 19 | $this->base_dir = $base_dir; |
20 | 20 | } |
21 | 21 | |
22 | - function paintHeader($test_name, $charset="UTF-8") |
|
22 | + function paintHeader($test_name, $charset = "UTF-8") |
|
23 | 23 | { |
24 | 24 | $this->sendNoCacheHeaders(); |
25 | - header('Content-Type: text/html; Charset='.$charset); |
|
25 | + header('Content-Type: text/html; Charset=' . $charset); |
|
26 | 26 | print "<html>\n<head>\n<title>$test_name</title>\n"; |
27 | 27 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset={$charset}\"/>"; |
28 | 28 | print "<style type=\"text/css\">\n"; |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | function _getCss() |
44 | 44 | { |
45 | - $contents = parent::_getCss()."\n "; |
|
45 | + $contents = parent::_getCss() . "\n "; |
|
46 | 46 | $contents .= ' |
47 | 47 | .bar { float: left; display: inline; border: 1px solid #eee; width: 300px; white-space: nowrap;} |
48 | 48 | .percentage { float: left; background-color: #eef; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 0.65em; padding: 5px; margin-right: } |
@@ -91,24 +91,24 @@ discard block |
||
91 | 91 | function paintCoverage() |
92 | 92 | { |
93 | 93 | $dir = dirname(__FILE__); |
94 | - if(count($this->coverage) > 0) |
|
94 | + if (count($this->coverage) > 0) |
|
95 | 95 | print '<h2>Code Coverage</h2>'; |
96 | 96 | |
97 | 97 | |
98 | 98 | ksort($this->coverage); |
99 | 99 | |
100 | 100 | $details = array(); |
101 | - foreach($this->coverage as $file => $coverage) |
|
101 | + foreach ($this->coverage as $file => $coverage) |
|
102 | 102 | { |
103 | - if(is_int(strpos($file, $dir)) == false |
|
103 | + if (is_int(strpos($file, $dir)) == false |
|
104 | 104 | && is_int(strpos($file, 'simpletest')) == false |
105 | 105 | && is_int(strpos($file, $this->base_dir))) |
106 | 106 | { |
107 | 107 | $total = HTMLCoverageReport::codelines($file); |
108 | 108 | $executed = count($coverage); |
109 | - $percentage = sprintf('%01d',$executed/$total*100); |
|
109 | + $percentage = sprintf('%01d', $executed / $total * 100); |
|
110 | 110 | $width = $percentage * 3; |
111 | - $filename = str_replace($this->base_dir, '',$file); |
|
111 | + $filename = str_replace($this->base_dir, '', $file); |
|
112 | 112 | $link = $this->constructURL($filename, $coverage); |
113 | 113 | |
114 | 114 | $detail['total'] = $total; |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | } |
121 | 121 | } |
122 | 122 | krsort($details); |
123 | - foreach($details as $percentage => $files) |
|
123 | + foreach ($details as $percentage => $files) |
|
124 | 124 | { |
125 | - foreach($files as $detail) |
|
125 | + foreach ($files as $detail) |
|
126 | 126 | { |
127 | 127 | $total = $detail['total']; |
128 | 128 | $executed = $detail['executed']; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | { |
146 | 146 | $file = rawurlencode($file); |
147 | 147 | $lines = implode(',', array_keys($coverage)); |
148 | - return $this->painter.'?file='.$file.'&lines='.$lines; |
|
148 | + return $this->painter . '?file=' . $file . '&lines=' . $lines; |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -168,14 +168,14 @@ discard block |
||
168 | 168 | $this->paintHeader($this->name); |
169 | 169 | |
170 | 170 | $contents = file($this->file); |
171 | - foreach($contents as $count => $line) |
|
171 | + foreach ($contents as $count => $line) |
|
172 | 172 | { |
173 | - $num = ($count+1); |
|
174 | - $line = preg_replace("/\\n|\\r/",'',$line); |
|
173 | + $num = ($count + 1); |
|
174 | + $line = preg_replace("/\\n|\\r/", '', $line); |
|
175 | 175 | $line = htmlspecialchars($line); |
176 | - $line = str_replace(' ',' ',$line); |
|
177 | - $line = str_replace("\t",' ',$line); |
|
178 | - if(in_array($count+1, $this->lines)) |
|
176 | + $line = str_replace(' ', ' ', $line); |
|
177 | + $line = str_replace("\t", ' ', $line); |
|
178 | + if (in_array($count + 1, $this->lines)) |
|
179 | 179 | echo "<div class=\"highlight\"><tt>$num $line</tt></div>\n"; |
180 | 180 | else |
181 | 181 | echo "<tt>$num $line</tt><br />\n"; |
@@ -184,14 +184,14 @@ discard block |
||
184 | 184 | $this->paintFooter(); |
185 | 185 | } |
186 | 186 | |
187 | - function paintHeader($file, $charset="UTF-8") |
|
187 | + function paintHeader($file, $charset = "UTF-8") |
|
188 | 188 | { |
189 | 189 | $total = $this->codelines($this->file); |
190 | 190 | $executed = count($this->lines); |
191 | - $percentage = sprintf('%01.2f',$executed/$total*100); |
|
191 | + $percentage = sprintf('%01.2f', $executed / $total * 100); |
|
192 | 192 | |
193 | 193 | $this->sendNoCacheHeaders(); |
194 | - header('Content-Type: text/html Charset='.$charset); |
|
194 | + header('Content-Type: text/html Charset=' . $charset); |
|
195 | 195 | print "<html>\n<head>\n<title>Code Coverage: $file</title>\n"; |
196 | 196 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset={$charset}\"/>"; |
197 | 197 | print "<style type=\"text/css\">\n"; |
@@ -247,16 +247,16 @@ discard block |
||
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
250 | - $lines = preg_replace('/\\n\s*$/m',"",$lines); |
|
251 | - $codelines = explode("\n",$lines); |
|
250 | + $lines = preg_replace('/\\n\s*$/m', "", $lines); |
|
251 | + $codelines = explode("\n", $lines); |
|
252 | 252 | $count = 0; |
253 | 253 | $patterns[] = '^\s*{\s*$'; |
254 | 254 | $patterns[] = '<\?'; |
255 | 255 | $patterns[] = '^\s*(private|protected|public)\s+\$'; |
256 | - $pattern = '/'.implode('|', $patterns).'/'; |
|
257 | - foreach($codelines as $line) |
|
256 | + $pattern = '/' . implode('|', $patterns) . '/'; |
|
257 | + foreach ($codelines as $line) |
|
258 | 258 | { |
259 | - if(!preg_match($pattern, $line)) |
|
259 | + if (!preg_match($pattern, $line)) |
|
260 | 260 | $count++; |
261 | 261 | } |
262 | 262 | return $count; |
@@ -1,9 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('T_ML_COMMENT')) |
|
3 | +if (!defined('T_ML_COMMENT')) { |
|
4 | 4 | define('T_ML_COMMENT', T_COMMENT); |
5 | -else |
|
5 | +} else { |
|
6 | 6 | define('T_DOC_COMMENT', T_ML_COMMENT); |
7 | +} |
|
7 | 8 | |
8 | 9 | class HtmlReporterWithCoverage extends HtmlReporter |
9 | 10 | { |
@@ -32,8 +33,9 @@ discard block |
||
32 | 33 | print "<h1>$test_name</h1>\n"; |
33 | 34 | flush(); |
34 | 35 | |
35 | - if (extension_loaded('xdebug')) |
|
36 | - xdebug_start_code_coverage(XDEBUG_CC_UNUSED); |
|
36 | + if (extension_loaded('xdebug')) { |
|
37 | + xdebug_start_code_coverage(XDEBUG_CC_UNUSED); |
|
38 | + } |
|
37 | 39 | |
38 | 40 | } |
39 | 41 | |
@@ -91,8 +93,9 @@ discard block |
||
91 | 93 | function paintCoverage() |
92 | 94 | { |
93 | 95 | $dir = dirname(__FILE__); |
94 | - if(count($this->coverage) > 0) |
|
95 | - print '<h2>Code Coverage</h2>'; |
|
96 | + if(count($this->coverage) > 0) { |
|
97 | + print '<h2>Code Coverage</h2>'; |
|
98 | + } |
|
96 | 99 | |
97 | 100 | |
98 | 101 | ksort($this->coverage); |
@@ -175,10 +178,11 @@ discard block |
||
175 | 178 | $line = htmlspecialchars($line); |
176 | 179 | $line = str_replace(' ',' ',$line); |
177 | 180 | $line = str_replace("\t",' ',$line); |
178 | - if(in_array($count+1, $this->lines)) |
|
179 | - echo "<div class=\"highlight\"><tt>$num $line</tt></div>\n"; |
|
180 | - else |
|
181 | - echo "<tt>$num $line</tt><br />\n"; |
|
181 | + if(in_array($count+1, $this->lines)) { |
|
182 | + echo "<div class=\"highlight\"><tt>$num $line</tt></div>\n"; |
|
183 | + } else { |
|
184 | + echo "<tt>$num $line</tt><br />\n"; |
|
185 | + } |
|
182 | 186 | } |
183 | 187 | |
184 | 188 | $this->paintFooter(); |
@@ -224,8 +228,7 @@ discard block |
||
224 | 228 | { |
225 | 229 | // simple 1-character token |
226 | 230 | $lines .= $token; |
227 | - } |
|
228 | - else |
|
231 | + } else |
|
229 | 232 | { |
230 | 233 | // token array |
231 | 234 | list($id, $text) = $token; |
@@ -256,8 +259,9 @@ discard block |
||
256 | 259 | $pattern = '/'.implode('|', $patterns).'/'; |
257 | 260 | foreach($codelines as $line) |
258 | 261 | { |
259 | - if(!preg_match($pattern, $line)) |
|
260 | - $count++; |
|
262 | + if(!preg_match($pattern, $line)) { |
|
263 | + $count++; |
|
264 | + } |
|
261 | 265 | } |
262 | 266 | return $count; |
263 | 267 | //var_dump($codelines); |
@@ -135,9 +135,6 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * Creates the first line which is the actual request. |
137 | 137 | * @param string $method HTTP request method, usually GET. |
138 | - * @param SimpleUrl $url URL as object. |
|
139 | - * @return string Request line content. |
|
140 | - * @access protected |
|
141 | 138 | */ |
142 | 139 | function _getRequestLine($method) { |
143 | 140 | $url = $this->getUrl(); |
@@ -149,9 +146,6 @@ discard block |
||
149 | 146 | |
150 | 147 | /** |
151 | 148 | * Creates the host part of the request. |
152 | - * @param SimpleUrl $url URL as object. |
|
153 | - * @return string Host line content. |
|
154 | - * @access protected |
|
155 | 149 | */ |
156 | 150 | function _getHostLine() { |
157 | 151 | $host = 'Host: ' . $this->_proxy->getHost(); |
@@ -235,10 +229,6 @@ discard block |
||
235 | 229 | /** |
236 | 230 | * Sends the headers. |
237 | 231 | * @param SimpleSocket $socket Open socket. |
238 | - * @param string $method HTTP request method, |
|
239 | - * usually GET. |
|
240 | - * @param SimpleFormEncoding $encoding Content to send with request. |
|
241 | - * @access private |
|
242 | 232 | */ |
243 | 233 | function _dispatchRequest($socket, $encoding) { |
244 | 234 | foreach ($this->_headers as $header_line) { |
@@ -323,7 +313,7 @@ discard block |
||
323 | 313 | |
324 | 314 | /** |
325 | 315 | * Accessor for parsed HTTP protocol version. |
326 | - * @return integer HTTP error code. |
|
316 | + * @return false|string HTTP error code. |
|
327 | 317 | * @access public |
328 | 318 | */ |
329 | 319 | function getHttpVersion() { |
@@ -565,7 +555,7 @@ discard block |
||
565 | 555 | /** |
566 | 556 | * Accessor for the content after the last |
567 | 557 | * header line. |
568 | - * @return string All content. |
|
558 | + * @return boolean All content. |
|
569 | 559 | * @access public |
570 | 560 | */ |
571 | 561 | function getContent() { |
@@ -575,7 +565,7 @@ discard block |
||
575 | 565 | /** |
576 | 566 | * Accessor for header block. The response is the |
577 | 567 | * combination of this and the content. |
578 | - * @return SimpleHeaders Wrapped header block. |
|
568 | + * @return SimpleHttpHeaders Wrapped header block. |
|
579 | 569 | * @access public |
580 | 570 | */ |
581 | 571 | function getHeaders() { |
@@ -1,623 +1,623 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage WebTester |
|
6 | - * @version $Id: http.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: http.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__) . '/socket.php'); |
|
13 | - require_once(dirname(__FILE__) . '/cookies.php'); |
|
14 | - require_once(dirname(__FILE__) . '/url.php'); |
|
15 | - /**#@-*/ |
|
16 | - |
|
17 | - /** |
|
18 | - * Creates HTTP headers for the end point of |
|
19 | - * a HTTP request. |
|
12 | + require_once(dirname(__FILE__) . '/socket.php'); |
|
13 | + require_once(dirname(__FILE__) . '/cookies.php'); |
|
14 | + require_once(dirname(__FILE__) . '/url.php'); |
|
15 | + /**#@-*/ |
|
16 | + |
|
17 | + /** |
|
18 | + * Creates HTTP headers for the end point of |
|
19 | + * a HTTP request. |
|
20 | 20 | * @package SimpleTest |
21 | 21 | * @subpackage WebTester |
22 | - */ |
|
23 | - class SimpleRoute { |
|
24 | - protected $_url; |
|
25 | - |
|
26 | - /** |
|
27 | - * Sets the target URL. |
|
28 | - * @param SimpleUrl $url URL as object. |
|
29 | - * @access public |
|
30 | - */ |
|
31 | - function SimpleRoute($url) { |
|
32 | - $this->_url = $url; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Resource name. |
|
37 | - * @return SimpleUrl Current url. |
|
38 | - * @access protected |
|
39 | - */ |
|
40 | - function getUrl() { |
|
41 | - return $this->_url; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Creates the first line which is the actual request. |
|
46 | - * @param string $method HTTP request method, usually GET. |
|
47 | - * @return string Request line content. |
|
48 | - * @access protected |
|
49 | - */ |
|
50 | - function _getRequestLine($method) { |
|
51 | - return $method . ' ' . $this->_url->getPath() . |
|
52 | - $this->_url->getEncodedRequest() . ' HTTP/1.0'; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Creates the host part of the request. |
|
57 | - * @return string Host line content. |
|
58 | - * @access protected |
|
59 | - */ |
|
60 | - function _getHostLine() { |
|
61 | - $line = 'Host: ' . $this->_url->getHost(); |
|
62 | - if ($this->_url->getPort()) { |
|
63 | - $line .= ':' . $this->_url->getPort(); |
|
64 | - } |
|
65 | - return $line; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Opens a socket to the route. |
|
70 | - * @param string $method HTTP request method, usually GET. |
|
71 | - * @param integer $timeout Connection timeout. |
|
72 | - * @return SimpleSocket New socket. |
|
73 | - * @access public |
|
74 | - */ |
|
75 | - function &createConnection($method, $timeout) { |
|
76 | - $default_port = ('https' == $this->_url->getScheme()) ? 443 : 80; |
|
77 | - $socket = $this->_createSocket( |
|
78 | - $this->_url->getScheme() ? $this->_url->getScheme() : 'http', |
|
79 | - $this->_url->getHost(), |
|
80 | - $this->_url->getPort() ? $this->_url->getPort() : $default_port, |
|
81 | - $timeout); |
|
82 | - if (! $socket->isError()) { |
|
83 | - $socket->write($this->_getRequestLine($method) . "\r\n"); |
|
84 | - $socket->write($this->_getHostLine() . "\r\n"); |
|
85 | - $socket->write("Connection: close\r\n"); |
|
86 | - } |
|
87 | - return $socket; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Factory for socket. |
|
92 | - * @param string $scheme Protocol to use. |
|
93 | - * @param string $host Hostname to connect to. |
|
94 | - * @param integer $port Remote port. |
|
95 | - * @param integer $timeout Connection timeout. |
|
96 | - * @return SimpleSocket/SimpleSecureSocket New socket. |
|
97 | - * @access protected |
|
98 | - */ |
|
99 | - function &_createSocket($scheme, $host, $port, $timeout) { |
|
100 | - if (in_array($scheme, array('https'))) { |
|
101 | - $socket = new SimpleSecureSocket($host, $port, $timeout); |
|
102 | - } else { |
|
103 | - $socket = new SimpleSocket($host, $port, $timeout); |
|
104 | - } |
|
105 | - return $socket; |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Creates HTTP headers for the end point of |
|
111 | - * a HTTP request via a proxy server. |
|
22 | + */ |
|
23 | + class SimpleRoute { |
|
24 | + protected $_url; |
|
25 | + |
|
26 | + /** |
|
27 | + * Sets the target URL. |
|
28 | + * @param SimpleUrl $url URL as object. |
|
29 | + * @access public |
|
30 | + */ |
|
31 | + function SimpleRoute($url) { |
|
32 | + $this->_url = $url; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Resource name. |
|
37 | + * @return SimpleUrl Current url. |
|
38 | + * @access protected |
|
39 | + */ |
|
40 | + function getUrl() { |
|
41 | + return $this->_url; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Creates the first line which is the actual request. |
|
46 | + * @param string $method HTTP request method, usually GET. |
|
47 | + * @return string Request line content. |
|
48 | + * @access protected |
|
49 | + */ |
|
50 | + function _getRequestLine($method) { |
|
51 | + return $method . ' ' . $this->_url->getPath() . |
|
52 | + $this->_url->getEncodedRequest() . ' HTTP/1.0'; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Creates the host part of the request. |
|
57 | + * @return string Host line content. |
|
58 | + * @access protected |
|
59 | + */ |
|
60 | + function _getHostLine() { |
|
61 | + $line = 'Host: ' . $this->_url->getHost(); |
|
62 | + if ($this->_url->getPort()) { |
|
63 | + $line .= ':' . $this->_url->getPort(); |
|
64 | + } |
|
65 | + return $line; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Opens a socket to the route. |
|
70 | + * @param string $method HTTP request method, usually GET. |
|
71 | + * @param integer $timeout Connection timeout. |
|
72 | + * @return SimpleSocket New socket. |
|
73 | + * @access public |
|
74 | + */ |
|
75 | + function &createConnection($method, $timeout) { |
|
76 | + $default_port = ('https' == $this->_url->getScheme()) ? 443 : 80; |
|
77 | + $socket = $this->_createSocket( |
|
78 | + $this->_url->getScheme() ? $this->_url->getScheme() : 'http', |
|
79 | + $this->_url->getHost(), |
|
80 | + $this->_url->getPort() ? $this->_url->getPort() : $default_port, |
|
81 | + $timeout); |
|
82 | + if (! $socket->isError()) { |
|
83 | + $socket->write($this->_getRequestLine($method) . "\r\n"); |
|
84 | + $socket->write($this->_getHostLine() . "\r\n"); |
|
85 | + $socket->write("Connection: close\r\n"); |
|
86 | + } |
|
87 | + return $socket; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Factory for socket. |
|
92 | + * @param string $scheme Protocol to use. |
|
93 | + * @param string $host Hostname to connect to. |
|
94 | + * @param integer $port Remote port. |
|
95 | + * @param integer $timeout Connection timeout. |
|
96 | + * @return SimpleSocket/SimpleSecureSocket New socket. |
|
97 | + * @access protected |
|
98 | + */ |
|
99 | + function &_createSocket($scheme, $host, $port, $timeout) { |
|
100 | + if (in_array($scheme, array('https'))) { |
|
101 | + $socket = new SimpleSecureSocket($host, $port, $timeout); |
|
102 | + } else { |
|
103 | + $socket = new SimpleSocket($host, $port, $timeout); |
|
104 | + } |
|
105 | + return $socket; |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Creates HTTP headers for the end point of |
|
111 | + * a HTTP request via a proxy server. |
|
112 | 112 | * @package SimpleTest |
113 | 113 | * @subpackage WebTester |
114 | - */ |
|
115 | - class SimpleProxyRoute extends SimpleRoute { |
|
116 | - protected $_proxy; |
|
117 | - protected $_username; |
|
118 | - protected $_password; |
|
119 | - |
|
120 | - /** |
|
121 | - * Stashes the proxy address. |
|
122 | - * @param SimpleUrl $url URL as object. |
|
123 | - * @param string $proxy Proxy URL. |
|
124 | - * @param string $username Username for autentication. |
|
125 | - * @param string $password Password for autentication. |
|
126 | - * @access public |
|
127 | - */ |
|
128 | - function SimpleProxyRoute($url, $proxy, $username = false, $password = false) { |
|
129 | - $this->SimpleRoute($url); |
|
130 | - $this->_proxy = $proxy; |
|
131 | - $this->_username = $username; |
|
132 | - $this->_password = $password; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Creates the first line which is the actual request. |
|
137 | - * @param string $method HTTP request method, usually GET. |
|
138 | - * @param SimpleUrl $url URL as object. |
|
139 | - * @return string Request line content. |
|
140 | - * @access protected |
|
141 | - */ |
|
142 | - function _getRequestLine($method) { |
|
143 | - $url = $this->getUrl(); |
|
144 | - $scheme = $url->getScheme() ? $url->getScheme() : 'http'; |
|
145 | - $port = $url->getPort() ? ':' . $url->getPort() : ''; |
|
146 | - return $method . ' ' . $scheme . '://' . $url->getHost() . $port . |
|
147 | - $url->getPath() . $url->getEncodedRequest() . ' HTTP/1.0'; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Creates the host part of the request. |
|
152 | - * @param SimpleUrl $url URL as object. |
|
153 | - * @return string Host line content. |
|
154 | - * @access protected |
|
155 | - */ |
|
156 | - function _getHostLine() { |
|
157 | - $host = 'Host: ' . $this->_proxy->getHost(); |
|
158 | - $port = $this->_proxy->getPort() ? $this->_proxy->getPort() : 8080; |
|
159 | - return "$host:$port"; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Opens a socket to the route. |
|
164 | - * @param string $method HTTP request method, usually GET. |
|
165 | - * @param integer $timeout Connection timeout. |
|
166 | - * @return SimpleSocket New socket. |
|
167 | - * @access public |
|
168 | - */ |
|
169 | - function &createConnection($method, $timeout) { |
|
170 | - $socket = $this->_createSocket( |
|
171 | - $this->_proxy->getScheme() ? $this->_proxy->getScheme() : 'http', |
|
172 | - $this->_proxy->getHost(), |
|
173 | - $this->_proxy->getPort() ? $this->_proxy->getPort() : 8080, |
|
174 | - $timeout); |
|
175 | - if ($socket->isError()) { |
|
176 | - return $socket; |
|
177 | - } |
|
178 | - $socket->write($this->_getRequestLine($method) . "\r\n"); |
|
179 | - $socket->write($this->_getHostLine() . "\r\n"); |
|
180 | - if ($this->_username && $this->_password) { |
|
181 | - $socket->write('Proxy-Authorization: Basic ' . |
|
182 | - base64_encode($this->_username . ':' . $this->_password) . |
|
183 | - "\r\n"); |
|
184 | - } |
|
185 | - $socket->write("Connection: close\r\n"); |
|
186 | - return $socket; |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * HTTP request for a web page. Factory for |
|
192 | - * HttpResponse object. |
|
114 | + */ |
|
115 | + class SimpleProxyRoute extends SimpleRoute { |
|
116 | + protected $_proxy; |
|
117 | + protected $_username; |
|
118 | + protected $_password; |
|
119 | + |
|
120 | + /** |
|
121 | + * Stashes the proxy address. |
|
122 | + * @param SimpleUrl $url URL as object. |
|
123 | + * @param string $proxy Proxy URL. |
|
124 | + * @param string $username Username for autentication. |
|
125 | + * @param string $password Password for autentication. |
|
126 | + * @access public |
|
127 | + */ |
|
128 | + function SimpleProxyRoute($url, $proxy, $username = false, $password = false) { |
|
129 | + $this->SimpleRoute($url); |
|
130 | + $this->_proxy = $proxy; |
|
131 | + $this->_username = $username; |
|
132 | + $this->_password = $password; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Creates the first line which is the actual request. |
|
137 | + * @param string $method HTTP request method, usually GET. |
|
138 | + * @param SimpleUrl $url URL as object. |
|
139 | + * @return string Request line content. |
|
140 | + * @access protected |
|
141 | + */ |
|
142 | + function _getRequestLine($method) { |
|
143 | + $url = $this->getUrl(); |
|
144 | + $scheme = $url->getScheme() ? $url->getScheme() : 'http'; |
|
145 | + $port = $url->getPort() ? ':' . $url->getPort() : ''; |
|
146 | + return $method . ' ' . $scheme . '://' . $url->getHost() . $port . |
|
147 | + $url->getPath() . $url->getEncodedRequest() . ' HTTP/1.0'; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Creates the host part of the request. |
|
152 | + * @param SimpleUrl $url URL as object. |
|
153 | + * @return string Host line content. |
|
154 | + * @access protected |
|
155 | + */ |
|
156 | + function _getHostLine() { |
|
157 | + $host = 'Host: ' . $this->_proxy->getHost(); |
|
158 | + $port = $this->_proxy->getPort() ? $this->_proxy->getPort() : 8080; |
|
159 | + return "$host:$port"; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Opens a socket to the route. |
|
164 | + * @param string $method HTTP request method, usually GET. |
|
165 | + * @param integer $timeout Connection timeout. |
|
166 | + * @return SimpleSocket New socket. |
|
167 | + * @access public |
|
168 | + */ |
|
169 | + function &createConnection($method, $timeout) { |
|
170 | + $socket = $this->_createSocket( |
|
171 | + $this->_proxy->getScheme() ? $this->_proxy->getScheme() : 'http', |
|
172 | + $this->_proxy->getHost(), |
|
173 | + $this->_proxy->getPort() ? $this->_proxy->getPort() : 8080, |
|
174 | + $timeout); |
|
175 | + if ($socket->isError()) { |
|
176 | + return $socket; |
|
177 | + } |
|
178 | + $socket->write($this->_getRequestLine($method) . "\r\n"); |
|
179 | + $socket->write($this->_getHostLine() . "\r\n"); |
|
180 | + if ($this->_username && $this->_password) { |
|
181 | + $socket->write('Proxy-Authorization: Basic ' . |
|
182 | + base64_encode($this->_username . ':' . $this->_password) . |
|
183 | + "\r\n"); |
|
184 | + } |
|
185 | + $socket->write("Connection: close\r\n"); |
|
186 | + return $socket; |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * HTTP request for a web page. Factory for |
|
192 | + * HttpResponse object. |
|
193 | 193 | * @package SimpleTest |
194 | 194 | * @subpackage WebTester |
195 | - */ |
|
196 | - class SimpleHttpRequest { |
|
197 | - protected $_route; |
|
198 | - protected $_encoding; |
|
199 | - protected $_headers; |
|
200 | - protected $_cookies; |
|
201 | - |
|
202 | - /** |
|
203 | - * Builds the socket request from the different pieces. |
|
204 | - * These include proxy information, URL, cookies, headers, |
|
205 | - * request method and choice of encoding. |
|
206 | - * @param SimpleRoute $route Request route. |
|
207 | - * @param SimpleFormEncoding $encoding Content to send with |
|
208 | - * request. |
|
209 | - * @access public |
|
210 | - */ |
|
211 | - function SimpleHttpRequest($route, $encoding) { |
|
212 | - $this->_route = $route; |
|
213 | - $this->_encoding = $encoding; |
|
214 | - $this->_headers = array(); |
|
215 | - $this->_cookies = array(); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Dispatches the content to the route's socket. |
|
220 | - * @param integer $timeout Connection timeout. |
|
221 | - * @return SimpleHttpResponse A response which may only have |
|
222 | - * an error, but hopefully has a |
|
223 | - * complete web page. |
|
224 | - * @access public |
|
225 | - */ |
|
226 | - function &fetch($timeout) { |
|
227 | - $socket = $this->_route->createConnection($this->_encoding->getMethod(), $timeout); |
|
228 | - if (! $socket->isError()) { |
|
229 | - $this->_dispatchRequest($socket, $this->_encoding); |
|
230 | - } |
|
231 | - $response = $this->_createResponse($socket); |
|
232 | - return $response; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Sends the headers. |
|
237 | - * @param SimpleSocket $socket Open socket. |
|
238 | - * @param string $method HTTP request method, |
|
239 | - * usually GET. |
|
240 | - * @param SimpleFormEncoding $encoding Content to send with request. |
|
241 | - * @access private |
|
242 | - */ |
|
243 | - function _dispatchRequest($socket, $encoding) { |
|
244 | - foreach ($this->_headers as $header_line) { |
|
245 | - $socket->write($header_line . "\r\n"); |
|
246 | - } |
|
247 | - if (count($this->_cookies) > 0) { |
|
248 | - $socket->write("Cookie: " . implode(";", $this->_cookies) . "\r\n"); |
|
249 | - } |
|
250 | - $encoding->writeHeadersTo($socket); |
|
251 | - $socket->write("\r\n"); |
|
252 | - $encoding->writeTo($socket); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Adds a header line to the request. |
|
257 | - * @param string $header_line Text of full header line. |
|
258 | - * @access public |
|
259 | - */ |
|
260 | - function addHeaderLine($header_line) { |
|
261 | - $this->_headers[] = $header_line; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Reads all the relevant cookies from the |
|
266 | - * cookie jar. |
|
267 | - * @param SimpleCookieJar $jar Jar to read |
|
268 | - * @param SimpleUrl $url Url to use for scope. |
|
269 | - * @access public |
|
270 | - */ |
|
271 | - function readCookiesFromJar($jar, $url) { |
|
272 | - $this->_cookies = $jar->selectAsPairs($url); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Wraps the socket in a response parser. |
|
277 | - * @param SimpleSocket $socket Responding socket. |
|
278 | - * @return SimpleHttpResponse Parsed response object. |
|
279 | - * @access protected |
|
280 | - */ |
|
281 | - function &_createResponse($socket) { |
|
282 | - $response = new SimpleHttpResponse( |
|
283 | - $socket, |
|
284 | - $this->_route->getUrl(), |
|
285 | - $this->_encoding); |
|
286 | - return $response; |
|
287 | - } |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Collection of header lines in the response. |
|
195 | + */ |
|
196 | + class SimpleHttpRequest { |
|
197 | + protected $_route; |
|
198 | + protected $_encoding; |
|
199 | + protected $_headers; |
|
200 | + protected $_cookies; |
|
201 | + |
|
202 | + /** |
|
203 | + * Builds the socket request from the different pieces. |
|
204 | + * These include proxy information, URL, cookies, headers, |
|
205 | + * request method and choice of encoding. |
|
206 | + * @param SimpleRoute $route Request route. |
|
207 | + * @param SimpleFormEncoding $encoding Content to send with |
|
208 | + * request. |
|
209 | + * @access public |
|
210 | + */ |
|
211 | + function SimpleHttpRequest($route, $encoding) { |
|
212 | + $this->_route = $route; |
|
213 | + $this->_encoding = $encoding; |
|
214 | + $this->_headers = array(); |
|
215 | + $this->_cookies = array(); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Dispatches the content to the route's socket. |
|
220 | + * @param integer $timeout Connection timeout. |
|
221 | + * @return SimpleHttpResponse A response which may only have |
|
222 | + * an error, but hopefully has a |
|
223 | + * complete web page. |
|
224 | + * @access public |
|
225 | + */ |
|
226 | + function &fetch($timeout) { |
|
227 | + $socket = $this->_route->createConnection($this->_encoding->getMethod(), $timeout); |
|
228 | + if (! $socket->isError()) { |
|
229 | + $this->_dispatchRequest($socket, $this->_encoding); |
|
230 | + } |
|
231 | + $response = $this->_createResponse($socket); |
|
232 | + return $response; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Sends the headers. |
|
237 | + * @param SimpleSocket $socket Open socket. |
|
238 | + * @param string $method HTTP request method, |
|
239 | + * usually GET. |
|
240 | + * @param SimpleFormEncoding $encoding Content to send with request. |
|
241 | + * @access private |
|
242 | + */ |
|
243 | + function _dispatchRequest($socket, $encoding) { |
|
244 | + foreach ($this->_headers as $header_line) { |
|
245 | + $socket->write($header_line . "\r\n"); |
|
246 | + } |
|
247 | + if (count($this->_cookies) > 0) { |
|
248 | + $socket->write("Cookie: " . implode(";", $this->_cookies) . "\r\n"); |
|
249 | + } |
|
250 | + $encoding->writeHeadersTo($socket); |
|
251 | + $socket->write("\r\n"); |
|
252 | + $encoding->writeTo($socket); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Adds a header line to the request. |
|
257 | + * @param string $header_line Text of full header line. |
|
258 | + * @access public |
|
259 | + */ |
|
260 | + function addHeaderLine($header_line) { |
|
261 | + $this->_headers[] = $header_line; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Reads all the relevant cookies from the |
|
266 | + * cookie jar. |
|
267 | + * @param SimpleCookieJar $jar Jar to read |
|
268 | + * @param SimpleUrl $url Url to use for scope. |
|
269 | + * @access public |
|
270 | + */ |
|
271 | + function readCookiesFromJar($jar, $url) { |
|
272 | + $this->_cookies = $jar->selectAsPairs($url); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Wraps the socket in a response parser. |
|
277 | + * @param SimpleSocket $socket Responding socket. |
|
278 | + * @return SimpleHttpResponse Parsed response object. |
|
279 | + * @access protected |
|
280 | + */ |
|
281 | + function &_createResponse($socket) { |
|
282 | + $response = new SimpleHttpResponse( |
|
283 | + $socket, |
|
284 | + $this->_route->getUrl(), |
|
285 | + $this->_encoding); |
|
286 | + return $response; |
|
287 | + } |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Collection of header lines in the response. |
|
292 | 292 | * @package SimpleTest |
293 | 293 | * @subpackage WebTester |
294 | - */ |
|
295 | - class SimpleHttpHeaders { |
|
296 | - protected $_raw_headers; |
|
297 | - protected $_response_code; |
|
298 | - protected $_http_version; |
|
299 | - protected $_mime_type; |
|
300 | - protected $_location; |
|
301 | - protected $_cookies; |
|
302 | - protected $_authentication; |
|
303 | - protected $_realm; |
|
304 | - |
|
305 | - /** |
|
306 | - * Parses the incoming header block. |
|
307 | - * @param string $headers Header block. |
|
308 | - * @access public |
|
309 | - */ |
|
310 | - function SimpleHttpHeaders($headers) { |
|
311 | - $this->_raw_headers = $headers; |
|
312 | - $this->_response_code = false; |
|
313 | - $this->_http_version = false; |
|
314 | - $this->_mime_type = ''; |
|
315 | - $this->_location = false; |
|
316 | - $this->_cookies = array(); |
|
317 | - $this->_authentication = false; |
|
318 | - $this->_realm = false; |
|
319 | - foreach (split("\r\n", $headers) as $header_line) { |
|
320 | - $this->_parseHeaderLine($header_line); |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Accessor for parsed HTTP protocol version. |
|
326 | - * @return integer HTTP error code. |
|
327 | - * @access public |
|
328 | - */ |
|
329 | - function getHttpVersion() { |
|
330 | - return $this->_http_version; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Accessor for raw header block. |
|
335 | - * @return string All headers as raw string. |
|
336 | - * @access public |
|
337 | - */ |
|
338 | - function getRaw() { |
|
339 | - return $this->_raw_headers; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Accessor for parsed HTTP error code. |
|
344 | - * @return integer HTTP error code. |
|
345 | - * @access public |
|
346 | - */ |
|
347 | - function getResponseCode() { |
|
348 | - return (integer)$this->_response_code; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Returns the redirected URL or false if |
|
353 | - * no redirection. |
|
354 | - * @return string URL or false for none. |
|
355 | - * @access public |
|
356 | - */ |
|
357 | - function getLocation() { |
|
358 | - return $this->_location; |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Test to see if the response is a valid redirect. |
|
363 | - * @return boolean True if valid redirect. |
|
364 | - * @access public |
|
365 | - */ |
|
366 | - function isRedirect() { |
|
367 | - return in_array($this->_response_code, array(301, 302, 303, 307)) && |
|
368 | - (boolean)$this->getLocation(); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Test to see if the response is an authentication |
|
373 | - * challenge. |
|
374 | - * @return boolean True if challenge. |
|
375 | - * @access public |
|
376 | - */ |
|
377 | - function isChallenge() { |
|
378 | - return ($this->_response_code == 401) && |
|
379 | - (boolean)$this->_authentication && |
|
380 | - (boolean)$this->_realm; |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * Accessor for MIME type header information. |
|
385 | - * @return string MIME type. |
|
386 | - * @access public |
|
387 | - */ |
|
388 | - function getMimeType() { |
|
389 | - return $this->_mime_type; |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Accessor for authentication type. |
|
394 | - * @return string Type. |
|
395 | - * @access public |
|
396 | - */ |
|
397 | - function getAuthentication() { |
|
398 | - return $this->_authentication; |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Accessor for security realm. |
|
403 | - * @return string Realm. |
|
404 | - * @access public |
|
405 | - */ |
|
406 | - function getRealm() { |
|
407 | - return $this->_realm; |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Writes new cookies to the cookie jar. |
|
412 | - * @param SimpleCookieJar $jar Jar to write to. |
|
413 | - * @param SimpleUrl $url Host and path to write under. |
|
414 | - * @access public |
|
415 | - */ |
|
416 | - function writeCookiesToJar($jar, $url) { |
|
417 | - foreach ($this->_cookies as $cookie) { |
|
418 | - $jar->setCookie( |
|
419 | - $cookie->getName(), |
|
420 | - $cookie->getValue(), |
|
421 | - $url->getHost(), |
|
422 | - $cookie->getPath(), |
|
423 | - $cookie->getExpiry()); |
|
424 | - } |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Called on each header line to accumulate the held |
|
429 | - * data within the class. |
|
430 | - * @param string $header_line One line of header. |
|
431 | - * @access protected |
|
432 | - */ |
|
433 | - function _parseHeaderLine($header_line) { |
|
434 | - if (preg_match('/HTTP\/(\d+\.\d+)\s+(\d+)/i', $header_line, $matches)) { |
|
435 | - $this->_http_version = $matches[1]; |
|
436 | - $this->_response_code = $matches[2]; |
|
437 | - } |
|
438 | - if (preg_match('/Content-type:\s*(.*)/i', $header_line, $matches)) { |
|
439 | - $this->_mime_type = trim($matches[1]); |
|
440 | - } |
|
441 | - if (preg_match('/Location:\s*(.*)/i', $header_line, $matches)) { |
|
442 | - $this->_location = trim($matches[1]); |
|
443 | - } |
|
444 | - if (preg_match('/Set-cookie:(.*)/i', $header_line, $matches)) { |
|
445 | - $this->_cookies[] = $this->_parseCookie($matches[1]); |
|
446 | - } |
|
447 | - if (preg_match('/WWW-Authenticate:\s+(\S+)\s+realm=\"(.*?)\"/i', $header_line, $matches)) { |
|
448 | - $this->_authentication = $matches[1]; |
|
449 | - $this->_realm = trim($matches[2]); |
|
450 | - } |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Parse the Set-cookie content. |
|
455 | - * @param string $cookie_line Text after "Set-cookie:" |
|
456 | - * @return SimpleCookie New cookie object. |
|
457 | - * @access private |
|
458 | - */ |
|
459 | - function _parseCookie($cookie_line) { |
|
460 | - $parts = split(";", $cookie_line); |
|
461 | - $cookie = array(); |
|
462 | - preg_match('/\s*(.*?)\s*=(.*)/', array_shift($parts), $cookie); |
|
463 | - foreach ($parts as $part) { |
|
464 | - if (preg_match('/\s*(.*?)\s*=(.*)/', $part, $matches)) { |
|
465 | - $cookie[$matches[1]] = trim($matches[2]); |
|
466 | - } |
|
467 | - } |
|
468 | - return new SimpleCookie( |
|
469 | - $cookie[1], |
|
470 | - trim($cookie[2]), |
|
471 | - isset($cookie["path"]) ? $cookie["path"] : "", |
|
472 | - isset($cookie["expires"]) ? $cookie["expires"] : false); |
|
473 | - } |
|
474 | - } |
|
475 | - |
|
476 | - /** |
|
477 | - * Basic HTTP response. |
|
294 | + */ |
|
295 | + class SimpleHttpHeaders { |
|
296 | + protected $_raw_headers; |
|
297 | + protected $_response_code; |
|
298 | + protected $_http_version; |
|
299 | + protected $_mime_type; |
|
300 | + protected $_location; |
|
301 | + protected $_cookies; |
|
302 | + protected $_authentication; |
|
303 | + protected $_realm; |
|
304 | + |
|
305 | + /** |
|
306 | + * Parses the incoming header block. |
|
307 | + * @param string $headers Header block. |
|
308 | + * @access public |
|
309 | + */ |
|
310 | + function SimpleHttpHeaders($headers) { |
|
311 | + $this->_raw_headers = $headers; |
|
312 | + $this->_response_code = false; |
|
313 | + $this->_http_version = false; |
|
314 | + $this->_mime_type = ''; |
|
315 | + $this->_location = false; |
|
316 | + $this->_cookies = array(); |
|
317 | + $this->_authentication = false; |
|
318 | + $this->_realm = false; |
|
319 | + foreach (split("\r\n", $headers) as $header_line) { |
|
320 | + $this->_parseHeaderLine($header_line); |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Accessor for parsed HTTP protocol version. |
|
326 | + * @return integer HTTP error code. |
|
327 | + * @access public |
|
328 | + */ |
|
329 | + function getHttpVersion() { |
|
330 | + return $this->_http_version; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Accessor for raw header block. |
|
335 | + * @return string All headers as raw string. |
|
336 | + * @access public |
|
337 | + */ |
|
338 | + function getRaw() { |
|
339 | + return $this->_raw_headers; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Accessor for parsed HTTP error code. |
|
344 | + * @return integer HTTP error code. |
|
345 | + * @access public |
|
346 | + */ |
|
347 | + function getResponseCode() { |
|
348 | + return (integer)$this->_response_code; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Returns the redirected URL or false if |
|
353 | + * no redirection. |
|
354 | + * @return string URL or false for none. |
|
355 | + * @access public |
|
356 | + */ |
|
357 | + function getLocation() { |
|
358 | + return $this->_location; |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Test to see if the response is a valid redirect. |
|
363 | + * @return boolean True if valid redirect. |
|
364 | + * @access public |
|
365 | + */ |
|
366 | + function isRedirect() { |
|
367 | + return in_array($this->_response_code, array(301, 302, 303, 307)) && |
|
368 | + (boolean)$this->getLocation(); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Test to see if the response is an authentication |
|
373 | + * challenge. |
|
374 | + * @return boolean True if challenge. |
|
375 | + * @access public |
|
376 | + */ |
|
377 | + function isChallenge() { |
|
378 | + return ($this->_response_code == 401) && |
|
379 | + (boolean)$this->_authentication && |
|
380 | + (boolean)$this->_realm; |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * Accessor for MIME type header information. |
|
385 | + * @return string MIME type. |
|
386 | + * @access public |
|
387 | + */ |
|
388 | + function getMimeType() { |
|
389 | + return $this->_mime_type; |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Accessor for authentication type. |
|
394 | + * @return string Type. |
|
395 | + * @access public |
|
396 | + */ |
|
397 | + function getAuthentication() { |
|
398 | + return $this->_authentication; |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Accessor for security realm. |
|
403 | + * @return string Realm. |
|
404 | + * @access public |
|
405 | + */ |
|
406 | + function getRealm() { |
|
407 | + return $this->_realm; |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Writes new cookies to the cookie jar. |
|
412 | + * @param SimpleCookieJar $jar Jar to write to. |
|
413 | + * @param SimpleUrl $url Host and path to write under. |
|
414 | + * @access public |
|
415 | + */ |
|
416 | + function writeCookiesToJar($jar, $url) { |
|
417 | + foreach ($this->_cookies as $cookie) { |
|
418 | + $jar->setCookie( |
|
419 | + $cookie->getName(), |
|
420 | + $cookie->getValue(), |
|
421 | + $url->getHost(), |
|
422 | + $cookie->getPath(), |
|
423 | + $cookie->getExpiry()); |
|
424 | + } |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Called on each header line to accumulate the held |
|
429 | + * data within the class. |
|
430 | + * @param string $header_line One line of header. |
|
431 | + * @access protected |
|
432 | + */ |
|
433 | + function _parseHeaderLine($header_line) { |
|
434 | + if (preg_match('/HTTP\/(\d+\.\d+)\s+(\d+)/i', $header_line, $matches)) { |
|
435 | + $this->_http_version = $matches[1]; |
|
436 | + $this->_response_code = $matches[2]; |
|
437 | + } |
|
438 | + if (preg_match('/Content-type:\s*(.*)/i', $header_line, $matches)) { |
|
439 | + $this->_mime_type = trim($matches[1]); |
|
440 | + } |
|
441 | + if (preg_match('/Location:\s*(.*)/i', $header_line, $matches)) { |
|
442 | + $this->_location = trim($matches[1]); |
|
443 | + } |
|
444 | + if (preg_match('/Set-cookie:(.*)/i', $header_line, $matches)) { |
|
445 | + $this->_cookies[] = $this->_parseCookie($matches[1]); |
|
446 | + } |
|
447 | + if (preg_match('/WWW-Authenticate:\s+(\S+)\s+realm=\"(.*?)\"/i', $header_line, $matches)) { |
|
448 | + $this->_authentication = $matches[1]; |
|
449 | + $this->_realm = trim($matches[2]); |
|
450 | + } |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Parse the Set-cookie content. |
|
455 | + * @param string $cookie_line Text after "Set-cookie:" |
|
456 | + * @return SimpleCookie New cookie object. |
|
457 | + * @access private |
|
458 | + */ |
|
459 | + function _parseCookie($cookie_line) { |
|
460 | + $parts = split(";", $cookie_line); |
|
461 | + $cookie = array(); |
|
462 | + preg_match('/\s*(.*?)\s*=(.*)/', array_shift($parts), $cookie); |
|
463 | + foreach ($parts as $part) { |
|
464 | + if (preg_match('/\s*(.*?)\s*=(.*)/', $part, $matches)) { |
|
465 | + $cookie[$matches[1]] = trim($matches[2]); |
|
466 | + } |
|
467 | + } |
|
468 | + return new SimpleCookie( |
|
469 | + $cookie[1], |
|
470 | + trim($cookie[2]), |
|
471 | + isset($cookie["path"]) ? $cookie["path"] : "", |
|
472 | + isset($cookie["expires"]) ? $cookie["expires"] : false); |
|
473 | + } |
|
474 | + } |
|
475 | + |
|
476 | + /** |
|
477 | + * Basic HTTP response. |
|
478 | 478 | * @package SimpleTest |
479 | 479 | * @subpackage WebTester |
480 | - */ |
|
481 | - class SimpleHttpResponse extends SimpleStickyError { |
|
482 | - protected $_url; |
|
483 | - protected $_encoding; |
|
484 | - protected $_sent; |
|
485 | - protected $_content; |
|
486 | - protected $_headers; |
|
487 | - |
|
488 | - /** |
|
489 | - * Constructor. Reads and parses the incoming |
|
490 | - * content and headers. |
|
491 | - * @param SimpleSocket $socket Network connection to fetch |
|
492 | - * response text from. |
|
493 | - * @param SimpleUrl $url Resource name. |
|
494 | - * @param mixed $encoding Record of content sent. |
|
495 | - * @access public |
|
496 | - */ |
|
497 | - function SimpleHttpResponse($socket, $url, $encoding) { |
|
498 | - $this->SimpleStickyError(); |
|
499 | - $this->_url = $url; |
|
500 | - $this->_encoding = $encoding; |
|
501 | - $this->_sent = $socket->getSent(); |
|
502 | - $this->_content = false; |
|
503 | - $raw = $this->_readAll($socket); |
|
504 | - if ($socket->isError()) { |
|
505 | - $this->_setError('Error reading socket [' . $socket->getError() . ']'); |
|
506 | - return; |
|
507 | - } |
|
508 | - $this->_parse($raw); |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Splits up the headers and the rest of the content. |
|
513 | - * @param string $raw Content to parse. |
|
514 | - * @access private |
|
515 | - */ |
|
516 | - function _parse($raw) { |
|
517 | - if (! $raw) { |
|
518 | - $this->_setError('Nothing fetched'); |
|
519 | - $this->_headers = new SimpleHttpHeaders(''); |
|
520 | - } elseif (! strstr($raw, "\r\n\r\n")) { |
|
521 | - $this->_setError('Could not split headers from content'); |
|
522 | - $this->_headers = new SimpleHttpHeaders($raw); |
|
523 | - } else { |
|
524 | - list($headers, $this->_content) = split("\r\n\r\n", $raw, 2); |
|
525 | - $this->_headers = new SimpleHttpHeaders($headers); |
|
526 | - } |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * Original request method. |
|
531 | - * @return string GET, POST or HEAD. |
|
532 | - * @access public |
|
533 | - */ |
|
534 | - function getMethod() { |
|
535 | - return $this->_encoding->getMethod(); |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Resource name. |
|
540 | - * @return SimpleUrl Current url. |
|
541 | - * @access public |
|
542 | - */ |
|
543 | - function getUrl() { |
|
544 | - return $this->_url; |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Original request data. |
|
549 | - * @return mixed Sent content. |
|
550 | - * @access public |
|
551 | - */ |
|
552 | - function getRequestData() { |
|
553 | - return $this->_encoding; |
|
554 | - } |
|
555 | - |
|
556 | - /** |
|
557 | - * Raw request that was sent down the wire. |
|
558 | - * @return string Bytes actually sent. |
|
559 | - * @access public |
|
560 | - */ |
|
561 | - function getSent() { |
|
562 | - return $this->_sent; |
|
563 | - } |
|
564 | - |
|
565 | - /** |
|
566 | - * Accessor for the content after the last |
|
567 | - * header line. |
|
568 | - * @return string All content. |
|
569 | - * @access public |
|
570 | - */ |
|
571 | - function getContent() { |
|
572 | - return $this->_content; |
|
573 | - } |
|
574 | - |
|
575 | - /** |
|
576 | - * Accessor for header block. The response is the |
|
577 | - * combination of this and the content. |
|
578 | - * @return SimpleHeaders Wrapped header block. |
|
579 | - * @access public |
|
580 | - */ |
|
581 | - function getHeaders() { |
|
582 | - return $this->_headers; |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Accessor for any new cookies. |
|
587 | - * @return array List of new cookies. |
|
588 | - * @access public |
|
589 | - */ |
|
590 | - function getNewCookies() { |
|
591 | - return $this->_headers->getNewCookies(); |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * Reads the whole of the socket output into a |
|
596 | - * single string. |
|
597 | - * @param SimpleSocket $socket Unread socket. |
|
598 | - * @return string Raw output if successful |
|
599 | - * else false. |
|
600 | - * @access private |
|
601 | - */ |
|
602 | - function _readAll($socket) { |
|
603 | - $all = ''; |
|
604 | - while (! $this->_isLastPacket($next = $socket->read())) { |
|
605 | - $all .= $next; |
|
606 | - } |
|
607 | - return $all; |
|
608 | - } |
|
609 | - |
|
610 | - /** |
|
611 | - * Test to see if the packet from the socket is the |
|
612 | - * last one. |
|
613 | - * @param string $packet Chunk to interpret. |
|
614 | - * @return boolean True if empty or EOF. |
|
615 | - * @access private |
|
616 | - */ |
|
617 | - function _isLastPacket($packet) { |
|
618 | - if (is_string($packet)) { |
|
619 | - return $packet === ''; |
|
620 | - } |
|
621 | - return ! $packet; |
|
622 | - } |
|
623 | - } |
|
624 | 480 | \ No newline at end of file |
481 | + */ |
|
482 | + class SimpleHttpResponse extends SimpleStickyError { |
|
483 | + protected $_url; |
|
484 | + protected $_encoding; |
|
485 | + protected $_sent; |
|
486 | + protected $_content; |
|
487 | + protected $_headers; |
|
488 | + |
|
489 | + /** |
|
490 | + * Constructor. Reads and parses the incoming |
|
491 | + * content and headers. |
|
492 | + * @param SimpleSocket $socket Network connection to fetch |
|
493 | + * response text from. |
|
494 | + * @param SimpleUrl $url Resource name. |
|
495 | + * @param mixed $encoding Record of content sent. |
|
496 | + * @access public |
|
497 | + */ |
|
498 | + function SimpleHttpResponse($socket, $url, $encoding) { |
|
499 | + $this->SimpleStickyError(); |
|
500 | + $this->_url = $url; |
|
501 | + $this->_encoding = $encoding; |
|
502 | + $this->_sent = $socket->getSent(); |
|
503 | + $this->_content = false; |
|
504 | + $raw = $this->_readAll($socket); |
|
505 | + if ($socket->isError()) { |
|
506 | + $this->_setError('Error reading socket [' . $socket->getError() . ']'); |
|
507 | + return; |
|
508 | + } |
|
509 | + $this->_parse($raw); |
|
510 | + } |
|
511 | + |
|
512 | + /** |
|
513 | + * Splits up the headers and the rest of the content. |
|
514 | + * @param string $raw Content to parse. |
|
515 | + * @access private |
|
516 | + */ |
|
517 | + function _parse($raw) { |
|
518 | + if (! $raw) { |
|
519 | + $this->_setError('Nothing fetched'); |
|
520 | + $this->_headers = new SimpleHttpHeaders(''); |
|
521 | + } elseif (! strstr($raw, "\r\n\r\n")) { |
|
522 | + $this->_setError('Could not split headers from content'); |
|
523 | + $this->_headers = new SimpleHttpHeaders($raw); |
|
524 | + } else { |
|
525 | + list($headers, $this->_content) = split("\r\n\r\n", $raw, 2); |
|
526 | + $this->_headers = new SimpleHttpHeaders($headers); |
|
527 | + } |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * Original request method. |
|
532 | + * @return string GET, POST or HEAD. |
|
533 | + * @access public |
|
534 | + */ |
|
535 | + function getMethod() { |
|
536 | + return $this->_encoding->getMethod(); |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * Resource name. |
|
541 | + * @return SimpleUrl Current url. |
|
542 | + * @access public |
|
543 | + */ |
|
544 | + function getUrl() { |
|
545 | + return $this->_url; |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Original request data. |
|
550 | + * @return mixed Sent content. |
|
551 | + * @access public |
|
552 | + */ |
|
553 | + function getRequestData() { |
|
554 | + return $this->_encoding; |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Raw request that was sent down the wire. |
|
559 | + * @return string Bytes actually sent. |
|
560 | + * @access public |
|
561 | + */ |
|
562 | + function getSent() { |
|
563 | + return $this->_sent; |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Accessor for the content after the last |
|
568 | + * header line. |
|
569 | + * @return string All content. |
|
570 | + * @access public |
|
571 | + */ |
|
572 | + function getContent() { |
|
573 | + return $this->_content; |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * Accessor for header block. The response is the |
|
578 | + * combination of this and the content. |
|
579 | + * @return SimpleHeaders Wrapped header block. |
|
580 | + * @access public |
|
581 | + */ |
|
582 | + function getHeaders() { |
|
583 | + return $this->_headers; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * Accessor for any new cookies. |
|
588 | + * @return array List of new cookies. |
|
589 | + * @access public |
|
590 | + */ |
|
591 | + function getNewCookies() { |
|
592 | + return $this->_headers->getNewCookies(); |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Reads the whole of the socket output into a |
|
597 | + * single string. |
|
598 | + * @param SimpleSocket $socket Unread socket. |
|
599 | + * @return string Raw output if successful |
|
600 | + * else false. |
|
601 | + * @access private |
|
602 | + */ |
|
603 | + function _readAll($socket) { |
|
604 | + $all = ''; |
|
605 | + while (! $this->_isLastPacket($next = $socket->read())) { |
|
606 | + $all .= $next; |
|
607 | + } |
|
608 | + return $all; |
|
609 | + } |
|
610 | + |
|
611 | + /** |
|
612 | + * Test to see if the packet from the socket is the |
|
613 | + * last one. |
|
614 | + * @param string $packet Chunk to interpret. |
|
615 | + * @return boolean True if empty or EOF. |
|
616 | + * @access private |
|
617 | + */ |
|
618 | + function _isLastPacket($packet) { |
|
619 | + if (is_string($packet)) { |
|
620 | + return $packet === ''; |
|
621 | + } |
|
622 | + return ! $packet; |
|
623 | + } |
|
624 | + } |
|
625 | 625 | \ No newline at end of file |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $this->_url->getHost(), |
80 | 80 | $this->_url->getPort() ? $this->_url->getPort() : $default_port, |
81 | 81 | $timeout); |
82 | - if (! $socket->isError()) { |
|
82 | + if (!$socket->isError()) { |
|
83 | 83 | $socket->write($this->_getRequestLine($method) . "\r\n"); |
84 | 84 | $socket->write($this->_getHostLine() . "\r\n"); |
85 | 85 | $socket->write("Connection: close\r\n"); |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | */ |
226 | 226 | function &fetch($timeout) { |
227 | 227 | $socket = $this->_route->createConnection($this->_encoding->getMethod(), $timeout); |
228 | - if (! $socket->isError()) { |
|
228 | + if (!$socket->isError()) { |
|
229 | 229 | $this->_dispatchRequest($socket, $this->_encoding); |
230 | 230 | } |
231 | 231 | $response = $this->_createResponse($socket); |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * @access public |
346 | 346 | */ |
347 | 347 | function getResponseCode() { |
348 | - return (integer)$this->_response_code; |
|
348 | + return (integer) $this->_response_code; |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | */ |
366 | 366 | function isRedirect() { |
367 | 367 | return in_array($this->_response_code, array(301, 302, 303, 307)) && |
368 | - (boolean)$this->getLocation(); |
|
368 | + (boolean) $this->getLocation(); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | */ |
377 | 377 | function isChallenge() { |
378 | 378 | return ($this->_response_code == 401) && |
379 | - (boolean)$this->_authentication && |
|
380 | - (boolean)$this->_realm; |
|
379 | + (boolean) $this->_authentication && |
|
380 | + (boolean) $this->_realm; |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -514,10 +514,10 @@ discard block |
||
514 | 514 | * @access private |
515 | 515 | */ |
516 | 516 | function _parse($raw) { |
517 | - if (! $raw) { |
|
517 | + if (!$raw) { |
|
518 | 518 | $this->_setError('Nothing fetched'); |
519 | 519 | $this->_headers = new SimpleHttpHeaders(''); |
520 | - } elseif (! strstr($raw, "\r\n\r\n")) { |
|
520 | + } elseif (!strstr($raw, "\r\n\r\n")) { |
|
521 | 521 | $this->_setError('Could not split headers from content'); |
522 | 522 | $this->_headers = new SimpleHttpHeaders($raw); |
523 | 523 | } else { |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | */ |
602 | 602 | function _readAll($socket) { |
603 | 603 | $all = ''; |
604 | - while (! $this->_isLastPacket($next = $socket->read())) { |
|
604 | + while (!$this->_isLastPacket($next = $socket->read())) { |
|
605 | 605 | $all .= $next; |
606 | 606 | } |
607 | 607 | return $all; |
@@ -618,6 +618,6 @@ discard block |
||
618 | 618 | if (is_string($packet)) { |
619 | 619 | return $packet === ''; |
620 | 620 | } |
621 | - return ! $packet; |
|
621 | + return !$packet; |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | \ No newline at end of file |