@@ -85,7 +85,7 @@ |
||
85 | 85 | |
86 | 86 | /** |
87 | 87 | * Accessor for current identity. |
88 | - * @return string Last succesful password. |
|
88 | + * @return boolean Last succesful password. |
|
89 | 89 | * @access public |
90 | 90 | */ |
91 | 91 | function getPassword() { |
@@ -1,237 +1,237 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * Base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage WebTester |
|
6 | - * @version $Id: authentication.php 1532 2006-12-01 12:28:55Z xue $ |
|
7 | - */ |
|
8 | - /** |
|
9 | - * include http class |
|
10 | - */ |
|
11 | - require_once(dirname(__FILE__) . '/http.php'); |
|
12 | - |
|
13 | - /** |
|
14 | - * Represents a single security realm's identity. |
|
2 | + /** |
|
3 | + * Base include file for SimpleTest |
|
4 | + * @package SimpleTest |
|
5 | + * @subpackage WebTester |
|
6 | + * @version $Id: authentication.php 1532 2006-12-01 12:28:55Z xue $ |
|
7 | + */ |
|
8 | + /** |
|
9 | + * include http class |
|
10 | + */ |
|
11 | + require_once(dirname(__FILE__) . '/http.php'); |
|
12 | + |
|
13 | + /** |
|
14 | + * Represents a single security realm's identity. |
|
15 | 15 | * @package SimpleTest |
16 | 16 | * @subpackage WebTester |
17 | - */ |
|
18 | - class SimpleRealm { |
|
19 | - protected $_type; |
|
20 | - protected $_root; |
|
21 | - protected $_username; |
|
22 | - protected $_password; |
|
23 | - |
|
24 | - /** |
|
25 | - * Starts with the initial entry directory. |
|
26 | - * @param string $type Authentication type for this |
|
27 | - * realm. Only Basic authentication |
|
28 | - * is currently supported. |
|
29 | - * @param SimpleUrl $url Somewhere in realm. |
|
30 | - * @access public |
|
31 | - */ |
|
32 | - function SimpleRealm($type, $url) { |
|
33 | - $this->_type = $type; |
|
34 | - $this->_root = $url->getBasePath(); |
|
35 | - $this->_username = false; |
|
36 | - $this->_password = false; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Adds another location to the realm. |
|
41 | - * @param SimpleUrl $url Somewhere in realm. |
|
42 | - * @access public |
|
43 | - */ |
|
44 | - function stretch($url) { |
|
45 | - $this->_root = $this->_getCommonPath($this->_root, $url->getPath()); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Finds the common starting path. |
|
50 | - * @param string $first Path to compare. |
|
51 | - * @param string $second Path to compare. |
|
52 | - * @return string Common directories. |
|
53 | - * @access private |
|
54 | - */ |
|
55 | - function _getCommonPath($first, $second) { |
|
56 | - $first = explode('/', $first); |
|
57 | - $second = explode('/', $second); |
|
58 | - for ($i = 0; $i < min(count($first), count($second)); $i++) { |
|
59 | - if ($first[$i] != $second[$i]) { |
|
60 | - return implode('/', array_slice($first, 0, $i)) . '/'; |
|
61 | - } |
|
62 | - } |
|
63 | - return implode('/', $first) . '/'; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Sets the identity to try within this realm. |
|
68 | - * @param string $username Username in authentication dialog. |
|
69 | - * @param string $username Password in authentication dialog. |
|
70 | - * @access public |
|
71 | - */ |
|
72 | - function setIdentity($username, $password) { |
|
73 | - $this->_username = $username; |
|
74 | - $this->_password = $password; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Accessor for current identity. |
|
79 | - * @return string Last succesful username. |
|
80 | - * @access public |
|
81 | - */ |
|
82 | - function getUsername() { |
|
83 | - return $this->_username; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Accessor for current identity. |
|
88 | - * @return string Last succesful password. |
|
89 | - * @access public |
|
90 | - */ |
|
91 | - function getPassword() { |
|
92 | - return $this->_password; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Test to see if the URL is within the directory |
|
97 | - * tree of the realm. |
|
98 | - * @param SimpleUrl $url URL to test. |
|
99 | - * @return boolean True if subpath. |
|
100 | - * @access public |
|
101 | - */ |
|
102 | - function isWithin($url) { |
|
103 | - if ($this->_isIn($this->_root, $url->getBasePath())) { |
|
104 | - return true; |
|
105 | - } |
|
106 | - if ($this->_isIn($this->_root, $url->getBasePath() . $url->getPage() . '/')) { |
|
107 | - return true; |
|
108 | - } |
|
109 | - return false; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Tests to see if one string is a substring of |
|
114 | - * another. |
|
115 | - * @param string $part Small bit. |
|
116 | - * @param string $whole Big bit. |
|
117 | - * @return boolean True if the small bit is |
|
118 | - * in the big bit. |
|
119 | - * @access private |
|
120 | - */ |
|
121 | - function _isIn($part, $whole) { |
|
122 | - return strpos($whole, $part) === 0; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Manages security realms. |
|
17 | + */ |
|
18 | + class SimpleRealm { |
|
19 | + protected $_type; |
|
20 | + protected $_root; |
|
21 | + protected $_username; |
|
22 | + protected $_password; |
|
23 | + |
|
24 | + /** |
|
25 | + * Starts with the initial entry directory. |
|
26 | + * @param string $type Authentication type for this |
|
27 | + * realm. Only Basic authentication |
|
28 | + * is currently supported. |
|
29 | + * @param SimpleUrl $url Somewhere in realm. |
|
30 | + * @access public |
|
31 | + */ |
|
32 | + function SimpleRealm($type, $url) { |
|
33 | + $this->_type = $type; |
|
34 | + $this->_root = $url->getBasePath(); |
|
35 | + $this->_username = false; |
|
36 | + $this->_password = false; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Adds another location to the realm. |
|
41 | + * @param SimpleUrl $url Somewhere in realm. |
|
42 | + * @access public |
|
43 | + */ |
|
44 | + function stretch($url) { |
|
45 | + $this->_root = $this->_getCommonPath($this->_root, $url->getPath()); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Finds the common starting path. |
|
50 | + * @param string $first Path to compare. |
|
51 | + * @param string $second Path to compare. |
|
52 | + * @return string Common directories. |
|
53 | + * @access private |
|
54 | + */ |
|
55 | + function _getCommonPath($first, $second) { |
|
56 | + $first = explode('/', $first); |
|
57 | + $second = explode('/', $second); |
|
58 | + for ($i = 0; $i < min(count($first), count($second)); $i++) { |
|
59 | + if ($first[$i] != $second[$i]) { |
|
60 | + return implode('/', array_slice($first, 0, $i)) . '/'; |
|
61 | + } |
|
62 | + } |
|
63 | + return implode('/', $first) . '/'; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Sets the identity to try within this realm. |
|
68 | + * @param string $username Username in authentication dialog. |
|
69 | + * @param string $username Password in authentication dialog. |
|
70 | + * @access public |
|
71 | + */ |
|
72 | + function setIdentity($username, $password) { |
|
73 | + $this->_username = $username; |
|
74 | + $this->_password = $password; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Accessor for current identity. |
|
79 | + * @return string Last succesful username. |
|
80 | + * @access public |
|
81 | + */ |
|
82 | + function getUsername() { |
|
83 | + return $this->_username; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Accessor for current identity. |
|
88 | + * @return string Last succesful password. |
|
89 | + * @access public |
|
90 | + */ |
|
91 | + function getPassword() { |
|
92 | + return $this->_password; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Test to see if the URL is within the directory |
|
97 | + * tree of the realm. |
|
98 | + * @param SimpleUrl $url URL to test. |
|
99 | + * @return boolean True if subpath. |
|
100 | + * @access public |
|
101 | + */ |
|
102 | + function isWithin($url) { |
|
103 | + if ($this->_isIn($this->_root, $url->getBasePath())) { |
|
104 | + return true; |
|
105 | + } |
|
106 | + if ($this->_isIn($this->_root, $url->getBasePath() . $url->getPage() . '/')) { |
|
107 | + return true; |
|
108 | + } |
|
109 | + return false; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Tests to see if one string is a substring of |
|
114 | + * another. |
|
115 | + * @param string $part Small bit. |
|
116 | + * @param string $whole Big bit. |
|
117 | + * @return boolean True if the small bit is |
|
118 | + * in the big bit. |
|
119 | + * @access private |
|
120 | + */ |
|
121 | + function _isIn($part, $whole) { |
|
122 | + return strpos($whole, $part) === 0; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Manages security realms. |
|
128 | 128 | * @package SimpleTest |
129 | 129 | * @subpackage WebTester |
130 | - */ |
|
131 | - class SimpleAuthenticator { |
|
132 | - protected $_realms; |
|
133 | - |
|
134 | - /** |
|
135 | - * Clears the realms. |
|
136 | - * @access public |
|
137 | - */ |
|
138 | - function SimpleAuthenticator() { |
|
139 | - $this->restartSession(); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Starts with no realms set up. |
|
144 | - * @access public |
|
145 | - */ |
|
146 | - function restartSession() { |
|
147 | - $this->_realms = array(); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Adds a new realm centered the current URL. |
|
152 | - * Browsers vary wildly on their behaviour in this |
|
153 | - * regard. Mozilla ignores the realm and presents |
|
154 | - * only when challenged, wasting bandwidth. IE |
|
155 | - * just carries on presenting until a new challenge |
|
156 | - * occours. SimpleTest tries to follow the spirit of |
|
157 | - * the original standards committee and treats the |
|
158 | - * base URL as the root of a file tree shaped realm. |
|
159 | - * @param SimpleUrl $url Base of realm. |
|
160 | - * @param string $type Authentication type for this |
|
161 | - * realm. Only Basic authentication |
|
162 | - * is currently supported. |
|
163 | - * @param string $realm Name of realm. |
|
164 | - * @access public |
|
165 | - */ |
|
166 | - function addRealm($url, $type, $realm) { |
|
167 | - $this->_realms[$url->getHost()][$realm] = new SimpleRealm($type, $url); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Sets the current identity to be presented |
|
172 | - * against that realm. |
|
173 | - * @param string $host Server hosting realm. |
|
174 | - * @param string $realm Name of realm. |
|
175 | - * @param string $username Username for realm. |
|
176 | - * @param string $password Password for realm. |
|
177 | - * @access public |
|
178 | - */ |
|
179 | - function setIdentityForRealm($host, $realm, $username, $password) { |
|
180 | - if (isset($this->_realms[$host][$realm])) { |
|
181 | - $this->_realms[$host][$realm]->setIdentity($username, $password); |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Finds the name of the realm by comparing URLs. |
|
187 | - * @param SimpleUrl $url URL to test. |
|
188 | - * @return SimpleRealm Name of realm. |
|
189 | - * @access private |
|
190 | - */ |
|
191 | - function _findRealmFromUrl($url) { |
|
192 | - if (! isset($this->_realms[$url->getHost()])) { |
|
193 | - return false; |
|
194 | - } |
|
195 | - foreach ($this->_realms[$url->getHost()] as $name => $realm) { |
|
196 | - if ($realm->isWithin($url)) { |
|
197 | - return $realm; |
|
198 | - } |
|
199 | - } |
|
200 | - return false; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Presents the appropriate headers for this location. |
|
205 | - * @param SimpleHttpRequest $request Request to modify. |
|
206 | - * @param SimpleUrl $url Base of realm. |
|
207 | - * @access public |
|
208 | - */ |
|
209 | - function addHeaders($request, $url) { |
|
210 | - if ($url->getUsername() && $url->getPassword()) { |
|
211 | - $username = $url->getUsername(); |
|
212 | - $password = $url->getPassword(); |
|
213 | - } elseif ($realm = $this->_findRealmFromUrl($url)) { |
|
214 | - $username = $realm->getUsername(); |
|
215 | - $password = $realm->getPassword(); |
|
216 | - } else { |
|
217 | - return; |
|
218 | - } |
|
219 | - $this->addBasicHeaders($request, $username, $password); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Presents the appropriate headers for this |
|
224 | - * location for basic authentication. |
|
225 | - * @param SimpleHttpRequest $request Request to modify. |
|
226 | - * @param string $username Username for realm. |
|
227 | - * @param string $password Password for realm. |
|
228 | - * @access public |
|
229 | - * @static |
|
230 | - */ |
|
231 | - static function addBasicHeaders($request, $username, $password) { |
|
232 | - if ($username && $password) { |
|
233 | - $request->addHeaderLine( |
|
234 | - 'Authorization: Basic ' . base64_encode("$username:$password")); |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
238 | 130 | \ No newline at end of file |
131 | + */ |
|
132 | + class SimpleAuthenticator { |
|
133 | + protected $_realms; |
|
134 | + |
|
135 | + /** |
|
136 | + * Clears the realms. |
|
137 | + * @access public |
|
138 | + */ |
|
139 | + function SimpleAuthenticator() { |
|
140 | + $this->restartSession(); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Starts with no realms set up. |
|
145 | + * @access public |
|
146 | + */ |
|
147 | + function restartSession() { |
|
148 | + $this->_realms = array(); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Adds a new realm centered the current URL. |
|
153 | + * Browsers vary wildly on their behaviour in this |
|
154 | + * regard. Mozilla ignores the realm and presents |
|
155 | + * only when challenged, wasting bandwidth. IE |
|
156 | + * just carries on presenting until a new challenge |
|
157 | + * occours. SimpleTest tries to follow the spirit of |
|
158 | + * the original standards committee and treats the |
|
159 | + * base URL as the root of a file tree shaped realm. |
|
160 | + * @param SimpleUrl $url Base of realm. |
|
161 | + * @param string $type Authentication type for this |
|
162 | + * realm. Only Basic authentication |
|
163 | + * is currently supported. |
|
164 | + * @param string $realm Name of realm. |
|
165 | + * @access public |
|
166 | + */ |
|
167 | + function addRealm($url, $type, $realm) { |
|
168 | + $this->_realms[$url->getHost()][$realm] = new SimpleRealm($type, $url); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Sets the current identity to be presented |
|
173 | + * against that realm. |
|
174 | + * @param string $host Server hosting realm. |
|
175 | + * @param string $realm Name of realm. |
|
176 | + * @param string $username Username for realm. |
|
177 | + * @param string $password Password for realm. |
|
178 | + * @access public |
|
179 | + */ |
|
180 | + function setIdentityForRealm($host, $realm, $username, $password) { |
|
181 | + if (isset($this->_realms[$host][$realm])) { |
|
182 | + $this->_realms[$host][$realm]->setIdentity($username, $password); |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Finds the name of the realm by comparing URLs. |
|
188 | + * @param SimpleUrl $url URL to test. |
|
189 | + * @return SimpleRealm Name of realm. |
|
190 | + * @access private |
|
191 | + */ |
|
192 | + function _findRealmFromUrl($url) { |
|
193 | + if (! isset($this->_realms[$url->getHost()])) { |
|
194 | + return false; |
|
195 | + } |
|
196 | + foreach ($this->_realms[$url->getHost()] as $name => $realm) { |
|
197 | + if ($realm->isWithin($url)) { |
|
198 | + return $realm; |
|
199 | + } |
|
200 | + } |
|
201 | + return false; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Presents the appropriate headers for this location. |
|
206 | + * @param SimpleHttpRequest $request Request to modify. |
|
207 | + * @param SimpleUrl $url Base of realm. |
|
208 | + * @access public |
|
209 | + */ |
|
210 | + function addHeaders($request, $url) { |
|
211 | + if ($url->getUsername() && $url->getPassword()) { |
|
212 | + $username = $url->getUsername(); |
|
213 | + $password = $url->getPassword(); |
|
214 | + } elseif ($realm = $this->_findRealmFromUrl($url)) { |
|
215 | + $username = $realm->getUsername(); |
|
216 | + $password = $realm->getPassword(); |
|
217 | + } else { |
|
218 | + return; |
|
219 | + } |
|
220 | + $this->addBasicHeaders($request, $username, $password); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Presents the appropriate headers for this |
|
225 | + * location for basic authentication. |
|
226 | + * @param SimpleHttpRequest $request Request to modify. |
|
227 | + * @param string $username Username for realm. |
|
228 | + * @param string $password Password for realm. |
|
229 | + * @access public |
|
230 | + * @static |
|
231 | + */ |
|
232 | + static function addBasicHeaders($request, $username, $password) { |
|
233 | + if ($username && $password) { |
|
234 | + $request->addHeaderLine( |
|
235 | + 'Authorization: Basic ' . base64_encode("$username:$password")); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | 239 | \ No newline at end of file |
@@ -189,7 +189,7 @@ |
||
189 | 189 | * @access private |
190 | 190 | */ |
191 | 191 | function _findRealmFromUrl($url) { |
192 | - if (! isset($this->_realms[$url->getHost()])) { |
|
192 | + if (!isset($this->_realms[$url->getHost()])) { |
|
193 | 193 | return false; |
194 | 194 | } |
195 | 195 | foreach ($this->_realms[$url->getHost()] as $name => $realm) { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | /** |
98 | 98 | * Parameters of last fetch from current history |
99 | 99 | * position. |
100 | - * @return SimpleFormEncoding Post parameters. |
|
100 | + * @return SimpleEncoding Post parameters. |
|
101 | 101 | * @access public |
102 | 102 | */ |
103 | 103 | function getParameters() { |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | |
186 | 186 | /** |
187 | 187 | * Creates the underlying user agent. |
188 | - * @return SimpleFetcher Content fetcher. |
|
188 | + * @return SimpleUserAgent Content fetcher. |
|
189 | 189 | * @access protected |
190 | 190 | */ |
191 | 191 | function &_createUserAgent() { |
@@ -311,9 +311,9 @@ discard block |
||
311 | 311 | |
312 | 312 | /** |
313 | 313 | * Fetches a page and makes it the current page/frame. |
314 | - * @param string/SimpleUrl $url Target to fetch as string. |
|
314 | + * @param SimpleUrl $url Target to fetch as string. |
|
315 | 315 | * @param SimplePostEncoding $parameters POST parameters. |
316 | - * @return string Raw content of page. |
|
316 | + * @return boolean Raw content of page. |
|
317 | 317 | * @access private |
318 | 318 | */ |
319 | 319 | function _loadPage($url, $parameters) { |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * Fetches a frame into the existing frameset replacing the |
329 | 329 | * original. |
330 | 330 | * @param array $frames List of names to drill down. |
331 | - * @param string/SimpleUrl $url Target to fetch as string. |
|
331 | + * @param SimpleUrl $url Target to fetch as string. |
|
332 | 332 | * @param SimpleFormEncoding $parameters POST parameters. |
333 | 333 | * @return string Raw content of page. |
334 | 334 | * @access private |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | /** |
454 | 454 | * Fetches the page content with a HEAD request. |
455 | 455 | * Will affect cookies, but will not change the base URL. |
456 | - * @param string/SimpleUrl $url Target to fetch as string. |
|
456 | + * @param string $url Target to fetch as string. |
|
457 | 457 | * @param hash/SimpleHeadEncoding $parameters Additional parameters for |
458 | 458 | * HEAD request. |
459 | 459 | * @return boolean True if successful. |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | |
473 | 473 | /** |
474 | 474 | * Fetches the page content with a simple GET request. |
475 | - * @param string/SimpleUrl $url Target to fetch. |
|
475 | + * @param string $url Target to fetch. |
|
476 | 476 | * @param hash/SimpleFormEncoding $parameters Additional parameters for |
477 | 477 | * GET request. |
478 | 478 | * @return string Content of page or false. |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | |
491 | 491 | /** |
492 | 492 | * Fetches the page content with a POST request. |
493 | - * @param string/SimpleUrl $url Target to fetch as string. |
|
493 | + * @param string $url Target to fetch as string. |
|
494 | 494 | * @param hash/SimpleFormEncoding $parameters POST parameters. |
495 | 495 | * @return string Content of page. |
496 | 496 | * @access public |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | |
598 | 598 | /** |
599 | 599 | * Accessor for a breakdown of the frameset. |
600 | - * @return array Hash tree of frames by name |
|
600 | + * @return string Hash tree of frames by name |
|
601 | 601 | * or index if no name. |
602 | 602 | * @access public |
603 | 603 | */ |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | |
725 | 725 | /** |
726 | 726 | * Accessor for raw page information. |
727 | - * @return string Original text content of web page. |
|
727 | + * @return boolean Original text content of web page. |
|
728 | 728 | * @access public |
729 | 729 | */ |
730 | 730 | function getContent() { |
@@ -1,1056 +1,1056 @@ |
||
1 | 1 | <?php |
2 | - /** |
|
3 | - * Base include file for SimpleTest |
|
4 | - * @package SimpleTest |
|
5 | - * @subpackage WebTester |
|
6 | - * @version $Id: browser.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: browser.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__) . '/simpletest.php'); |
|
13 | - require_once(dirname(__FILE__) . '/http.php'); |
|
14 | - require_once(dirname(__FILE__) . '/encoding.php'); |
|
15 | - require_once(dirname(__FILE__) . '/page.php'); |
|
16 | - require_once(dirname(__FILE__) . '/selector.php'); |
|
17 | - require_once(dirname(__FILE__) . '/frames.php'); |
|
18 | - require_once(dirname(__FILE__) . '/user_agent.php'); |
|
19 | - /**#@-*/ |
|
20 | - |
|
21 | - if (!defined('DEFAULT_MAX_NESTED_FRAMES')) { |
|
22 | - define('DEFAULT_MAX_NESTED_FRAMES', 3); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Browser history list. |
|
12 | + require_once(dirname(__FILE__) . '/simpletest.php'); |
|
13 | + require_once(dirname(__FILE__) . '/http.php'); |
|
14 | + require_once(dirname(__FILE__) . '/encoding.php'); |
|
15 | + require_once(dirname(__FILE__) . '/page.php'); |
|
16 | + require_once(dirname(__FILE__) . '/selector.php'); |
|
17 | + require_once(dirname(__FILE__) . '/frames.php'); |
|
18 | + require_once(dirname(__FILE__) . '/user_agent.php'); |
|
19 | + /**#@-*/ |
|
20 | + |
|
21 | + if (!defined('DEFAULT_MAX_NESTED_FRAMES')) { |
|
22 | + define('DEFAULT_MAX_NESTED_FRAMES', 3); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Browser history list. |
|
27 | 27 | * @package SimpleTest |
28 | 28 | * @subpackage WebTester |
29 | - */ |
|
30 | - class SimpleBrowserHistory { |
|
31 | - protected $_sequence; |
|
32 | - protected $_position; |
|
33 | - |
|
34 | - /** |
|
35 | - * Starts empty. |
|
36 | - * @access public |
|
37 | - */ |
|
38 | - function SimpleBrowserHistory() { |
|
39 | - $this->_sequence = array(); |
|
40 | - $this->_position = -1; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Test for no entries yet. |
|
45 | - * @return boolean True if empty. |
|
46 | - * @access private |
|
47 | - */ |
|
48 | - function _isEmpty() { |
|
49 | - return ($this->_position == -1); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Test for being at the beginning. |
|
54 | - * @return boolean True if first. |
|
55 | - * @access private |
|
56 | - */ |
|
57 | - function _atBeginning() { |
|
58 | - return ($this->_position == 0) && ! $this->_isEmpty(); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Test for being at the last entry. |
|
63 | - * @return boolean True if last. |
|
64 | - * @access private |
|
65 | - */ |
|
66 | - function _atEnd() { |
|
67 | - return ($this->_position + 1 >= count($this->_sequence)) && ! $this->_isEmpty(); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Adds a successfully fetched page to the history. |
|
72 | - * @param SimpleUrl $url URL of fetch. |
|
73 | - * @param SimpleEncoding $parameters Any post data with the fetch. |
|
74 | - * @access public |
|
75 | - */ |
|
76 | - function recordEntry($url, $parameters) { |
|
77 | - $this->_dropFuture(); |
|
78 | - array_push( |
|
79 | - $this->_sequence, |
|
80 | - array('url' => $url, 'parameters' => $parameters)); |
|
81 | - $this->_position++; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Last fully qualified URL for current history |
|
86 | - * position. |
|
87 | - * @return SimpleUrl URL for this position. |
|
88 | - * @access public |
|
89 | - */ |
|
90 | - function getUrl() { |
|
91 | - if ($this->_isEmpty()) { |
|
92 | - return false; |
|
93 | - } |
|
94 | - return $this->_sequence[$this->_position]['url']; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Parameters of last fetch from current history |
|
99 | - * position. |
|
100 | - * @return SimpleFormEncoding Post parameters. |
|
101 | - * @access public |
|
102 | - */ |
|
103 | - function getParameters() { |
|
104 | - if ($this->_isEmpty()) { |
|
105 | - return false; |
|
106 | - } |
|
107 | - return $this->_sequence[$this->_position]['parameters']; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Step back one place in the history. Stops at |
|
112 | - * the first page. |
|
113 | - * @return boolean True if any previous entries. |
|
114 | - * @access public |
|
115 | - */ |
|
116 | - function back() { |
|
117 | - if ($this->_isEmpty() || $this->_atBeginning()) { |
|
118 | - return false; |
|
119 | - } |
|
120 | - $this->_position--; |
|
121 | - return true; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Step forward one place. If already at the |
|
126 | - * latest entry then nothing will happen. |
|
127 | - * @return boolean True if any future entries. |
|
128 | - * @access public |
|
129 | - */ |
|
130 | - function forward() { |
|
131 | - if ($this->_isEmpty() || $this->_atEnd()) { |
|
132 | - return false; |
|
133 | - } |
|
134 | - $this->_position++; |
|
135 | - return true; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Ditches all future entries beyond the current |
|
140 | - * point. |
|
141 | - * @access private |
|
142 | - */ |
|
143 | - function _dropFuture() { |
|
144 | - if ($this->_isEmpty()) { |
|
145 | - return; |
|
146 | - } |
|
147 | - while (! $this->_atEnd()) { |
|
148 | - array_pop($this->_sequence); |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Simulated web browser. This is an aggregate of |
|
155 | - * the user agent, the HTML parsing, request history |
|
156 | - * and the last header set. |
|
29 | + */ |
|
30 | + class SimpleBrowserHistory { |
|
31 | + protected $_sequence; |
|
32 | + protected $_position; |
|
33 | + |
|
34 | + /** |
|
35 | + * Starts empty. |
|
36 | + * @access public |
|
37 | + */ |
|
38 | + function SimpleBrowserHistory() { |
|
39 | + $this->_sequence = array(); |
|
40 | + $this->_position = -1; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Test for no entries yet. |
|
45 | + * @return boolean True if empty. |
|
46 | + * @access private |
|
47 | + */ |
|
48 | + function _isEmpty() { |
|
49 | + return ($this->_position == -1); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Test for being at the beginning. |
|
54 | + * @return boolean True if first. |
|
55 | + * @access private |
|
56 | + */ |
|
57 | + function _atBeginning() { |
|
58 | + return ($this->_position == 0) && ! $this->_isEmpty(); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Test for being at the last entry. |
|
63 | + * @return boolean True if last. |
|
64 | + * @access private |
|
65 | + */ |
|
66 | + function _atEnd() { |
|
67 | + return ($this->_position + 1 >= count($this->_sequence)) && ! $this->_isEmpty(); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Adds a successfully fetched page to the history. |
|
72 | + * @param SimpleUrl $url URL of fetch. |
|
73 | + * @param SimpleEncoding $parameters Any post data with the fetch. |
|
74 | + * @access public |
|
75 | + */ |
|
76 | + function recordEntry($url, $parameters) { |
|
77 | + $this->_dropFuture(); |
|
78 | + array_push( |
|
79 | + $this->_sequence, |
|
80 | + array('url' => $url, 'parameters' => $parameters)); |
|
81 | + $this->_position++; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Last fully qualified URL for current history |
|
86 | + * position. |
|
87 | + * @return SimpleUrl URL for this position. |
|
88 | + * @access public |
|
89 | + */ |
|
90 | + function getUrl() { |
|
91 | + if ($this->_isEmpty()) { |
|
92 | + return false; |
|
93 | + } |
|
94 | + return $this->_sequence[$this->_position]['url']; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Parameters of last fetch from current history |
|
99 | + * position. |
|
100 | + * @return SimpleFormEncoding Post parameters. |
|
101 | + * @access public |
|
102 | + */ |
|
103 | + function getParameters() { |
|
104 | + if ($this->_isEmpty()) { |
|
105 | + return false; |
|
106 | + } |
|
107 | + return $this->_sequence[$this->_position]['parameters']; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Step back one place in the history. Stops at |
|
112 | + * the first page. |
|
113 | + * @return boolean True if any previous entries. |
|
114 | + * @access public |
|
115 | + */ |
|
116 | + function back() { |
|
117 | + if ($this->_isEmpty() || $this->_atBeginning()) { |
|
118 | + return false; |
|
119 | + } |
|
120 | + $this->_position--; |
|
121 | + return true; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Step forward one place. If already at the |
|
126 | + * latest entry then nothing will happen. |
|
127 | + * @return boolean True if any future entries. |
|
128 | + * @access public |
|
129 | + */ |
|
130 | + function forward() { |
|
131 | + if ($this->_isEmpty() || $this->_atEnd()) { |
|
132 | + return false; |
|
133 | + } |
|
134 | + $this->_position++; |
|
135 | + return true; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Ditches all future entries beyond the current |
|
140 | + * point. |
|
141 | + * @access private |
|
142 | + */ |
|
143 | + function _dropFuture() { |
|
144 | + if ($this->_isEmpty()) { |
|
145 | + return; |
|
146 | + } |
|
147 | + while (! $this->_atEnd()) { |
|
148 | + array_pop($this->_sequence); |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Simulated web browser. This is an aggregate of |
|
155 | + * the user agent, the HTML parsing, request history |
|
156 | + * and the last header set. |
|
157 | 157 | * @package SimpleTest |
158 | 158 | * @subpackage WebTester |
159 | - */ |
|
160 | - class SimpleBrowser { |
|
161 | - protected $_user_agent; |
|
162 | - protected $_page; |
|
163 | - protected $_history; |
|
164 | - protected $_ignore_frames; |
|
165 | - protected $_maximum_nested_frames; |
|
166 | - |
|
167 | - /** |
|
168 | - * Starts with a fresh browser with no |
|
169 | - * cookie or any other state information. The |
|
170 | - * exception is that a default proxy will be |
|
171 | - * set up if specified in the options. |
|
172 | - * @access public |
|
173 | - */ |
|
174 | - function SimpleBrowser() { |
|
175 | - $this->_user_agent = $this->_createUserAgent(); |
|
176 | - $this->_user_agent->useProxy( |
|
177 | - SimpleTest::getDefaultProxy(), |
|
178 | - SimpleTest::getDefaultProxyUsername(), |
|
179 | - SimpleTest::getDefaultProxyPassword()); |
|
180 | - $this->_page = new SimplePage(); |
|
181 | - $this->_history = $this->_createHistory(); |
|
182 | - $this->_ignore_frames = false; |
|
183 | - $this->_maximum_nested_frames = DEFAULT_MAX_NESTED_FRAMES; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Creates the underlying user agent. |
|
188 | - * @return SimpleFetcher Content fetcher. |
|
189 | - * @access protected |
|
190 | - */ |
|
191 | - function &_createUserAgent() { |
|
192 | - $user_agent = new SimpleUserAgent(); |
|
193 | - return $user_agent; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Creates a new empty history list. |
|
198 | - * @return SimpleBrowserHistory New list. |
|
199 | - * @access protected |
|
200 | - */ |
|
201 | - function &_createHistory() { |
|
202 | - $history = new SimpleBrowserHistory(); |
|
203 | - return $history; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Disables frames support. Frames will not be fetched |
|
208 | - * and the frameset page will be used instead. |
|
209 | - * @access public |
|
210 | - */ |
|
211 | - function ignoreFrames() { |
|
212 | - $this->_ignore_frames = true; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Enables frames support. Frames will be fetched from |
|
217 | - * now on. |
|
218 | - * @access public |
|
219 | - */ |
|
220 | - function useFrames() { |
|
221 | - $this->_ignore_frames = false; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Switches off cookie sending and recieving. |
|
226 | - * @access public |
|
227 | - */ |
|
228 | - function ignoreCookies() { |
|
229 | - $this->_user_agent->ignoreCookies(); |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Switches back on the cookie sending and recieving. |
|
234 | - * @access public |
|
235 | - */ |
|
236 | - function useCookies() { |
|
237 | - $this->_user_agent->useCookies(); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Parses the raw content into a page. Will load further |
|
242 | - * frame pages unless frames are disabled. |
|
243 | - * @param SimpleHttpResponse $response Response from fetch. |
|
244 | - * @param integer $depth Nested frameset depth. |
|
245 | - * @return SimplePage Parsed HTML. |
|
246 | - * @access private |
|
247 | - */ |
|
248 | - function &_parse($response, $depth = 0) { |
|
249 | - $page = $this->_buildPage($response); |
|
250 | - if ($this->_ignore_frames || ! $page->hasFrames() || ($depth > $this->_maximum_nested_frames)) { |
|
251 | - return $page; |
|
252 | - } |
|
253 | - $frameset = new SimpleFrameset($page); |
|
254 | - foreach ($page->getFrameset() as $key => $url) { |
|
255 | - $frame = $this->_fetch($url, new SimpleGetEncoding(), $depth + 1); |
|
256 | - $frameset->addFrame($frame, $key); |
|
257 | - } |
|
258 | - return $frameset; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Assembles the parsing machinery and actually parses |
|
263 | - * a single page. Frees all of the builder memory and so |
|
264 | - * unjams the PHP memory management. |
|
265 | - * @param SimpleHttpResponse $response Response from fetch. |
|
266 | - * @return SimplePage Parsed top level page. |
|
267 | - * @access protected |
|
268 | - */ |
|
269 | - function &_buildPage($response) { |
|
270 | - $builder = new SimplePageBuilder(); |
|
271 | - $page = $builder->parse($response); |
|
272 | - $builder->free(); |
|
273 | - unset($builder); |
|
274 | - return $page; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Fetches a page. Jointly recursive with the _parse() |
|
279 | - * method as it descends a frameset. |
|
280 | - * @param string/SimpleUrl $url Target to fetch. |
|
281 | - * @param SimpleEncoding $encoding GET/POST parameters. |
|
282 | - * @param integer $depth Nested frameset depth protection. |
|
283 | - * @return SimplePage Parsed page. |
|
284 | - * @access private |
|
285 | - */ |
|
286 | - function &_fetch($url, $encoding, $depth = 0) { |
|
287 | - $response = $this->_user_agent->fetchResponse($url, $encoding); |
|
288 | - if ($response->isError()) { |
|
289 | - $page = new SimplePage($response); |
|
290 | - } else { |
|
291 | - $page = $this->_parse($response, $depth); |
|
292 | - } |
|
293 | - return $page; |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Fetches a page or a single frame if that is the current |
|
298 | - * focus. |
|
299 | - * @param SimpleUrl $url Target to fetch. |
|
300 | - * @param SimpleEncoding $parameters GET/POST parameters. |
|
301 | - * @return string Raw content of page. |
|
302 | - * @access private |
|
303 | - */ |
|
304 | - function _load($url, $parameters) { |
|
305 | - $frame = $url->getTarget(); |
|
306 | - if (! $frame || ! $this->_page->hasFrames() || (strtolower($frame) == '_top')) { |
|
307 | - return $this->_loadPage($url, $parameters); |
|
308 | - } |
|
309 | - return $this->_loadFrame(array($frame), $url, $parameters); |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Fetches a page and makes it the current page/frame. |
|
314 | - * @param string/SimpleUrl $url Target to fetch as string. |
|
315 | - * @param SimplePostEncoding $parameters POST parameters. |
|
316 | - * @return string Raw content of page. |
|
317 | - * @access private |
|
318 | - */ |
|
319 | - function _loadPage($url, $parameters) { |
|
320 | - $this->_page = $this->_fetch($url, $parameters); |
|
321 | - $this->_history->recordEntry( |
|
322 | - $this->_page->getUrl(), |
|
323 | - $this->_page->getRequestData()); |
|
324 | - return $this->_page->getRaw(); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Fetches a frame into the existing frameset replacing the |
|
329 | - * original. |
|
330 | - * @param array $frames List of names to drill down. |
|
331 | - * @param string/SimpleUrl $url Target to fetch as string. |
|
332 | - * @param SimpleFormEncoding $parameters POST parameters. |
|
333 | - * @return string Raw content of page. |
|
334 | - * @access private |
|
335 | - */ |
|
336 | - function _loadFrame($frames, $url, $parameters) { |
|
337 | - $page = $this->_fetch($url, $parameters); |
|
338 | - $this->_page->setFrame($frames, $page); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Removes expired and temporary cookies as if |
|
343 | - * the browser was closed and re-opened. |
|
344 | - * @param string/integer $date Time when session restarted. |
|
345 | - * If omitted then all persistent |
|
346 | - * cookies are kept. |
|
347 | - * @access public |
|
348 | - */ |
|
349 | - function restart($date = false) { |
|
350 | - $this->_user_agent->restart($date); |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Adds a header to every fetch. |
|
355 | - * @param string $header Header line to add to every |
|
356 | - * request until cleared. |
|
357 | - * @access public |
|
358 | - */ |
|
359 | - function addHeader($header) { |
|
360 | - $this->_user_agent->addHeader($header); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Ages the cookies by the specified time. |
|
365 | - * @param integer $interval Amount in seconds. |
|
366 | - * @access public |
|
367 | - */ |
|
368 | - function ageCookies($interval) { |
|
369 | - $this->_user_agent->ageCookies($interval); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Sets an additional cookie. If a cookie has |
|
374 | - * the same name and path it is replaced. |
|
375 | - * @param string $name Cookie key. |
|
376 | - * @param string $value Value of cookie. |
|
377 | - * @param string $host Host upon which the cookie is valid. |
|
378 | - * @param string $path Cookie path if not host wide. |
|
379 | - * @param string $expiry Expiry date. |
|
380 | - * @access public |
|
381 | - */ |
|
382 | - function setCookie($name, $value, $host = false, $path = '/', $expiry = false) { |
|
383 | - $this->_user_agent->setCookie($name, $value, $host, $path, $expiry); |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Reads the most specific cookie value from the |
|
388 | - * browser cookies. |
|
389 | - * @param string $host Host to search. |
|
390 | - * @param string $path Applicable path. |
|
391 | - * @param string $name Name of cookie to read. |
|
392 | - * @return string False if not present, else the |
|
393 | - * value as a string. |
|
394 | - * @access public |
|
395 | - */ |
|
396 | - function getCookieValue($host, $path, $name) { |
|
397 | - return $this->_user_agent->getCookieValue($host, $path, $name); |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * Reads the current cookies for the current URL. |
|
402 | - * @param string $name Key of cookie to find. |
|
403 | - * @return string Null if there is no current URL, false |
|
404 | - * if the cookie is not set. |
|
405 | - * @access public |
|
406 | - */ |
|
407 | - function getCurrentCookieValue($name) { |
|
408 | - return $this->_user_agent->getBaseCookieValue($name, $this->_page->getUrl()); |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Sets the maximum number of redirects before |
|
413 | - * a page will be loaded anyway. |
|
414 | - * @param integer $max Most hops allowed. |
|
415 | - * @access public |
|
416 | - */ |
|
417 | - function setMaximumRedirects($max) { |
|
418 | - $this->_user_agent->setMaximumRedirects($max); |
|
419 | - } |
|
420 | - |
|
421 | - /** |
|
422 | - * Sets the maximum number of nesting of framed pages |
|
423 | - * within a framed page to prevent loops. |
|
424 | - * @param integer $max Highest depth allowed. |
|
425 | - * @access public |
|
426 | - */ |
|
427 | - function setMaximumNestedFrames($max) { |
|
428 | - $this->_maximum_nested_frames = $max; |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Sets the socket timeout for opening a connection. |
|
433 | - * @param integer $timeout Maximum time in seconds. |
|
434 | - * @access public |
|
435 | - */ |
|
436 | - function setConnectionTimeout($timeout) { |
|
437 | - $this->_user_agent->setConnectionTimeout($timeout); |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * Sets proxy to use on all requests for when |
|
442 | - * testing from behind a firewall. Set URL |
|
443 | - * to false to disable. |
|
444 | - * @param string $proxy Proxy URL. |
|
445 | - * @param string $username Proxy username for authentication. |
|
446 | - * @param string $password Proxy password for authentication. |
|
447 | - * @access public |
|
448 | - */ |
|
449 | - function useProxy($proxy, $username = false, $password = false) { |
|
450 | - $this->_user_agent->useProxy($proxy, $username, $password); |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Fetches the page content with a HEAD request. |
|
455 | - * Will affect cookies, but will not change the base URL. |
|
456 | - * @param string/SimpleUrl $url Target to fetch as string. |
|
457 | - * @param hash/SimpleHeadEncoding $parameters Additional parameters for |
|
458 | - * HEAD request. |
|
459 | - * @return boolean True if successful. |
|
460 | - * @access public |
|
461 | - */ |
|
462 | - function head($url, $parameters = false) { |
|
463 | - if (! is_object($url)) { |
|
464 | - $url = new SimpleUrl($url); |
|
465 | - } |
|
466 | - if ($this->getUrl()) { |
|
467 | - $url = $url->makeAbsolute($this->getUrl()); |
|
468 | - } |
|
469 | - $response = $this->_user_agent->fetchResponse($url, new SimpleHeadEncoding($parameters)); |
|
470 | - return ! $response->isError(); |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Fetches the page content with a simple GET request. |
|
475 | - * @param string/SimpleUrl $url Target to fetch. |
|
476 | - * @param hash/SimpleFormEncoding $parameters Additional parameters for |
|
477 | - * GET request. |
|
478 | - * @return string Content of page or false. |
|
479 | - * @access public |
|
480 | - */ |
|
481 | - function get($url, $parameters = false) { |
|
482 | - if (! is_object($url)) { |
|
483 | - $url = new SimpleUrl($url); |
|
484 | - } |
|
485 | - if ($this->getUrl()) { |
|
486 | - $url = $url->makeAbsolute($this->getUrl()); |
|
487 | - } |
|
488 | - return $this->_load($url, new SimpleGetEncoding($parameters)); |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * Fetches the page content with a POST request. |
|
493 | - * @param string/SimpleUrl $url Target to fetch as string. |
|
494 | - * @param hash/SimpleFormEncoding $parameters POST parameters. |
|
495 | - * @return string Content of page. |
|
496 | - * @access public |
|
497 | - */ |
|
498 | - function post($url, $parameters = false) { |
|
499 | - if (! is_object($url)) { |
|
500 | - $url = new SimpleUrl($url); |
|
501 | - } |
|
502 | - if ($this->getUrl()) { |
|
503 | - $url = $url->makeAbsolute($this->getUrl()); |
|
504 | - } |
|
505 | - return $this->_load($url, new SimplePostEncoding($parameters)); |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * Equivalent to hitting the retry button on the |
|
510 | - * browser. Will attempt to repeat the page fetch. If |
|
511 | - * there is no history to repeat it will give false. |
|
512 | - * @return string/boolean Content if fetch succeeded |
|
513 | - * else false. |
|
514 | - * @access public |
|
515 | - */ |
|
516 | - function retry() { |
|
517 | - $frames = $this->_page->getFrameFocus(); |
|
518 | - if (count($frames) > 0) { |
|
519 | - $this->_loadFrame( |
|
520 | - $frames, |
|
521 | - $this->_page->getUrl(), |
|
522 | - $this->_page->getRequestData()); |
|
523 | - return $this->_page->getRaw(); |
|
524 | - } |
|
525 | - if ($url = $this->_history->getUrl()) { |
|
526 | - $this->_page = $this->_fetch($url, $this->_history->getParameters()); |
|
527 | - return $this->_page->getRaw(); |
|
528 | - } |
|
529 | - return false; |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * Equivalent to hitting the back button on the |
|
534 | - * browser. The browser history is unchanged on |
|
535 | - * failure. The page content is refetched as there |
|
536 | - * is no concept of content caching in SimpleTest. |
|
537 | - * @return boolean True if history entry and |
|
538 | - * fetch succeeded |
|
539 | - * @access public |
|
540 | - */ |
|
541 | - function back() { |
|
542 | - if (! $this->_history->back()) { |
|
543 | - return false; |
|
544 | - } |
|
545 | - $content = $this->retry(); |
|
546 | - if (! $content) { |
|
547 | - $this->_history->forward(); |
|
548 | - } |
|
549 | - return $content; |
|
550 | - } |
|
551 | - |
|
552 | - /** |
|
553 | - * Equivalent to hitting the forward button on the |
|
554 | - * browser. The browser history is unchanged on |
|
555 | - * failure. The page content is refetched as there |
|
556 | - * is no concept of content caching in SimpleTest. |
|
557 | - * @return boolean True if history entry and |
|
558 | - * fetch succeeded |
|
559 | - * @access public |
|
560 | - */ |
|
561 | - function forward() { |
|
562 | - if (! $this->_history->forward()) { |
|
563 | - return false; |
|
564 | - } |
|
565 | - $content = $this->retry(); |
|
566 | - if (! $content) { |
|
567 | - $this->_history->back(); |
|
568 | - } |
|
569 | - return $content; |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Retries a request after setting the authentication |
|
574 | - * for the current realm. |
|
575 | - * @param string $username Username for realm. |
|
576 | - * @param string $password Password for realm. |
|
577 | - * @return boolean True if successful fetch. Note |
|
578 | - * that authentication may still have |
|
579 | - * failed. |
|
580 | - * @access public |
|
581 | - */ |
|
582 | - function authenticate($username, $password) { |
|
583 | - if (! $this->_page->getRealm()) { |
|
584 | - return false; |
|
585 | - } |
|
586 | - $url = $this->_page->getUrl(); |
|
587 | - if (! $url) { |
|
588 | - return false; |
|
589 | - } |
|
590 | - $this->_user_agent->setIdentity( |
|
591 | - $url->getHost(), |
|
592 | - $this->_page->getRealm(), |
|
593 | - $username, |
|
594 | - $password); |
|
595 | - return $this->retry(); |
|
596 | - } |
|
597 | - |
|
598 | - /** |
|
599 | - * Accessor for a breakdown of the frameset. |
|
600 | - * @return array Hash tree of frames by name |
|
601 | - * or index if no name. |
|
602 | - * @access public |
|
603 | - */ |
|
604 | - function getFrames() { |
|
605 | - return $this->_page->getFrames(); |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Accessor for current frame focus. Will be |
|
610 | - * false if no frame has focus. |
|
611 | - * @return integer/string/boolean Label if any, otherwise |
|
612 | - * the position in the frameset |
|
613 | - * or false if none. |
|
614 | - * @access public |
|
615 | - */ |
|
616 | - function getFrameFocus() { |
|
617 | - return $this->_page->getFrameFocus(); |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * Sets the focus by index. The integer index starts from 1. |
|
622 | - * @param integer $choice Chosen frame. |
|
623 | - * @return boolean True if frame exists. |
|
624 | - * @access public |
|
625 | - */ |
|
626 | - function setFrameFocusByIndex($choice) { |
|
627 | - return $this->_page->setFrameFocusByIndex($choice); |
|
628 | - } |
|
629 | - |
|
630 | - /** |
|
631 | - * Sets the focus by name. |
|
632 | - * @param string $name Chosen frame. |
|
633 | - * @return boolean True if frame exists. |
|
634 | - * @access public |
|
635 | - */ |
|
636 | - function setFrameFocus($name) { |
|
637 | - return $this->_page->setFrameFocus($name); |
|
638 | - } |
|
639 | - |
|
640 | - /** |
|
641 | - * Clears the frame focus. All frames will be searched |
|
642 | - * for content. |
|
643 | - * @access public |
|
644 | - */ |
|
645 | - function clearFrameFocus() { |
|
646 | - return $this->_page->clearFrameFocus(); |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * Accessor for last error. |
|
651 | - * @return string Error from last response. |
|
652 | - * @access public |
|
653 | - */ |
|
654 | - function getTransportError() { |
|
655 | - return $this->_page->getTransportError(); |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * Accessor for current MIME type. |
|
660 | - * @return string MIME type as string; e.g. 'text/html' |
|
661 | - * @access public |
|
662 | - */ |
|
663 | - function getMimeType() { |
|
664 | - return $this->_page->getMimeType(); |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * Accessor for last response code. |
|
669 | - * @return integer Last HTTP response code received. |
|
670 | - * @access public |
|
671 | - */ |
|
672 | - function getResponseCode() { |
|
673 | - return $this->_page->getResponseCode(); |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * Accessor for last Authentication type. Only valid |
|
678 | - * straight after a challenge (401). |
|
679 | - * @return string Description of challenge type. |
|
680 | - * @access public |
|
681 | - */ |
|
682 | - function getAuthentication() { |
|
683 | - return $this->_page->getAuthentication(); |
|
684 | - } |
|
685 | - |
|
686 | - /** |
|
687 | - * Accessor for last Authentication realm. Only valid |
|
688 | - * straight after a challenge (401). |
|
689 | - * @return string Name of security realm. |
|
690 | - * @access public |
|
691 | - */ |
|
692 | - function getRealm() { |
|
693 | - return $this->_page->getRealm(); |
|
694 | - } |
|
695 | - |
|
696 | - /** |
|
697 | - * Accessor for current URL of page or frame if |
|
698 | - * focused. |
|
699 | - * @return string Location of current page or frame as |
|
700 | - * a string. |
|
701 | - */ |
|
702 | - function getUrl() { |
|
703 | - $url = $this->_page->getUrl(); |
|
704 | - return $url ? $url->asString() : false; |
|
705 | - } |
|
706 | - |
|
707 | - /** |
|
708 | - * Accessor for raw bytes sent down the wire. |
|
709 | - * @return string Original text sent. |
|
710 | - * @access public |
|
711 | - */ |
|
712 | - function getRequest() { |
|
713 | - return $this->_page->getRequest(); |
|
714 | - } |
|
715 | - |
|
716 | - /** |
|
717 | - * Accessor for raw header information. |
|
718 | - * @return string Header block. |
|
719 | - * @access public |
|
720 | - */ |
|
721 | - function getHeaders() { |
|
722 | - return $this->_page->getHeaders(); |
|
723 | - } |
|
724 | - |
|
725 | - /** |
|
726 | - * Accessor for raw page information. |
|
727 | - * @return string Original text content of web page. |
|
728 | - * @access public |
|
729 | - */ |
|
730 | - function getContent() { |
|
731 | - return $this->_page->getRaw(); |
|
732 | - } |
|
733 | - |
|
734 | - /** |
|
735 | - * Accessor for plain text version of the page. |
|
736 | - * @return string Normalised text representation. |
|
737 | - * @access public |
|
738 | - */ |
|
739 | - function getContentAsText() { |
|
740 | - return $this->_page->getText(); |
|
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Accessor for parsed title. |
|
745 | - * @return string Title or false if no title is present. |
|
746 | - * @access public |
|
747 | - */ |
|
748 | - function getTitle() { |
|
749 | - return $this->_page->getTitle(); |
|
750 | - } |
|
751 | - |
|
752 | - /** |
|
753 | - * Accessor for a list of all fixed links in current page. |
|
754 | - * @return array List of urls with scheme of |
|
755 | - * http or https and hostname. |
|
756 | - * @access public |
|
757 | - */ |
|
758 | - function getAbsoluteUrls() { |
|
759 | - return $this->_page->getAbsoluteUrls(); |
|
760 | - } |
|
761 | - |
|
762 | - /** |
|
763 | - * Accessor for a list of all relative links. |
|
764 | - * @return array List of urls without hostname. |
|
765 | - * @access public |
|
766 | - */ |
|
767 | - function getRelativeUrls() { |
|
768 | - return $this->_page->getRelativeUrls(); |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Sets all form fields with that name. |
|
773 | - * @param string $label Name or label of field in forms. |
|
774 | - * @param string $value New value of field. |
|
775 | - * @return boolean True if field exists, otherwise false. |
|
776 | - * @access public |
|
777 | - */ |
|
778 | - function setField($label, $value) { |
|
779 | - return $this->_page->setField(new SimpleByLabelOrName($label), $value); |
|
780 | - } |
|
781 | - |
|
782 | - /** |
|
783 | - * Sets all form fields with that name. Will use label if |
|
784 | - * one is available (not yet implemented). |
|
785 | - * @param string $name Name of field in forms. |
|
786 | - * @param string $value New value of field. |
|
787 | - * @return boolean True if field exists, otherwise false. |
|
788 | - * @access public |
|
789 | - */ |
|
790 | - function setFieldByName($name, $value) { |
|
791 | - return $this->_page->setField(new SimpleByName($name), $value); |
|
792 | - } |
|
793 | - |
|
794 | - /** |
|
795 | - * Sets all form fields with that id attribute. |
|
796 | - * @param string/integer $id Id of field in forms. |
|
797 | - * @param string $value New value of field. |
|
798 | - * @return boolean True if field exists, otherwise false. |
|
799 | - * @access public |
|
800 | - */ |
|
801 | - function setFieldById($id, $value) { |
|
802 | - return $this->_page->setField(new SimpleById($id), $value); |
|
803 | - } |
|
804 | - |
|
805 | - /** |
|
806 | - * Accessor for a form element value within the page. |
|
807 | - * Finds the first match. |
|
808 | - * @param string $label Field label. |
|
809 | - * @return string/boolean A value if the field is |
|
810 | - * present, false if unchecked |
|
811 | - * and null if missing. |
|
812 | - * @access public |
|
813 | - */ |
|
814 | - function getField($label) { |
|
815 | - return $this->_page->getField(new SimpleByLabelOrName($label)); |
|
816 | - } |
|
817 | - |
|
818 | - /** |
|
819 | - * Accessor for a form element value within the page. |
|
820 | - * Finds the first match. |
|
821 | - * @param string $name Field name. |
|
822 | - * @return string/boolean A string if the field is |
|
823 | - * present, false if unchecked |
|
824 | - * and null if missing. |
|
825 | - * @access public |
|
826 | - */ |
|
827 | - function getFieldByName($name) { |
|
828 | - return $this->_page->getField(new SimpleByName($name)); |
|
829 | - } |
|
830 | - |
|
831 | - /** |
|
832 | - * Accessor for a form element value within the page. |
|
833 | - * @param string/integer $id Id of field in forms. |
|
834 | - * @return string/boolean A string if the field is |
|
835 | - * present, false if unchecked |
|
836 | - * and null if missing. |
|
837 | - * @access public |
|
838 | - */ |
|
839 | - function getFieldById($id) { |
|
840 | - return $this->_page->getField(new SimpleById($id)); |
|
841 | - } |
|
842 | - |
|
843 | - /** |
|
844 | - * Clicks the submit button by label. The owning |
|
845 | - * form will be submitted by this. |
|
846 | - * @param string $label Button label. An unlabeled |
|
847 | - * button can be triggered by 'Submit'. |
|
848 | - * @param hash $additional Additional form data. |
|
849 | - * @return string/boolean Page on success. |
|
850 | - * @access public |
|
851 | - */ |
|
852 | - function clickSubmit($label = 'Submit', $additional = false) { |
|
853 | - if (! ($form = $this->_page->getFormBySubmit(new SimpleByLabel($label)))) { |
|
854 | - return false; |
|
855 | - } |
|
856 | - $success = $this->_load( |
|
857 | - $form->getAction(), |
|
858 | - $form->submitButton(new SimpleByLabel($label), $additional)); |
|
859 | - return ($success ? $this->getContent() : $success); |
|
860 | - } |
|
861 | - |
|
862 | - /** |
|
863 | - * Clicks the submit button by name attribute. The owning |
|
864 | - * form will be submitted by this. |
|
865 | - * @param string $name Button name. |
|
866 | - * @param hash $additional Additional form data. |
|
867 | - * @return string/boolean Page on success. |
|
868 | - * @access public |
|
869 | - */ |
|
870 | - function clickSubmitByName($name, $additional = false) { |
|
871 | - if (! ($form = $this->_page->getFormBySubmit(new SimpleByName($name)))) { |
|
872 | - return false; |
|
873 | - } |
|
874 | - $success = $this->_load( |
|
875 | - $form->getAction(), |
|
876 | - $form->submitButton(new SimpleByName($name), $additional)); |
|
877 | - return ($success ? $this->getContent() : $success); |
|
878 | - } |
|
879 | - |
|
880 | - /** |
|
881 | - * Clicks the submit button by ID attribute of the button |
|
882 | - * itself. The owning form will be submitted by this. |
|
883 | - * @param string $id Button ID. |
|
884 | - * @param hash $additional Additional form data. |
|
885 | - * @return string/boolean Page on success. |
|
886 | - * @access public |
|
887 | - */ |
|
888 | - function clickSubmitById($id, $additional = false) { |
|
889 | - if (! ($form = $this->_page->getFormBySubmit(new SimpleById($id)))) { |
|
890 | - return false; |
|
891 | - } |
|
892 | - $success = $this->_load( |
|
893 | - $form->getAction(), |
|
894 | - $form->submitButton(new SimpleById($id), $additional)); |
|
895 | - return ($success ? $this->getContent() : $success); |
|
896 | - } |
|
897 | - |
|
898 | - /** |
|
899 | - * Clicks the submit image by some kind of label. Usually |
|
900 | - * the alt tag or the nearest equivalent. The owning |
|
901 | - * form will be submitted by this. Clicking outside of |
|
902 | - * the boundary of the coordinates will result in |
|
903 | - * a failure. |
|
904 | - * @param string $label ID attribute of button. |
|
905 | - * @param integer $x X-coordinate of imaginary click. |
|
906 | - * @param integer $y Y-coordinate of imaginary click. |
|
907 | - * @param hash $additional Additional form data. |
|
908 | - * @return string/boolean Page on success. |
|
909 | - * @access public |
|
910 | - */ |
|
911 | - function clickImage($label, $x = 1, $y = 1, $additional = false) { |
|
912 | - if (! ($form = $this->_page->getFormByImage(new SimpleByLabel($label)))) { |
|
913 | - return false; |
|
914 | - } |
|
915 | - $success = $this->_load( |
|
916 | - $form->getAction(), |
|
917 | - $form->submitImage(new SimpleByLabel($label), $x, $y, $additional)); |
|
918 | - return ($success ? $this->getContent() : $success); |
|
919 | - } |
|
920 | - |
|
921 | - /** |
|
922 | - * Clicks the submit image by the name. Usually |
|
923 | - * the alt tag or the nearest equivalent. The owning |
|
924 | - * form will be submitted by this. Clicking outside of |
|
925 | - * the boundary of the coordinates will result in |
|
926 | - * a failure. |
|
927 | - * @param string $name Name attribute of button. |
|
928 | - * @param integer $x X-coordinate of imaginary click. |
|
929 | - * @param integer $y Y-coordinate of imaginary click. |
|
930 | - * @param hash $additional Additional form data. |
|
931 | - * @return string/boolean Page on success. |
|
932 | - * @access public |
|
933 | - */ |
|
934 | - function clickImageByName($name, $x = 1, $y = 1, $additional = false) { |
|
935 | - if (! ($form = $this->_page->getFormByImage(new SimpleByName($name)))) { |
|
936 | - return false; |
|
937 | - } |
|
938 | - $success = $this->_load( |
|
939 | - $form->getAction(), |
|
940 | - $form->submitImage(new SimpleByName($name), $x, $y, $additional)); |
|
941 | - return ($success ? $this->getContent() : $success); |
|
942 | - } |
|
943 | - |
|
944 | - /** |
|
945 | - * Clicks the submit image by ID attribute. The owning |
|
946 | - * form will be submitted by this. Clicking outside of |
|
947 | - * the boundary of the coordinates will result in |
|
948 | - * a failure. |
|
949 | - * @param integer/string $id ID attribute of button. |
|
950 | - * @param integer $x X-coordinate of imaginary click. |
|
951 | - * @param integer $y Y-coordinate of imaginary click. |
|
952 | - * @param hash $additional Additional form data. |
|
953 | - * @return string/boolean Page on success. |
|
954 | - * @access public |
|
955 | - */ |
|
956 | - function clickImageById($id, $x = 1, $y = 1, $additional = false) { |
|
957 | - if (! ($form = $this->_page->getFormByImage(new SimpleById($id)))) { |
|
958 | - return false; |
|
959 | - } |
|
960 | - $success = $this->_load( |
|
961 | - $form->getAction(), |
|
962 | - $form->submitImage(new SimpleById($id), $x, $y, $additional)); |
|
963 | - return ($success ? $this->getContent() : $success); |
|
964 | - } |
|
965 | - |
|
966 | - /** |
|
967 | - * Submits a form by the ID. |
|
968 | - * @param string $id The form ID. No submit button value |
|
969 | - * will be sent. |
|
970 | - * @return string/boolean Page on success. |
|
971 | - * @access public |
|
972 | - */ |
|
973 | - function submitFormById($id) { |
|
974 | - if (! ($form = $this->_page->getFormById($id))) { |
|
975 | - return false; |
|
976 | - } |
|
977 | - $success = $this->_load( |
|
978 | - $form->getAction(), |
|
979 | - $form->submit()); |
|
980 | - return ($success ? $this->getContent() : $success); |
|
981 | - } |
|
982 | - |
|
983 | - /** |
|
984 | - * Follows a link by label. Will click the first link |
|
985 | - * found with this link text by default, or a later |
|
986 | - * one if an index is given. The match ignores case and |
|
987 | - * white space issues. |
|
988 | - * @param string $label Text between the anchor tags. |
|
989 | - * @param integer $index Link position counting from zero. |
|
990 | - * @return string/boolean Page on success. |
|
991 | - * @access public |
|
992 | - */ |
|
993 | - function clickLink($label, $index = 0) { |
|
994 | - $urls = $this->_page->getUrlsByLabel($label); |
|
995 | - if (count($urls) == 0) { |
|
996 | - return false; |
|
997 | - } |
|
998 | - if (count($urls) < $index + 1) { |
|
999 | - return false; |
|
1000 | - } |
|
1001 | - $this->_load($urls[$index], new SimpleGetEncoding()); |
|
1002 | - return $this->getContent(); |
|
1003 | - } |
|
1004 | - |
|
1005 | - /** |
|
1006 | - * Tests to see if a link is present by label. |
|
1007 | - * @param string $label Text of value attribute. |
|
1008 | - * @return boolean True if link present. |
|
1009 | - * @access public |
|
1010 | - */ |
|
1011 | - function isLink($label) { |
|
1012 | - return (count($this->_page->getUrlsByLabel($label)) > 0); |
|
1013 | - } |
|
1014 | - |
|
1015 | - /** |
|
1016 | - * Follows a link by id attribute. |
|
1017 | - * @param string $id ID attribute value. |
|
1018 | - * @return string/boolean Page on success. |
|
1019 | - * @access public |
|
1020 | - */ |
|
1021 | - function clickLinkById($id) { |
|
1022 | - if (! ($url = $this->_page->getUrlById($id))) { |
|
1023 | - return false; |
|
1024 | - } |
|
1025 | - $this->_load($url, new SimpleGetEncoding()); |
|
1026 | - return $this->getContent(); |
|
1027 | - } |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * Tests to see if a link is present by ID attribute. |
|
1031 | - * @param string $id Text of id attribute. |
|
1032 | - * @return boolean True if link present. |
|
1033 | - * @access public |
|
1034 | - */ |
|
1035 | - function isLinkById($id) { |
|
1036 | - return (boolean)$this->_page->getUrlById($id); |
|
1037 | - } |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * Clicks a visible text item. Will first try buttons, |
|
1041 | - * then links and then images. |
|
1042 | - * @param string $label Visible text or alt text. |
|
1043 | - * @return string/boolean Raw page or false. |
|
1044 | - * @access public |
|
1045 | - */ |
|
1046 | - function click($label) { |
|
1047 | - $raw = $this->clickSubmit($label); |
|
1048 | - if (! $raw) { |
|
1049 | - $raw = $this->clickLink($label); |
|
1050 | - } |
|
1051 | - if (! $raw) { |
|
1052 | - $raw = $this->clickImage($label); |
|
1053 | - } |
|
1054 | - return $raw; |
|
1055 | - } |
|
1056 | - } |
|
1057 | 159 | \ No newline at end of file |
160 | + */ |
|
161 | + class SimpleBrowser { |
|
162 | + protected $_user_agent; |
|
163 | + protected $_page; |
|
164 | + protected $_history; |
|
165 | + protected $_ignore_frames; |
|
166 | + protected $_maximum_nested_frames; |
|
167 | + |
|
168 | + /** |
|
169 | + * Starts with a fresh browser with no |
|
170 | + * cookie or any other state information. The |
|
171 | + * exception is that a default proxy will be |
|
172 | + * set up if specified in the options. |
|
173 | + * @access public |
|
174 | + */ |
|
175 | + function SimpleBrowser() { |
|
176 | + $this->_user_agent = $this->_createUserAgent(); |
|
177 | + $this->_user_agent->useProxy( |
|
178 | + SimpleTest::getDefaultProxy(), |
|
179 | + SimpleTest::getDefaultProxyUsername(), |
|
180 | + SimpleTest::getDefaultProxyPassword()); |
|
181 | + $this->_page = new SimplePage(); |
|
182 | + $this->_history = $this->_createHistory(); |
|
183 | + $this->_ignore_frames = false; |
|
184 | + $this->_maximum_nested_frames = DEFAULT_MAX_NESTED_FRAMES; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Creates the underlying user agent. |
|
189 | + * @return SimpleFetcher Content fetcher. |
|
190 | + * @access protected |
|
191 | + */ |
|
192 | + function &_createUserAgent() { |
|
193 | + $user_agent = new SimpleUserAgent(); |
|
194 | + return $user_agent; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Creates a new empty history list. |
|
199 | + * @return SimpleBrowserHistory New list. |
|
200 | + * @access protected |
|
201 | + */ |
|
202 | + function &_createHistory() { |
|
203 | + $history = new SimpleBrowserHistory(); |
|
204 | + return $history; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Disables frames support. Frames will not be fetched |
|
209 | + * and the frameset page will be used instead. |
|
210 | + * @access public |
|
211 | + */ |
|
212 | + function ignoreFrames() { |
|
213 | + $this->_ignore_frames = true; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Enables frames support. Frames will be fetched from |
|
218 | + * now on. |
|
219 | + * @access public |
|
220 | + */ |
|
221 | + function useFrames() { |
|
222 | + $this->_ignore_frames = false; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Switches off cookie sending and recieving. |
|
227 | + * @access public |
|
228 | + */ |
|
229 | + function ignoreCookies() { |
|
230 | + $this->_user_agent->ignoreCookies(); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Switches back on the cookie sending and recieving. |
|
235 | + * @access public |
|
236 | + */ |
|
237 | + function useCookies() { |
|
238 | + $this->_user_agent->useCookies(); |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Parses the raw content into a page. Will load further |
|
243 | + * frame pages unless frames are disabled. |
|
244 | + * @param SimpleHttpResponse $response Response from fetch. |
|
245 | + * @param integer $depth Nested frameset depth. |
|
246 | + * @return SimplePage Parsed HTML. |
|
247 | + * @access private |
|
248 | + */ |
|
249 | + function &_parse($response, $depth = 0) { |
|
250 | + $page = $this->_buildPage($response); |
|
251 | + if ($this->_ignore_frames || ! $page->hasFrames() || ($depth > $this->_maximum_nested_frames)) { |
|
252 | + return $page; |
|
253 | + } |
|
254 | + $frameset = new SimpleFrameset($page); |
|
255 | + foreach ($page->getFrameset() as $key => $url) { |
|
256 | + $frame = $this->_fetch($url, new SimpleGetEncoding(), $depth + 1); |
|
257 | + $frameset->addFrame($frame, $key); |
|
258 | + } |
|
259 | + return $frameset; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Assembles the parsing machinery and actually parses |
|
264 | + * a single page. Frees all of the builder memory and so |
|
265 | + * unjams the PHP memory management. |
|
266 | + * @param SimpleHttpResponse $response Response from fetch. |
|
267 | + * @return SimplePage Parsed top level page. |
|
268 | + * @access protected |
|
269 | + */ |
|
270 | + function &_buildPage($response) { |
|
271 | + $builder = new SimplePageBuilder(); |
|
272 | + $page = $builder->parse($response); |
|
273 | + $builder->free(); |
|
274 | + unset($builder); |
|
275 | + return $page; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Fetches a page. Jointly recursive with the _parse() |
|
280 | + * method as it descends a frameset. |
|
281 | + * @param string/SimpleUrl $url Target to fetch. |
|
282 | + * @param SimpleEncoding $encoding GET/POST parameters. |
|
283 | + * @param integer $depth Nested frameset depth protection. |
|
284 | + * @return SimplePage Parsed page. |
|
285 | + * @access private |
|
286 | + */ |
|
287 | + function &_fetch($url, $encoding, $depth = 0) { |
|
288 | + $response = $this->_user_agent->fetchResponse($url, $encoding); |
|
289 | + if ($response->isError()) { |
|
290 | + $page = new SimplePage($response); |
|
291 | + } else { |
|
292 | + $page = $this->_parse($response, $depth); |
|
293 | + } |
|
294 | + return $page; |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Fetches a page or a single frame if that is the current |
|
299 | + * focus. |
|
300 | + * @param SimpleUrl $url Target to fetch. |
|
301 | + * @param SimpleEncoding $parameters GET/POST parameters. |
|
302 | + * @return string Raw content of page. |
|
303 | + * @access private |
|
304 | + */ |
|
305 | + function _load($url, $parameters) { |
|
306 | + $frame = $url->getTarget(); |
|
307 | + if (! $frame || ! $this->_page->hasFrames() || (strtolower($frame) == '_top')) { |
|
308 | + return $this->_loadPage($url, $parameters); |
|
309 | + } |
|
310 | + return $this->_loadFrame(array($frame), $url, $parameters); |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Fetches a page and makes it the current page/frame. |
|
315 | + * @param string/SimpleUrl $url Target to fetch as string. |
|
316 | + * @param SimplePostEncoding $parameters POST parameters. |
|
317 | + * @return string Raw content of page. |
|
318 | + * @access private |
|
319 | + */ |
|
320 | + function _loadPage($url, $parameters) { |
|
321 | + $this->_page = $this->_fetch($url, $parameters); |
|
322 | + $this->_history->recordEntry( |
|
323 | + $this->_page->getUrl(), |
|
324 | + $this->_page->getRequestData()); |
|
325 | + return $this->_page->getRaw(); |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Fetches a frame into the existing frameset replacing the |
|
330 | + * original. |
|
331 | + * @param array $frames List of names to drill down. |
|
332 | + * @param string/SimpleUrl $url Target to fetch as string. |
|
333 | + * @param SimpleFormEncoding $parameters POST parameters. |
|
334 | + * @return string Raw content of page. |
|
335 | + * @access private |
|
336 | + */ |
|
337 | + function _loadFrame($frames, $url, $parameters) { |
|
338 | + $page = $this->_fetch($url, $parameters); |
|
339 | + $this->_page->setFrame($frames, $page); |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Removes expired and temporary cookies as if |
|
344 | + * the browser was closed and re-opened. |
|
345 | + * @param string/integer $date Time when session restarted. |
|
346 | + * If omitted then all persistent |
|
347 | + * cookies are kept. |
|
348 | + * @access public |
|
349 | + */ |
|
350 | + function restart($date = false) { |
|
351 | + $this->_user_agent->restart($date); |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Adds a header to every fetch. |
|
356 | + * @param string $header Header line to add to every |
|
357 | + * request until cleared. |
|
358 | + * @access public |
|
359 | + */ |
|
360 | + function addHeader($header) { |
|
361 | + $this->_user_agent->addHeader($header); |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * Ages the cookies by the specified time. |
|
366 | + * @param integer $interval Amount in seconds. |
|
367 | + * @access public |
|
368 | + */ |
|
369 | + function ageCookies($interval) { |
|
370 | + $this->_user_agent->ageCookies($interval); |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Sets an additional cookie. If a cookie has |
|
375 | + * the same name and path it is replaced. |
|
376 | + * @param string $name Cookie key. |
|
377 | + * @param string $value Value of cookie. |
|
378 | + * @param string $host Host upon which the cookie is valid. |
|
379 | + * @param string $path Cookie path if not host wide. |
|
380 | + * @param string $expiry Expiry date. |
|
381 | + * @access public |
|
382 | + */ |
|
383 | + function setCookie($name, $value, $host = false, $path = '/', $expiry = false) { |
|
384 | + $this->_user_agent->setCookie($name, $value, $host, $path, $expiry); |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Reads the most specific cookie value from the |
|
389 | + * browser cookies. |
|
390 | + * @param string $host Host to search. |
|
391 | + * @param string $path Applicable path. |
|
392 | + * @param string $name Name of cookie to read. |
|
393 | + * @return string False if not present, else the |
|
394 | + * value as a string. |
|
395 | + * @access public |
|
396 | + */ |
|
397 | + function getCookieValue($host, $path, $name) { |
|
398 | + return $this->_user_agent->getCookieValue($host, $path, $name); |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Reads the current cookies for the current URL. |
|
403 | + * @param string $name Key of cookie to find. |
|
404 | + * @return string Null if there is no current URL, false |
|
405 | + * if the cookie is not set. |
|
406 | + * @access public |
|
407 | + */ |
|
408 | + function getCurrentCookieValue($name) { |
|
409 | + return $this->_user_agent->getBaseCookieValue($name, $this->_page->getUrl()); |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Sets the maximum number of redirects before |
|
414 | + * a page will be loaded anyway. |
|
415 | + * @param integer $max Most hops allowed. |
|
416 | + * @access public |
|
417 | + */ |
|
418 | + function setMaximumRedirects($max) { |
|
419 | + $this->_user_agent->setMaximumRedirects($max); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Sets the maximum number of nesting of framed pages |
|
424 | + * within a framed page to prevent loops. |
|
425 | + * @param integer $max Highest depth allowed. |
|
426 | + * @access public |
|
427 | + */ |
|
428 | + function setMaximumNestedFrames($max) { |
|
429 | + $this->_maximum_nested_frames = $max; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Sets the socket timeout for opening a connection. |
|
434 | + * @param integer $timeout Maximum time in seconds. |
|
435 | + * @access public |
|
436 | + */ |
|
437 | + function setConnectionTimeout($timeout) { |
|
438 | + $this->_user_agent->setConnectionTimeout($timeout); |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Sets proxy to use on all requests for when |
|
443 | + * testing from behind a firewall. Set URL |
|
444 | + * to false to disable. |
|
445 | + * @param string $proxy Proxy URL. |
|
446 | + * @param string $username Proxy username for authentication. |
|
447 | + * @param string $password Proxy password for authentication. |
|
448 | + * @access public |
|
449 | + */ |
|
450 | + function useProxy($proxy, $username = false, $password = false) { |
|
451 | + $this->_user_agent->useProxy($proxy, $username, $password); |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * Fetches the page content with a HEAD request. |
|
456 | + * Will affect cookies, but will not change the base URL. |
|
457 | + * @param string/SimpleUrl $url Target to fetch as string. |
|
458 | + * @param hash/SimpleHeadEncoding $parameters Additional parameters for |
|
459 | + * HEAD request. |
|
460 | + * @return boolean True if successful. |
|
461 | + * @access public |
|
462 | + */ |
|
463 | + function head($url, $parameters = false) { |
|
464 | + if (! is_object($url)) { |
|
465 | + $url = new SimpleUrl($url); |
|
466 | + } |
|
467 | + if ($this->getUrl()) { |
|
468 | + $url = $url->makeAbsolute($this->getUrl()); |
|
469 | + } |
|
470 | + $response = $this->_user_agent->fetchResponse($url, new SimpleHeadEncoding($parameters)); |
|
471 | + return ! $response->isError(); |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * Fetches the page content with a simple GET request. |
|
476 | + * @param string/SimpleUrl $url Target to fetch. |
|
477 | + * @param hash/SimpleFormEncoding $parameters Additional parameters for |
|
478 | + * GET request. |
|
479 | + * @return string Content of page or false. |
|
480 | + * @access public |
|
481 | + */ |
|
482 | + function get($url, $parameters = false) { |
|
483 | + if (! is_object($url)) { |
|
484 | + $url = new SimpleUrl($url); |
|
485 | + } |
|
486 | + if ($this->getUrl()) { |
|
487 | + $url = $url->makeAbsolute($this->getUrl()); |
|
488 | + } |
|
489 | + return $this->_load($url, new SimpleGetEncoding($parameters)); |
|
490 | + } |
|
491 | + |
|
492 | + /** |
|
493 | + * Fetches the page content with a POST request. |
|
494 | + * @param string/SimpleUrl $url Target to fetch as string. |
|
495 | + * @param hash/SimpleFormEncoding $parameters POST parameters. |
|
496 | + * @return string Content of page. |
|
497 | + * @access public |
|
498 | + */ |
|
499 | + function post($url, $parameters = false) { |
|
500 | + if (! is_object($url)) { |
|
501 | + $url = new SimpleUrl($url); |
|
502 | + } |
|
503 | + if ($this->getUrl()) { |
|
504 | + $url = $url->makeAbsolute($this->getUrl()); |
|
505 | + } |
|
506 | + return $this->_load($url, new SimplePostEncoding($parameters)); |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * Equivalent to hitting the retry button on the |
|
511 | + * browser. Will attempt to repeat the page fetch. If |
|
512 | + * there is no history to repeat it will give false. |
|
513 | + * @return string/boolean Content if fetch succeeded |
|
514 | + * else false. |
|
515 | + * @access public |
|
516 | + */ |
|
517 | + function retry() { |
|
518 | + $frames = $this->_page->getFrameFocus(); |
|
519 | + if (count($frames) > 0) { |
|
520 | + $this->_loadFrame( |
|
521 | + $frames, |
|
522 | + $this->_page->getUrl(), |
|
523 | + $this->_page->getRequestData()); |
|
524 | + return $this->_page->getRaw(); |
|
525 | + } |
|
526 | + if ($url = $this->_history->getUrl()) { |
|
527 | + $this->_page = $this->_fetch($url, $this->_history->getParameters()); |
|
528 | + return $this->_page->getRaw(); |
|
529 | + } |
|
530 | + return false; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Equivalent to hitting the back button on the |
|
535 | + * browser. The browser history is unchanged on |
|
536 | + * failure. The page content is refetched as there |
|
537 | + * is no concept of content caching in SimpleTest. |
|
538 | + * @return boolean True if history entry and |
|
539 | + * fetch succeeded |
|
540 | + * @access public |
|
541 | + */ |
|
542 | + function back() { |
|
543 | + if (! $this->_history->back()) { |
|
544 | + return false; |
|
545 | + } |
|
546 | + $content = $this->retry(); |
|
547 | + if (! $content) { |
|
548 | + $this->_history->forward(); |
|
549 | + } |
|
550 | + return $content; |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Equivalent to hitting the forward button on the |
|
555 | + * browser. The browser history is unchanged on |
|
556 | + * failure. The page content is refetched as there |
|
557 | + * is no concept of content caching in SimpleTest. |
|
558 | + * @return boolean True if history entry and |
|
559 | + * fetch succeeded |
|
560 | + * @access public |
|
561 | + */ |
|
562 | + function forward() { |
|
563 | + if (! $this->_history->forward()) { |
|
564 | + return false; |
|
565 | + } |
|
566 | + $content = $this->retry(); |
|
567 | + if (! $content) { |
|
568 | + $this->_history->back(); |
|
569 | + } |
|
570 | + return $content; |
|
571 | + } |
|
572 | + |
|
573 | + /** |
|
574 | + * Retries a request after setting the authentication |
|
575 | + * for the current realm. |
|
576 | + * @param string $username Username for realm. |
|
577 | + * @param string $password Password for realm. |
|
578 | + * @return boolean True if successful fetch. Note |
|
579 | + * that authentication may still have |
|
580 | + * failed. |
|
581 | + * @access public |
|
582 | + */ |
|
583 | + function authenticate($username, $password) { |
|
584 | + if (! $this->_page->getRealm()) { |
|
585 | + return false; |
|
586 | + } |
|
587 | + $url = $this->_page->getUrl(); |
|
588 | + if (! $url) { |
|
589 | + return false; |
|
590 | + } |
|
591 | + $this->_user_agent->setIdentity( |
|
592 | + $url->getHost(), |
|
593 | + $this->_page->getRealm(), |
|
594 | + $username, |
|
595 | + $password); |
|
596 | + return $this->retry(); |
|
597 | + } |
|
598 | + |
|
599 | + /** |
|
600 | + * Accessor for a breakdown of the frameset. |
|
601 | + * @return array Hash tree of frames by name |
|
602 | + * or index if no name. |
|
603 | + * @access public |
|
604 | + */ |
|
605 | + function getFrames() { |
|
606 | + return $this->_page->getFrames(); |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Accessor for current frame focus. Will be |
|
611 | + * false if no frame has focus. |
|
612 | + * @return integer/string/boolean Label if any, otherwise |
|
613 | + * the position in the frameset |
|
614 | + * or false if none. |
|
615 | + * @access public |
|
616 | + */ |
|
617 | + function getFrameFocus() { |
|
618 | + return $this->_page->getFrameFocus(); |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Sets the focus by index. The integer index starts from 1. |
|
623 | + * @param integer $choice Chosen frame. |
|
624 | + * @return boolean True if frame exists. |
|
625 | + * @access public |
|
626 | + */ |
|
627 | + function setFrameFocusByIndex($choice) { |
|
628 | + return $this->_page->setFrameFocusByIndex($choice); |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | + * Sets the focus by name. |
|
633 | + * @param string $name Chosen frame. |
|
634 | + * @return boolean True if frame exists. |
|
635 | + * @access public |
|
636 | + */ |
|
637 | + function setFrameFocus($name) { |
|
638 | + return $this->_page->setFrameFocus($name); |
|
639 | + } |
|
640 | + |
|
641 | + /** |
|
642 | + * Clears the frame focus. All frames will be searched |
|
643 | + * for content. |
|
644 | + * @access public |
|
645 | + */ |
|
646 | + function clearFrameFocus() { |
|
647 | + return $this->_page->clearFrameFocus(); |
|
648 | + } |
|
649 | + |
|
650 | + /** |
|
651 | + * Accessor for last error. |
|
652 | + * @return string Error from last response. |
|
653 | + * @access public |
|
654 | + */ |
|
655 | + function getTransportError() { |
|
656 | + return $this->_page->getTransportError(); |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Accessor for current MIME type. |
|
661 | + * @return string MIME type as string; e.g. 'text/html' |
|
662 | + * @access public |
|
663 | + */ |
|
664 | + function getMimeType() { |
|
665 | + return $this->_page->getMimeType(); |
|
666 | + } |
|
667 | + |
|
668 | + /** |
|
669 | + * Accessor for last response code. |
|
670 | + * @return integer Last HTTP response code received. |
|
671 | + * @access public |
|
672 | + */ |
|
673 | + function getResponseCode() { |
|
674 | + return $this->_page->getResponseCode(); |
|
675 | + } |
|
676 | + |
|
677 | + /** |
|
678 | + * Accessor for last Authentication type. Only valid |
|
679 | + * straight after a challenge (401). |
|
680 | + * @return string Description of challenge type. |
|
681 | + * @access public |
|
682 | + */ |
|
683 | + function getAuthentication() { |
|
684 | + return $this->_page->getAuthentication(); |
|
685 | + } |
|
686 | + |
|
687 | + /** |
|
688 | + * Accessor for last Authentication realm. Only valid |
|
689 | + * straight after a challenge (401). |
|
690 | + * @return string Name of security realm. |
|
691 | + * @access public |
|
692 | + */ |
|
693 | + function getRealm() { |
|
694 | + return $this->_page->getRealm(); |
|
695 | + } |
|
696 | + |
|
697 | + /** |
|
698 | + * Accessor for current URL of page or frame if |
|
699 | + * focused. |
|
700 | + * @return string Location of current page or frame as |
|
701 | + * a string. |
|
702 | + */ |
|
703 | + function getUrl() { |
|
704 | + $url = $this->_page->getUrl(); |
|
705 | + return $url ? $url->asString() : false; |
|
706 | + } |
|
707 | + |
|
708 | + /** |
|
709 | + * Accessor for raw bytes sent down the wire. |
|
710 | + * @return string Original text sent. |
|
711 | + * @access public |
|
712 | + */ |
|
713 | + function getRequest() { |
|
714 | + return $this->_page->getRequest(); |
|
715 | + } |
|
716 | + |
|
717 | + /** |
|
718 | + * Accessor for raw header information. |
|
719 | + * @return string Header block. |
|
720 | + * @access public |
|
721 | + */ |
|
722 | + function getHeaders() { |
|
723 | + return $this->_page->getHeaders(); |
|
724 | + } |
|
725 | + |
|
726 | + /** |
|
727 | + * Accessor for raw page information. |
|
728 | + * @return string Original text content of web page. |
|
729 | + * @access public |
|
730 | + */ |
|
731 | + function getContent() { |
|
732 | + return $this->_page->getRaw(); |
|
733 | + } |
|
734 | + |
|
735 | + /** |
|
736 | + * Accessor for plain text version of the page. |
|
737 | + * @return string Normalised text representation. |
|
738 | + * @access public |
|
739 | + */ |
|
740 | + function getContentAsText() { |
|
741 | + return $this->_page->getText(); |
|
742 | + } |
|
743 | + |
|
744 | + /** |
|
745 | + * Accessor for parsed title. |
|
746 | + * @return string Title or false if no title is present. |
|
747 | + * @access public |
|
748 | + */ |
|
749 | + function getTitle() { |
|
750 | + return $this->_page->getTitle(); |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | + * Accessor for a list of all fixed links in current page. |
|
755 | + * @return array List of urls with scheme of |
|
756 | + * http or https and hostname. |
|
757 | + * @access public |
|
758 | + */ |
|
759 | + function getAbsoluteUrls() { |
|
760 | + return $this->_page->getAbsoluteUrls(); |
|
761 | + } |
|
762 | + |
|
763 | + /** |
|
764 | + * Accessor for a list of all relative links. |
|
765 | + * @return array List of urls without hostname. |
|
766 | + * @access public |
|
767 | + */ |
|
768 | + function getRelativeUrls() { |
|
769 | + return $this->_page->getRelativeUrls(); |
|
770 | + } |
|
771 | + |
|
772 | + /** |
|
773 | + * Sets all form fields with that name. |
|
774 | + * @param string $label Name or label of field in forms. |
|
775 | + * @param string $value New value of field. |
|
776 | + * @return boolean True if field exists, otherwise false. |
|
777 | + * @access public |
|
778 | + */ |
|
779 | + function setField($label, $value) { |
|
780 | + return $this->_page->setField(new SimpleByLabelOrName($label), $value); |
|
781 | + } |
|
782 | + |
|
783 | + /** |
|
784 | + * Sets all form fields with that name. Will use label if |
|
785 | + * one is available (not yet implemented). |
|
786 | + * @param string $name Name of field in forms. |
|
787 | + * @param string $value New value of field. |
|
788 | + * @return boolean True if field exists, otherwise false. |
|
789 | + * @access public |
|
790 | + */ |
|
791 | + function setFieldByName($name, $value) { |
|
792 | + return $this->_page->setField(new SimpleByName($name), $value); |
|
793 | + } |
|
794 | + |
|
795 | + /** |
|
796 | + * Sets all form fields with that id attribute. |
|
797 | + * @param string/integer $id Id of field in forms. |
|
798 | + * @param string $value New value of field. |
|
799 | + * @return boolean True if field exists, otherwise false. |
|
800 | + * @access public |
|
801 | + */ |
|
802 | + function setFieldById($id, $value) { |
|
803 | + return $this->_page->setField(new SimpleById($id), $value); |
|
804 | + } |
|
805 | + |
|
806 | + /** |
|
807 | + * Accessor for a form element value within the page. |
|
808 | + * Finds the first match. |
|
809 | + * @param string $label Field label. |
|
810 | + * @return string/boolean A value if the field is |
|
811 | + * present, false if unchecked |
|
812 | + * and null if missing. |
|
813 | + * @access public |
|
814 | + */ |
|
815 | + function getField($label) { |
|
816 | + return $this->_page->getField(new SimpleByLabelOrName($label)); |
|
817 | + } |
|
818 | + |
|
819 | + /** |
|
820 | + * Accessor for a form element value within the page. |
|
821 | + * Finds the first match. |
|
822 | + * @param string $name Field name. |
|
823 | + * @return string/boolean A string if the field is |
|
824 | + * present, false if unchecked |
|
825 | + * and null if missing. |
|
826 | + * @access public |
|
827 | + */ |
|
828 | + function getFieldByName($name) { |
|
829 | + return $this->_page->getField(new SimpleByName($name)); |
|
830 | + } |
|
831 | + |
|
832 | + /** |
|
833 | + * Accessor for a form element value within the page. |
|
834 | + * @param string/integer $id Id of field in forms. |
|
835 | + * @return string/boolean A string if the field is |
|
836 | + * present, false if unchecked |
|
837 | + * and null if missing. |
|
838 | + * @access public |
|
839 | + */ |
|
840 | + function getFieldById($id) { |
|
841 | + return $this->_page->getField(new SimpleById($id)); |
|
842 | + } |
|
843 | + |
|
844 | + /** |
|
845 | + * Clicks the submit button by label. The owning |
|
846 | + * form will be submitted by this. |
|
847 | + * @param string $label Button label. An unlabeled |
|
848 | + * button can be triggered by 'Submit'. |
|
849 | + * @param hash $additional Additional form data. |
|
850 | + * @return string/boolean Page on success. |
|
851 | + * @access public |
|
852 | + */ |
|
853 | + function clickSubmit($label = 'Submit', $additional = false) { |
|
854 | + if (! ($form = $this->_page->getFormBySubmit(new SimpleByLabel($label)))) { |
|
855 | + return false; |
|
856 | + } |
|
857 | + $success = $this->_load( |
|
858 | + $form->getAction(), |
|
859 | + $form->submitButton(new SimpleByLabel($label), $additional)); |
|
860 | + return ($success ? $this->getContent() : $success); |
|
861 | + } |
|
862 | + |
|
863 | + /** |
|
864 | + * Clicks the submit button by name attribute. The owning |
|
865 | + * form will be submitted by this. |
|
866 | + * @param string $name Button name. |
|
867 | + * @param hash $additional Additional form data. |
|
868 | + * @return string/boolean Page on success. |
|
869 | + * @access public |
|
870 | + */ |
|
871 | + function clickSubmitByName($name, $additional = false) { |
|
872 | + if (! ($form = $this->_page->getFormBySubmit(new SimpleByName($name)))) { |
|
873 | + return false; |
|
874 | + } |
|
875 | + $success = $this->_load( |
|
876 | + $form->getAction(), |
|
877 | + $form->submitButton(new SimpleByName($name), $additional)); |
|
878 | + return ($success ? $this->getContent() : $success); |
|
879 | + } |
|
880 | + |
|
881 | + /** |
|
882 | + * Clicks the submit button by ID attribute of the button |
|
883 | + * itself. The owning form will be submitted by this. |
|
884 | + * @param string $id Button ID. |
|
885 | + * @param hash $additional Additional form data. |
|
886 | + * @return string/boolean Page on success. |
|
887 | + * @access public |
|
888 | + */ |
|
889 | + function clickSubmitById($id, $additional = false) { |
|
890 | + if (! ($form = $this->_page->getFormBySubmit(new SimpleById($id)))) { |
|
891 | + return false; |
|
892 | + } |
|
893 | + $success = $this->_load( |
|
894 | + $form->getAction(), |
|
895 | + $form->submitButton(new SimpleById($id), $additional)); |
|
896 | + return ($success ? $this->getContent() : $success); |
|
897 | + } |
|
898 | + |
|
899 | + /** |
|
900 | + * Clicks the submit image by some kind of label. Usually |
|
901 | + * the alt tag or the nearest equivalent. The owning |
|
902 | + * form will be submitted by this. Clicking outside of |
|
903 | + * the boundary of the coordinates will result in |
|
904 | + * a failure. |
|
905 | + * @param string $label ID attribute of button. |
|
906 | + * @param integer $x X-coordinate of imaginary click. |
|
907 | + * @param integer $y Y-coordinate of imaginary click. |
|
908 | + * @param hash $additional Additional form data. |
|
909 | + * @return string/boolean Page on success. |
|
910 | + * @access public |
|
911 | + */ |
|
912 | + function clickImage($label, $x = 1, $y = 1, $additional = false) { |
|
913 | + if (! ($form = $this->_page->getFormByImage(new SimpleByLabel($label)))) { |
|
914 | + return false; |
|
915 | + } |
|
916 | + $success = $this->_load( |
|
917 | + $form->getAction(), |
|
918 | + $form->submitImage(new SimpleByLabel($label), $x, $y, $additional)); |
|
919 | + return ($success ? $this->getContent() : $success); |
|
920 | + } |
|
921 | + |
|
922 | + /** |
|
923 | + * Clicks the submit image by the name. Usually |
|
924 | + * the alt tag or the nearest equivalent. The owning |
|
925 | + * form will be submitted by this. Clicking outside of |
|
926 | + * the boundary of the coordinates will result in |
|
927 | + * a failure. |
|
928 | + * @param string $name Name attribute of button. |
|
929 | + * @param integer $x X-coordinate of imaginary click. |
|
930 | + * @param integer $y Y-coordinate of imaginary click. |
|
931 | + * @param hash $additional Additional form data. |
|
932 | + * @return string/boolean Page on success. |
|
933 | + * @access public |
|
934 | + */ |
|
935 | + function clickImageByName($name, $x = 1, $y = 1, $additional = false) { |
|
936 | + if (! ($form = $this->_page->getFormByImage(new SimpleByName($name)))) { |
|
937 | + return false; |
|
938 | + } |
|
939 | + $success = $this->_load( |
|
940 | + $form->getAction(), |
|
941 | + $form->submitImage(new SimpleByName($name), $x, $y, $additional)); |
|
942 | + return ($success ? $this->getContent() : $success); |
|
943 | + } |
|
944 | + |
|
945 | + /** |
|
946 | + * Clicks the submit image by ID attribute. The owning |
|
947 | + * form will be submitted by this. Clicking outside of |
|
948 | + * the boundary of the coordinates will result in |
|
949 | + * a failure. |
|
950 | + * @param integer/string $id ID attribute of button. |
|
951 | + * @param integer $x X-coordinate of imaginary click. |
|
952 | + * @param integer $y Y-coordinate of imaginary click. |
|
953 | + * @param hash $additional Additional form data. |
|
954 | + * @return string/boolean Page on success. |
|
955 | + * @access public |
|
956 | + */ |
|
957 | + function clickImageById($id, $x = 1, $y = 1, $additional = false) { |
|
958 | + if (! ($form = $this->_page->getFormByImage(new SimpleById($id)))) { |
|
959 | + return false; |
|
960 | + } |
|
961 | + $success = $this->_load( |
|
962 | + $form->getAction(), |
|
963 | + $form->submitImage(new SimpleById($id), $x, $y, $additional)); |
|
964 | + return ($success ? $this->getContent() : $success); |
|
965 | + } |
|
966 | + |
|
967 | + /** |
|
968 | + * Submits a form by the ID. |
|
969 | + * @param string $id The form ID. No submit button value |
|
970 | + * will be sent. |
|
971 | + * @return string/boolean Page on success. |
|
972 | + * @access public |
|
973 | + */ |
|
974 | + function submitFormById($id) { |
|
975 | + if (! ($form = $this->_page->getFormById($id))) { |
|
976 | + return false; |
|
977 | + } |
|
978 | + $success = $this->_load( |
|
979 | + $form->getAction(), |
|
980 | + $form->submit()); |
|
981 | + return ($success ? $this->getContent() : $success); |
|
982 | + } |
|
983 | + |
|
984 | + /** |
|
985 | + * Follows a link by label. Will click the first link |
|
986 | + * found with this link text by default, or a later |
|
987 | + * one if an index is given. The match ignores case and |
|
988 | + * white space issues. |
|
989 | + * @param string $label Text between the anchor tags. |
|
990 | + * @param integer $index Link position counting from zero. |
|
991 | + * @return string/boolean Page on success. |
|
992 | + * @access public |
|
993 | + */ |
|
994 | + function clickLink($label, $index = 0) { |
|
995 | + $urls = $this->_page->getUrlsByLabel($label); |
|
996 | + if (count($urls) == 0) { |
|
997 | + return false; |
|
998 | + } |
|
999 | + if (count($urls) < $index + 1) { |
|
1000 | + return false; |
|
1001 | + } |
|
1002 | + $this->_load($urls[$index], new SimpleGetEncoding()); |
|
1003 | + return $this->getContent(); |
|
1004 | + } |
|
1005 | + |
|
1006 | + /** |
|
1007 | + * Tests to see if a link is present by label. |
|
1008 | + * @param string $label Text of value attribute. |
|
1009 | + * @return boolean True if link present. |
|
1010 | + * @access public |
|
1011 | + */ |
|
1012 | + function isLink($label) { |
|
1013 | + return (count($this->_page->getUrlsByLabel($label)) > 0); |
|
1014 | + } |
|
1015 | + |
|
1016 | + /** |
|
1017 | + * Follows a link by id attribute. |
|
1018 | + * @param string $id ID attribute value. |
|
1019 | + * @return string/boolean Page on success. |
|
1020 | + * @access public |
|
1021 | + */ |
|
1022 | + function clickLinkById($id) { |
|
1023 | + if (! ($url = $this->_page->getUrlById($id))) { |
|
1024 | + return false; |
|
1025 | + } |
|
1026 | + $this->_load($url, new SimpleGetEncoding()); |
|
1027 | + return $this->getContent(); |
|
1028 | + } |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * Tests to see if a link is present by ID attribute. |
|
1032 | + * @param string $id Text of id attribute. |
|
1033 | + * @return boolean True if link present. |
|
1034 | + * @access public |
|
1035 | + */ |
|
1036 | + function isLinkById($id) { |
|
1037 | + return (boolean)$this->_page->getUrlById($id); |
|
1038 | + } |
|
1039 | + |
|
1040 | + /** |
|
1041 | + * Clicks a visible text item. Will first try buttons, |
|
1042 | + * then links and then images. |
|
1043 | + * @param string $label Visible text or alt text. |
|
1044 | + * @return string/boolean Raw page or false. |
|
1045 | + * @access public |
|
1046 | + */ |
|
1047 | + function click($label) { |
|
1048 | + $raw = $this->clickSubmit($label); |
|
1049 | + if (! $raw) { |
|
1050 | + $raw = $this->clickLink($label); |
|
1051 | + } |
|
1052 | + if (! $raw) { |
|
1053 | + $raw = $this->clickImage($label); |
|
1054 | + } |
|
1055 | + return $raw; |
|
1056 | + } |
|
1057 | + } |
|
1058 | 1058 | \ No newline at end of file |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @access private |
56 | 56 | */ |
57 | 57 | function _atBeginning() { |
58 | - return ($this->_position == 0) && ! $this->_isEmpty(); |
|
58 | + return ($this->_position == 0) && !$this->_isEmpty(); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @access private |
65 | 65 | */ |
66 | 66 | function _atEnd() { |
67 | - return ($this->_position + 1 >= count($this->_sequence)) && ! $this->_isEmpty(); |
|
67 | + return ($this->_position + 1 >= count($this->_sequence)) && !$this->_isEmpty(); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | if ($this->_isEmpty()) { |
145 | 145 | return; |
146 | 146 | } |
147 | - while (! $this->_atEnd()) { |
|
147 | + while (!$this->_atEnd()) { |
|
148 | 148 | array_pop($this->_sequence); |
149 | 149 | } |
150 | 150 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | */ |
248 | 248 | function &_parse($response, $depth = 0) { |
249 | 249 | $page = $this->_buildPage($response); |
250 | - if ($this->_ignore_frames || ! $page->hasFrames() || ($depth > $this->_maximum_nested_frames)) { |
|
250 | + if ($this->_ignore_frames || !$page->hasFrames() || ($depth > $this->_maximum_nested_frames)) { |
|
251 | 251 | return $page; |
252 | 252 | } |
253 | 253 | $frameset = new SimpleFrameset($page); |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | */ |
304 | 304 | function _load($url, $parameters) { |
305 | 305 | $frame = $url->getTarget(); |
306 | - if (! $frame || ! $this->_page->hasFrames() || (strtolower($frame) == '_top')) { |
|
306 | + if (!$frame || !$this->_page->hasFrames() || (strtolower($frame) == '_top')) { |
|
307 | 307 | return $this->_loadPage($url, $parameters); |
308 | 308 | } |
309 | 309 | return $this->_loadFrame(array($frame), $url, $parameters); |
@@ -460,14 +460,14 @@ discard block |
||
460 | 460 | * @access public |
461 | 461 | */ |
462 | 462 | function head($url, $parameters = false) { |
463 | - if (! is_object($url)) { |
|
463 | + if (!is_object($url)) { |
|
464 | 464 | $url = new SimpleUrl($url); |
465 | 465 | } |
466 | 466 | if ($this->getUrl()) { |
467 | 467 | $url = $url->makeAbsolute($this->getUrl()); |
468 | 468 | } |
469 | 469 | $response = $this->_user_agent->fetchResponse($url, new SimpleHeadEncoding($parameters)); |
470 | - return ! $response->isError(); |
|
470 | + return !$response->isError(); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | /** |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | * @access public |
480 | 480 | */ |
481 | 481 | function get($url, $parameters = false) { |
482 | - if (! is_object($url)) { |
|
482 | + if (!is_object($url)) { |
|
483 | 483 | $url = new SimpleUrl($url); |
484 | 484 | } |
485 | 485 | if ($this->getUrl()) { |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | * @access public |
497 | 497 | */ |
498 | 498 | function post($url, $parameters = false) { |
499 | - if (! is_object($url)) { |
|
499 | + if (!is_object($url)) { |
|
500 | 500 | $url = new SimpleUrl($url); |
501 | 501 | } |
502 | 502 | if ($this->getUrl()) { |
@@ -539,11 +539,11 @@ discard block |
||
539 | 539 | * @access public |
540 | 540 | */ |
541 | 541 | function back() { |
542 | - if (! $this->_history->back()) { |
|
542 | + if (!$this->_history->back()) { |
|
543 | 543 | return false; |
544 | 544 | } |
545 | 545 | $content = $this->retry(); |
546 | - if (! $content) { |
|
546 | + if (!$content) { |
|
547 | 547 | $this->_history->forward(); |
548 | 548 | } |
549 | 549 | return $content; |
@@ -559,11 +559,11 @@ discard block |
||
559 | 559 | * @access public |
560 | 560 | */ |
561 | 561 | function forward() { |
562 | - if (! $this->_history->forward()) { |
|
562 | + if (!$this->_history->forward()) { |
|
563 | 563 | return false; |
564 | 564 | } |
565 | 565 | $content = $this->retry(); |
566 | - if (! $content) { |
|
566 | + if (!$content) { |
|
567 | 567 | $this->_history->back(); |
568 | 568 | } |
569 | 569 | return $content; |
@@ -580,11 +580,11 @@ discard block |
||
580 | 580 | * @access public |
581 | 581 | */ |
582 | 582 | function authenticate($username, $password) { |
583 | - if (! $this->_page->getRealm()) { |
|
583 | + if (!$this->_page->getRealm()) { |
|
584 | 584 | return false; |
585 | 585 | } |
586 | 586 | $url = $this->_page->getUrl(); |
587 | - if (! $url) { |
|
587 | + if (!$url) { |
|
588 | 588 | return false; |
589 | 589 | } |
590 | 590 | $this->_user_agent->setIdentity( |
@@ -850,7 +850,7 @@ discard block |
||
850 | 850 | * @access public |
851 | 851 | */ |
852 | 852 | function clickSubmit($label = 'Submit', $additional = false) { |
853 | - if (! ($form = $this->_page->getFormBySubmit(new SimpleByLabel($label)))) { |
|
853 | + if (!($form = $this->_page->getFormBySubmit(new SimpleByLabel($label)))) { |
|
854 | 854 | return false; |
855 | 855 | } |
856 | 856 | $success = $this->_load( |
@@ -868,7 +868,7 @@ discard block |
||
868 | 868 | * @access public |
869 | 869 | */ |
870 | 870 | function clickSubmitByName($name, $additional = false) { |
871 | - if (! ($form = $this->_page->getFormBySubmit(new SimpleByName($name)))) { |
|
871 | + if (!($form = $this->_page->getFormBySubmit(new SimpleByName($name)))) { |
|
872 | 872 | return false; |
873 | 873 | } |
874 | 874 | $success = $this->_load( |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | * @access public |
887 | 887 | */ |
888 | 888 | function clickSubmitById($id, $additional = false) { |
889 | - if (! ($form = $this->_page->getFormBySubmit(new SimpleById($id)))) { |
|
889 | + if (!($form = $this->_page->getFormBySubmit(new SimpleById($id)))) { |
|
890 | 890 | return false; |
891 | 891 | } |
892 | 892 | $success = $this->_load( |
@@ -909,7 +909,7 @@ discard block |
||
909 | 909 | * @access public |
910 | 910 | */ |
911 | 911 | function clickImage($label, $x = 1, $y = 1, $additional = false) { |
912 | - if (! ($form = $this->_page->getFormByImage(new SimpleByLabel($label)))) { |
|
912 | + if (!($form = $this->_page->getFormByImage(new SimpleByLabel($label)))) { |
|
913 | 913 | return false; |
914 | 914 | } |
915 | 915 | $success = $this->_load( |
@@ -932,7 +932,7 @@ discard block |
||
932 | 932 | * @access public |
933 | 933 | */ |
934 | 934 | function clickImageByName($name, $x = 1, $y = 1, $additional = false) { |
935 | - if (! ($form = $this->_page->getFormByImage(new SimpleByName($name)))) { |
|
935 | + if (!($form = $this->_page->getFormByImage(new SimpleByName($name)))) { |
|
936 | 936 | return false; |
937 | 937 | } |
938 | 938 | $success = $this->_load( |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | * @access public |
955 | 955 | */ |
956 | 956 | function clickImageById($id, $x = 1, $y = 1, $additional = false) { |
957 | - if (! ($form = $this->_page->getFormByImage(new SimpleById($id)))) { |
|
957 | + if (!($form = $this->_page->getFormByImage(new SimpleById($id)))) { |
|
958 | 958 | return false; |
959 | 959 | } |
960 | 960 | $success = $this->_load( |
@@ -971,7 +971,7 @@ discard block |
||
971 | 971 | * @access public |
972 | 972 | */ |
973 | 973 | function submitFormById($id) { |
974 | - if (! ($form = $this->_page->getFormById($id))) { |
|
974 | + if (!($form = $this->_page->getFormById($id))) { |
|
975 | 975 | return false; |
976 | 976 | } |
977 | 977 | $success = $this->_load( |
@@ -1019,7 +1019,7 @@ discard block |
||
1019 | 1019 | * @access public |
1020 | 1020 | */ |
1021 | 1021 | function clickLinkById($id) { |
1022 | - if (! ($url = $this->_page->getUrlById($id))) { |
|
1022 | + if (!($url = $this->_page->getUrlById($id))) { |
|
1023 | 1023 | return false; |
1024 | 1024 | } |
1025 | 1025 | $this->_load($url, new SimpleGetEncoding()); |
@@ -1033,7 +1033,7 @@ discard block |
||
1033 | 1033 | * @access public |
1034 | 1034 | */ |
1035 | 1035 | function isLinkById($id) { |
1036 | - return (boolean)$this->_page->getUrlById($id); |
|
1036 | + return (boolean) $this->_page->getUrlById($id); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | /** |
@@ -1045,10 +1045,10 @@ discard block |
||
1045 | 1045 | */ |
1046 | 1046 | function click($label) { |
1047 | 1047 | $raw = $this->clickSubmit($label); |
1048 | - if (! $raw) { |
|
1048 | + if (!$raw) { |
|
1049 | 1049 | $raw = $this->clickLink($label); |
1050 | 1050 | } |
1051 | - if (! $raw) { |
|
1051 | + if (!$raw) { |
|
1052 | 1052 | $raw = $this->clickImage($label); |
1053 | 1053 | } |
1054 | 1054 | return $raw; |
@@ -63,7 +63,6 @@ discard block |
||
63 | 63 | * {@link SimplePatternCollector::_handle()}. |
64 | 64 | * |
65 | 65 | * @param object $test Group test with {@link GroupTest::addTestFile()} method. |
66 | - * @param string $filename A filename as generated by {@link collect()} |
|
67 | 66 | * @see collect() |
68 | 67 | * @access protected |
69 | 68 | */ |
@@ -102,7 +101,6 @@ discard block |
||
102 | 101 | * |
103 | 102 | * @see SimpleCollector::_handle() |
104 | 103 | * @param object $test Group test with {@link GroupTest::addTestFile()} method. |
105 | - * @param string $path Directory to scan. |
|
106 | 104 | * @access protected |
107 | 105 | */ |
108 | 106 | function _handle($test, $filename) { |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * This file contains the following classes: {@link SimpleCollector}, |
|
4 | - * {@link SimplePatternCollector}. |
|
5 | - * |
|
6 | - * @author Travis Swicegood <[email protected]> |
|
7 | - * @package SimpleTest |
|
8 | - * @subpackage UnitTester |
|
9 | - */ |
|
3 | + * This file contains the following classes: {@link SimpleCollector}, |
|
4 | + * {@link SimplePatternCollector}. |
|
5 | + * |
|
6 | + * @author Travis Swicegood <[email protected]> |
|
7 | + * @package SimpleTest |
|
8 | + * @subpackage UnitTester |
|
9 | + */ |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * The basic collector for {@link GroupTest} |
@@ -17,61 +17,61 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class SimpleCollector { |
19 | 19 | |
20 | - /** |
|
21 | - * Strips off any kind of slash at the end so as to normalise the path |
|
22 | - * |
|
23 | - * @param string $path Path to normalise. |
|
24 | - */ |
|
25 | - function _removeTrailingSlash($path) { |
|
26 | - return preg_replace('|[\\/]$|', '', $path); |
|
20 | + /** |
|
21 | + * Strips off any kind of slash at the end so as to normalise the path |
|
22 | + * |
|
23 | + * @param string $path Path to normalise. |
|
24 | + */ |
|
25 | + function _removeTrailingSlash($path) { |
|
26 | + return preg_replace('|[\\/]$|', '', $path); |
|
27 | 27 | |
28 | - /** |
|
29 | - * @internal |
|
30 | - * Try benchmarking the following. It's more code, but by not using the |
|
31 | - * regex, it may be faster? Also, shouldn't be looking for |
|
32 | - * DIRECTORY_SEPERATOR instead of a manual "/"? |
|
33 | - */ |
|
34 | - if (substr($path, -1) == DIRECTORY_SEPERATOR) { |
|
35 | - return substr($path, 0, -1); |
|
36 | - } else { |
|
37 | - return $path; |
|
38 | - } |
|
39 | - } |
|
28 | + /** |
|
29 | + * @internal |
|
30 | + * Try benchmarking the following. It's more code, but by not using the |
|
31 | + * regex, it may be faster? Also, shouldn't be looking for |
|
32 | + * DIRECTORY_SEPERATOR instead of a manual "/"? |
|
33 | + */ |
|
34 | + if (substr($path, -1) == DIRECTORY_SEPERATOR) { |
|
35 | + return substr($path, 0, -1); |
|
36 | + } else { |
|
37 | + return $path; |
|
38 | + } |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Scans the directory and adds what it can. |
|
43 | - * @param object $test Group test with {@link GroupTest::addTestFile()} method. |
|
44 | - * @param string $path Directory to scan. |
|
45 | - * @see _attemptToAdd() |
|
46 | - */ |
|
47 | - function collect($test, $path) { |
|
48 | - $path = $this->_removeTrailingSlash($path); |
|
49 | - if ($handle = opendir($path)) { |
|
50 | - while (($entry = readdir($handle)) !== false) { |
|
51 | - $this->_handle($test, $path . DIRECTORY_SEPARATOR . $entry); |
|
52 | - } |
|
53 | - closedir($handle); |
|
54 | - } |
|
55 | - } |
|
41 | + /** |
|
42 | + * Scans the directory and adds what it can. |
|
43 | + * @param object $test Group test with {@link GroupTest::addTestFile()} method. |
|
44 | + * @param string $path Directory to scan. |
|
45 | + * @see _attemptToAdd() |
|
46 | + */ |
|
47 | + function collect($test, $path) { |
|
48 | + $path = $this->_removeTrailingSlash($path); |
|
49 | + if ($handle = opendir($path)) { |
|
50 | + while (($entry = readdir($handle)) !== false) { |
|
51 | + $this->_handle($test, $path . DIRECTORY_SEPARATOR . $entry); |
|
52 | + } |
|
53 | + closedir($handle); |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * This method determines what should be done with a given file and adds |
|
59 | - * it via {@link GroupTest::addTestFile()} if necessary. |
|
60 | - * |
|
61 | - * This method should be overriden to provide custom matching criteria, |
|
62 | - * such as pattern matching, recursive matching, etc. For an example, see |
|
63 | - * {@link SimplePatternCollector::_handle()}. |
|
64 | - * |
|
65 | - * @param object $test Group test with {@link GroupTest::addTestFile()} method. |
|
66 | - * @param string $filename A filename as generated by {@link collect()} |
|
67 | - * @see collect() |
|
68 | - * @access protected |
|
69 | - */ |
|
70 | - function _handle($test, $file) { |
|
71 | - if (!is_dir($file)) { |
|
72 | - $test->addTestFile($file); |
|
73 | - } |
|
74 | - } |
|
57 | + /** |
|
58 | + * This method determines what should be done with a given file and adds |
|
59 | + * it via {@link GroupTest::addTestFile()} if necessary. |
|
60 | + * |
|
61 | + * This method should be overriden to provide custom matching criteria, |
|
62 | + * such as pattern matching, recursive matching, etc. For an example, see |
|
63 | + * {@link SimplePatternCollector::_handle()}. |
|
64 | + * |
|
65 | + * @param object $test Group test with {@link GroupTest::addTestFile()} method. |
|
66 | + * @param string $filename A filename as generated by {@link collect()} |
|
67 | + * @see collect() |
|
68 | + * @access protected |
|
69 | + */ |
|
70 | + function _handle($test, $file) { |
|
71 | + if (!is_dir($file)) { |
|
72 | + $test->addTestFile($file); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -83,31 +83,31 @@ discard block |
||
83 | 83 | * @see SimpleCollector |
84 | 84 | */ |
85 | 85 | class SimplePatternCollector extends SimpleCollector { |
86 | - protected $_pattern; |
|
86 | + protected $_pattern; |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * |
|
91 | - * @param string $pattern Perl compatible regex to test name against |
|
92 | - * See {@link http://us4.php.net/manual/en/reference.pcre.pattern.syntax.php PHP's PCRE} |
|
93 | - * for full documentation of valid pattern.s |
|
94 | - */ |
|
95 | - function SimplePatternCollector($pattern = '/php$/i') { |
|
96 | - $this->_pattern = $pattern; |
|
97 | - } |
|
89 | + /** |
|
90 | + * |
|
91 | + * @param string $pattern Perl compatible regex to test name against |
|
92 | + * See {@link http://us4.php.net/manual/en/reference.pcre.pattern.syntax.php PHP's PCRE} |
|
93 | + * for full documentation of valid pattern.s |
|
94 | + */ |
|
95 | + function SimplePatternCollector($pattern = '/php$/i') { |
|
96 | + $this->_pattern = $pattern; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | - /** |
|
101 | - * Attempts to add files that match a given pattern. |
|
102 | - * |
|
103 | - * @see SimpleCollector::_handle() |
|
104 | - * @param object $test Group test with {@link GroupTest::addTestFile()} method. |
|
105 | - * @param string $path Directory to scan. |
|
106 | - * @access protected |
|
107 | - */ |
|
108 | - function _handle($test, $filename) { |
|
109 | - if (preg_match($this->_pattern, $filename)) { |
|
110 | - parent::_handle($test, $filename); |
|
111 | - } |
|
112 | - } |
|
100 | + /** |
|
101 | + * Attempts to add files that match a given pattern. |
|
102 | + * |
|
103 | + * @see SimpleCollector::_handle() |
|
104 | + * @param object $test Group test with {@link GroupTest::addTestFile()} method. |
|
105 | + * @param string $path Directory to scan. |
|
106 | + * @access protected |
|
107 | + */ |
|
108 | + function _handle($test, $filename) { |
|
109 | + if (preg_match($this->_pattern, $filename)) { |
|
110 | + parent::_handle($test, $filename); |
|
111 | + } |
|
112 | + } |
|
113 | 113 | } |
114 | 114 | \ No newline at end of file |
@@ -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); |