@@ -31,6 +31,9 @@ discard block |
||
31 | 31 | $this->ScriptDirectory = $this->config->getScriptDir(); |
32 | 32 | } |
33 | 33 | |
34 | + /** |
|
35 | + * @param string $feature |
|
36 | + */ |
|
34 | 37 | public function hasSupportFor($feature) |
35 | 38 | { |
36 | 39 | return $this->config->hasFeature($feature); |
@@ -63,6 +66,7 @@ discard block |
||
63 | 66 | |
64 | 67 | /** |
65 | 68 | * Run a sql batch for the datasource. |
69 | + * @param string $script |
|
66 | 70 | */ |
67 | 71 | protected function initScript($script) |
68 | 72 | { |
@@ -248,6 +252,9 @@ discard block |
||
248 | 252 | return strtotime($this->getDatetime()); |
249 | 253 | } |
250 | 254 | |
255 | + /** |
|
256 | + * @return string |
|
257 | + */ |
|
251 | 258 | public function getDateTime() |
252 | 259 | { |
253 | 260 | return $this->_datetime; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once(dirname(__FILE__).'/common.php'); |
|
3 | +require_once(dirname(__FILE__) . '/common.php'); |
|
4 | 4 | Prado::using('System.Data.SqlMap.TSqlMapManager'); |
5 | 5 | |
6 | 6 | /** |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | |
39 | 39 | public function __destruct() |
40 | 40 | { |
41 | - if(!is_null($this->mapper)) |
|
41 | + if (!is_null($this->mapper)) |
|
42 | 42 | $this->mapper->cacheConfiguration(); |
43 | 43 | } |
44 | 44 | |
45 | 45 | function getConnection() |
46 | 46 | { |
47 | - if(is_null($this->connection)) |
|
47 | + if (is_null($this->connection)) |
|
48 | 48 | $this->connection = $this->config->getConnection(); |
49 | 49 | $this->connection->setActive(true); |
50 | 50 | return $this->connection; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | protected function initScript($script) |
68 | 68 | { |
69 | 69 | $runner = $this->config->getScriptRunner(); |
70 | - $runner->runScript($this->getConnection(), $this->ScriptDirectory.$script); |
|
70 | + $runner->runScript($this->getConnection(), $this->ScriptDirectory . $script); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | */ |
110 | 110 | protected function assertOrder1(Order $order) |
111 | 111 | { |
112 | - $date = @mktime(8,15,0,2,15,2003); |
|
112 | + $date = @mktime(8, 15, 0, 2, 15, 2003); |
|
113 | 113 | |
114 | - $this->assertIdentical((int)$order->getID(), 1); |
|
115 | - if($order->getDate() instanceof TDateTime) |
|
114 | + $this->assertIdentical((int) $order->getID(), 1); |
|
115 | + if ($order->getDate() instanceof TDateTime) |
|
116 | 116 | $this->assertIdentical($order->getDate()->getTimestamp(), $date); |
117 | 117 | else |
118 | 118 | $this->fail(); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | |
127 | 127 | function assertAccount1AsHashArray($account) |
128 | 128 | { |
129 | - $this->assertIdentical(1, (int)$account["Id"]); |
|
129 | + $this->assertIdentical(1, (int) $account["Id"]); |
|
130 | 130 | $this->assertIdentical("Joe", $account["FirstName"]); |
131 | 131 | $this->assertIdentical("Dalton", $account["LastName"]); |
132 | 132 | $this->assertIdentical("[email protected]", $account["EmailAddress"]); |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | |
135 | 135 | function AssertOrder1AsHashArray($order) |
136 | 136 | { |
137 | - $date = @mktime(8,15,0,2,15,2003); |
|
137 | + $date = @mktime(8, 15, 0, 2, 15, 2003); |
|
138 | 138 | |
139 | 139 | $this->assertIdentical(1, $order["Id"]); |
140 | - if($order['Date'] instanceof TDateTime) |
|
140 | + if ($order['Date'] instanceof TDateTime) |
|
141 | 141 | $this->assertIdentical($date, $order["Date"]->getTimestamp()); |
142 | 142 | else |
143 | 143 | $this->fail(); |
@@ -157,22 +157,22 @@ discard block |
||
157 | 157 | public function getResult($string) |
158 | 158 | { |
159 | 159 | $value = intval($string); |
160 | - if($value == 100) |
|
160 | + if ($value == 100) |
|
161 | 161 | return true; |
162 | - if($value == 200) |
|
162 | + if ($value == 200) |
|
163 | 163 | return false; |
164 | 164 | //throw new Exception('unexpected value '.$value); |
165 | 165 | } |
166 | 166 | |
167 | 167 | public function getParameter($parameter) |
168 | 168 | { |
169 | - if($parameter) |
|
169 | + if ($parameter) |
|
170 | 170 | return 100; |
171 | 171 | else |
172 | 172 | return 200; |
173 | 173 | } |
174 | 174 | |
175 | - public function createNewInstance($data=null) |
|
175 | + public function createNewInstance($data = null) |
|
176 | 176 | { |
177 | 177 | throw new TDataMapperException('can not create'); |
178 | 178 | } |
@@ -185,22 +185,22 @@ discard block |
||
185 | 185 | |
186 | 186 | public function getResult($string) |
187 | 187 | { |
188 | - if($string === self::YES) |
|
188 | + if ($string === self::YES) |
|
189 | 189 | return true; |
190 | - if($string === self::NO) |
|
190 | + if ($string === self::NO) |
|
191 | 191 | return false; |
192 | 192 | //throw new Exception('unexpected value '.$string); |
193 | 193 | } |
194 | 194 | |
195 | 195 | public function getParameter($parameter) |
196 | 196 | { |
197 | - if($parameter) |
|
197 | + if ($parameter) |
|
198 | 198 | return self::YES; |
199 | 199 | else |
200 | 200 | return self::NO; |
201 | 201 | } |
202 | 202 | |
203 | - public function createNewInstance($data=null) |
|
203 | + public function createNewInstance($data = null) |
|
204 | 204 | { |
205 | 205 | throw new TDataMapperException('can not create'); |
206 | 206 | } |
@@ -221,13 +221,13 @@ discard block |
||
221 | 221 | |
222 | 222 | public function getParameter($parameter) |
223 | 223 | { |
224 | - if($parameter instanceof TDateTime) |
|
224 | + if ($parameter instanceof TDateTime) |
|
225 | 225 | return $parameter->getTimestamp(); |
226 | 226 | else |
227 | 227 | return $parameter; |
228 | 228 | } |
229 | 229 | |
230 | - public function createNewInstance($data=null) |
|
230 | + public function createNewInstance($data = null) |
|
231 | 231 | { |
232 | 232 | return new TDateTime; |
233 | 233 | } |
@@ -237,9 +237,9 @@ discard block |
||
237 | 237 | { |
238 | 238 | private $_datetime; |
239 | 239 | |
240 | - public function __construct($datetime=null) |
|
240 | + public function __construct($datetime = null) |
|
241 | 241 | { |
242 | - if(!is_null($datetime)) |
|
242 | + if (!is_null($datetime)) |
|
243 | 243 | $this->setDatetime($datetime); |
244 | 244 | } |
245 | 245 |
@@ -38,14 +38,16 @@ discard block |
||
38 | 38 | |
39 | 39 | public function __destruct() |
40 | 40 | { |
41 | - if(!is_null($this->mapper)) |
|
42 | - $this->mapper->cacheConfiguration(); |
|
41 | + if(!is_null($this->mapper)) { |
|
42 | + $this->mapper->cacheConfiguration(); |
|
43 | + } |
|
43 | 44 | } |
44 | 45 | |
45 | 46 | function getConnection() |
46 | 47 | { |
47 | - if(is_null($this->connection)) |
|
48 | - $this->connection = $this->config->getConnection(); |
|
48 | + if(is_null($this->connection)) { |
|
49 | + $this->connection = $this->config->getConnection(); |
|
50 | + } |
|
49 | 51 | $this->connection->setActive(true); |
50 | 52 | return $this->connection; |
51 | 53 | } |
@@ -112,10 +114,11 @@ discard block |
||
112 | 114 | $date = @mktime(8,15,0,2,15,2003); |
113 | 115 | |
114 | 116 | $this->assertIdentical((int)$order->getID(), 1); |
115 | - if($order->getDate() instanceof TDateTime) |
|
116 | - $this->assertIdentical($order->getDate()->getTimestamp(), $date); |
|
117 | - else |
|
118 | - $this->fail(); |
|
117 | + if($order->getDate() instanceof TDateTime) { |
|
118 | + $this->assertIdentical($order->getDate()->getTimestamp(), $date); |
|
119 | + } else { |
|
120 | + $this->fail(); |
|
121 | + } |
|
119 | 122 | $this->assertIdentical($order->getCardType(), 'VISA'); |
120 | 123 | $this->assertIdentical($order->getCardNumber(), '999999999999'); |
121 | 124 | $this->assertIdentical($order->getCardExpiry(), '05/03'); |
@@ -137,10 +140,11 @@ discard block |
||
137 | 140 | $date = @mktime(8,15,0,2,15,2003); |
138 | 141 | |
139 | 142 | $this->assertIdentical(1, $order["Id"]); |
140 | - if($order['Date'] instanceof TDateTime) |
|
141 | - $this->assertIdentical($date, $order["Date"]->getTimestamp()); |
|
142 | - else |
|
143 | - $this->fail(); |
|
143 | + if($order['Date'] instanceof TDateTime) { |
|
144 | + $this->assertIdentical($date, $order["Date"]->getTimestamp()); |
|
145 | + } else { |
|
146 | + $this->fail(); |
|
147 | + } |
|
144 | 148 | $this->assertIdentical("VISA", $order["CardType"]); |
145 | 149 | $this->assertIdentical("999999999999", $order["CardNumber"]); |
146 | 150 | $this->assertIdentical("05/03", $order["CardExpiry"]); |
@@ -157,19 +161,22 @@ discard block |
||
157 | 161 | public function getResult($string) |
158 | 162 | { |
159 | 163 | $value = intval($string); |
160 | - if($value == 100) |
|
161 | - return true; |
|
162 | - if($value == 200) |
|
163 | - return false; |
|
164 | + if($value == 100) { |
|
165 | + return true; |
|
166 | + } |
|
167 | + if($value == 200) { |
|
168 | + return false; |
|
169 | + } |
|
164 | 170 | //throw new Exception('unexpected value '.$value); |
165 | 171 | } |
166 | 172 | |
167 | 173 | public function getParameter($parameter) |
168 | 174 | { |
169 | - if($parameter) |
|
170 | - return 100; |
|
171 | - else |
|
172 | - return 200; |
|
175 | + if($parameter) { |
|
176 | + return 100; |
|
177 | + } else { |
|
178 | + return 200; |
|
179 | + } |
|
173 | 180 | } |
174 | 181 | |
175 | 182 | public function createNewInstance($data=null) |
@@ -185,19 +192,22 @@ discard block |
||
185 | 192 | |
186 | 193 | public function getResult($string) |
187 | 194 | { |
188 | - if($string === self::YES) |
|
189 | - return true; |
|
190 | - if($string === self::NO) |
|
191 | - return false; |
|
195 | + if($string === self::YES) { |
|
196 | + return true; |
|
197 | + } |
|
198 | + if($string === self::NO) { |
|
199 | + return false; |
|
200 | + } |
|
192 | 201 | //throw new Exception('unexpected value '.$string); |
193 | 202 | } |
194 | 203 | |
195 | 204 | public function getParameter($parameter) |
196 | 205 | { |
197 | - if($parameter) |
|
198 | - return self::YES; |
|
199 | - else |
|
200 | - return self::NO; |
|
206 | + if($parameter) { |
|
207 | + return self::YES; |
|
208 | + } else { |
|
209 | + return self::NO; |
|
210 | + } |
|
201 | 211 | } |
202 | 212 | |
203 | 213 | public function createNewInstance($data=null) |
@@ -221,10 +231,11 @@ discard block |
||
221 | 231 | |
222 | 232 | public function getParameter($parameter) |
223 | 233 | { |
224 | - if($parameter instanceof TDateTime) |
|
225 | - return $parameter->getTimestamp(); |
|
226 | - else |
|
227 | - return $parameter; |
|
234 | + if($parameter instanceof TDateTime) { |
|
235 | + return $parameter->getTimestamp(); |
|
236 | + } else { |
|
237 | + return $parameter; |
|
238 | + } |
|
228 | 239 | } |
229 | 240 | |
230 | 241 | public function createNewInstance($data=null) |
@@ -239,8 +250,9 @@ discard block |
||
239 | 250 | |
240 | 251 | public function __construct($datetime=null) |
241 | 252 | { |
242 | - if(!is_null($datetime)) |
|
243 | - $this->setDatetime($datetime); |
|
253 | + if(!is_null($datetime)) { |
|
254 | + $this->setDatetime($datetime); |
|
255 | + } |
|
244 | 256 | } |
245 | 257 | |
246 | 258 | public function getTimestamp() |
@@ -51,12 +51,19 @@ |
||
51 | 51 | protected $baseFile; |
52 | 52 | protected $targetFile; |
53 | 53 | |
54 | + /** |
|
55 | + * @param string $base |
|
56 | + * @param string $target |
|
57 | + */ |
|
54 | 58 | public function __construct($base, $target) |
55 | 59 | { |
56 | 60 | $this->baseFile = $base; |
57 | 61 | $this->targetFile = $target; |
58 | 62 | } |
59 | 63 | |
64 | + /** |
|
65 | + * @param string $script |
|
66 | + */ |
|
60 | 67 | function runScript($connection, $script) |
61 | 68 | { |
62 | 69 | copy($this->baseFile, $this->targetFile); |
@@ -2,33 +2,33 @@ discard block |
||
2 | 2 | |
3 | 3 | Prado::using('System.Data.TDbConnection'); |
4 | 4 | |
5 | -if(!defined('SQLMAP_TESTS')) |
|
5 | +if (!defined('SQLMAP_TESTS')) |
|
6 | 6 | define('SQLMAP_TESTS', realpath(dirname(__FILE__))); |
7 | 7 | |
8 | -if(!class_exists('Account', false)) |
|
8 | +if (!class_exists('Account', false)) |
|
9 | 9 | { |
10 | - include(SQLMAP_TESTS.'/domain/A.php'); |
|
11 | - include(SQLMAP_TESTS.'/domain/Account.php'); |
|
12 | - include(SQLMAP_TESTS.'/domain/AccountBis.php'); |
|
13 | - include(SQLMAP_TESTS.'/domain/AccountCollection.php'); |
|
14 | - include(SQLMAP_TESTS.'/domain/B.php'); |
|
15 | - include(SQLMAP_TESTS.'/domain/Document.php'); |
|
16 | - include(SQLMAP_TESTS.'/domain/Book.php'); |
|
17 | - include(SQLMAP_TESTS.'/domain/C.php'); |
|
18 | - include(SQLMAP_TESTS.'/domain/Category.php'); |
|
19 | - include(SQLMAP_TESTS.'/domain/Complex.php'); |
|
20 | - include(SQLMAP_TESTS.'/domain/D.php'); |
|
21 | - include(SQLMAP_TESTS.'/domain/DocumentCollection.php'); |
|
22 | - include(SQLMAP_TESTS.'/domain/E.php'); |
|
23 | - include(SQLMAP_TESTS.'/domain/F.php'); |
|
24 | - include(SQLMAP_TESTS.'/domain/LineItem.php'); |
|
25 | - include(SQLMAP_TESTS.'/domain/LineItemCollection.php'); |
|
26 | - include(SQLMAP_TESTS.'/domain/Newspaper.php'); |
|
27 | - include(SQLMAP_TESTS.'/domain/Order.php'); |
|
28 | - include(SQLMAP_TESTS.'/domain/Other.php'); |
|
29 | - include(SQLMAP_TESTS.'/domain/Sample.php'); |
|
30 | - include(SQLMAP_TESTS.'/domain/Search.php'); |
|
31 | - include(SQLMAP_TESTS.'/domain/User.php'); |
|
10 | + include(SQLMAP_TESTS . '/domain/A.php'); |
|
11 | + include(SQLMAP_TESTS . '/domain/Account.php'); |
|
12 | + include(SQLMAP_TESTS . '/domain/AccountBis.php'); |
|
13 | + include(SQLMAP_TESTS . '/domain/AccountCollection.php'); |
|
14 | + include(SQLMAP_TESTS . '/domain/B.php'); |
|
15 | + include(SQLMAP_TESTS . '/domain/Document.php'); |
|
16 | + include(SQLMAP_TESTS . '/domain/Book.php'); |
|
17 | + include(SQLMAP_TESTS . '/domain/C.php'); |
|
18 | + include(SQLMAP_TESTS . '/domain/Category.php'); |
|
19 | + include(SQLMAP_TESTS . '/domain/Complex.php'); |
|
20 | + include(SQLMAP_TESTS . '/domain/D.php'); |
|
21 | + include(SQLMAP_TESTS . '/domain/DocumentCollection.php'); |
|
22 | + include(SQLMAP_TESTS . '/domain/E.php'); |
|
23 | + include(SQLMAP_TESTS . '/domain/F.php'); |
|
24 | + include(SQLMAP_TESTS . '/domain/LineItem.php'); |
|
25 | + include(SQLMAP_TESTS . '/domain/LineItemCollection.php'); |
|
26 | + include(SQLMAP_TESTS . '/domain/Newspaper.php'); |
|
27 | + include(SQLMAP_TESTS . '/domain/Order.php'); |
|
28 | + include(SQLMAP_TESTS . '/domain/Other.php'); |
|
29 | + include(SQLMAP_TESTS . '/domain/Sample.php'); |
|
30 | + include(SQLMAP_TESTS . '/domain/Search.php'); |
|
31 | + include(SQLMAP_TESTS . '/domain/User.php'); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | class DefaultScriptRunner |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | { |
38 | 38 | $sql = file_get_contents($script); |
39 | 39 | $lines = explode(';', $sql); |
40 | - foreach($lines as $line) |
|
40 | + foreach ($lines as $line) |
|
41 | 41 | { |
42 | 42 | $line = trim($line); |
43 | - if(strlen($line) > 0) |
|
43 | + if (strlen($line) > 0) |
|
44 | 44 | $connection->createCommand($line)->execute(); |
45 | 45 | } |
46 | 46 | } |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | |
71 | 71 | public function __construct() |
72 | 72 | { |
73 | - $this->_sqlmapConfigFile = SQLMAP_TESTS.'/sqlite.xml'; |
|
74 | - $this->_scriptDir = SQLMAP_TESTS.'/scripts/sqlite/'; |
|
73 | + $this->_sqlmapConfigFile = SQLMAP_TESTS . '/sqlite.xml'; |
|
74 | + $this->_scriptDir = SQLMAP_TESTS . '/scripts/sqlite/'; |
|
75 | 75 | |
76 | - $this->targetFile = realpath(SQLMAP_TESTS.'/sqlite/tests.db'); |
|
77 | - $this->baseFile = realpath(SQLMAP_TESTS.'/sqlite/backup.db'); |
|
76 | + $this->targetFile = realpath(SQLMAP_TESTS . '/sqlite/tests.db'); |
|
77 | + $this->baseFile = realpath(SQLMAP_TESTS . '/sqlite/backup.db'); |
|
78 | 78 | $file = realpath($this->targetFile); |
79 | 79 | $this->_connection = new TDbConnection("sqlite:{$file}"); |
80 | 80 | } |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | { |
90 | 90 | public function __construct() |
91 | 91 | { |
92 | - $this->_sqlmapConfigFile = SQLMAP_TESTS.'/mysql.xml'; |
|
93 | - $this->_scriptDir = SQLMAP_TESTS.'/scripts/mysql/'; |
|
92 | + $this->_sqlmapConfigFile = SQLMAP_TESTS . '/mysql.xml'; |
|
93 | + $this->_scriptDir = SQLMAP_TESTS . '/scripts/mysql/'; |
|
94 | 94 | $this->_features = array('insert_id'); |
95 | 95 | $dsn = 'mysql:host=localhost;dbname=sqlmap_test;port=3307'; |
96 | 96 | $this->_connection = new TDbConnection($dsn, 'test5', 'test5'); |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | { |
102 | 102 | public function __construct() |
103 | 103 | { |
104 | - $this->_sqlmap = SQLMAP_TESTS.'/mssql.xml'; |
|
104 | + $this->_sqlmap = SQLMAP_TESTS . '/mssql.xml'; |
|
105 | 105 | $this->_connectionString = 'odbc_mssql://sqlmap_tests'; |
106 | - $this->_scriptDir = SQLMAP_TESTS.'/scripts/mssql/'; |
|
106 | + $this->_scriptDir = SQLMAP_TESTS . '/scripts/mssql/'; |
|
107 | 107 | $this->_features = array('insert_id'); |
108 | 108 | } |
109 | 109 | } |
@@ -2,8 +2,9 @@ discard block |
||
2 | 2 | |
3 | 3 | Prado::using('System.Data.TDbConnection'); |
4 | 4 | |
5 | -if(!defined('SQLMAP_TESTS')) |
|
5 | +if(!defined('SQLMAP_TESTS')) { |
|
6 | 6 | define('SQLMAP_TESTS', realpath(dirname(__FILE__))); |
7 | +} |
|
7 | 8 | |
8 | 9 | if(!class_exists('Account', false)) |
9 | 10 | { |
@@ -40,8 +41,9 @@ discard block |
||
40 | 41 | foreach($lines as $line) |
41 | 42 | { |
42 | 43 | $line = trim($line); |
43 | - if(strlen($line) > 0) |
|
44 | - $connection->createCommand($line)->execute(); |
|
44 | + if(strlen($line) > 0) { |
|
45 | + $connection->createCommand($line)->execute(); |
|
46 | + } |
|
45 | 47 | } |
46 | 48 | } |
47 | 49 | } |
@@ -11,15 +11,31 @@ |
||
11 | 11 | private $_CartOptions=0; |
12 | 12 | |
13 | 13 | public function getID(){ return $this->_ID; } |
14 | + |
|
15 | + /** |
|
16 | + * @param integer $value |
|
17 | + */ |
|
14 | 18 | public function setID($value){ $this->_ID = intval($value); } |
15 | 19 | |
16 | 20 | public function getFirstName(){ return $this->_FirstName; } |
21 | + |
|
22 | + /** |
|
23 | + * @param string $value |
|
24 | + */ |
|
17 | 25 | public function setFirstName($value){ $this->_FirstName = $value; } |
18 | 26 | |
19 | 27 | public function getLastName(){ return $this->_LastName; } |
28 | + |
|
29 | + /** |
|
30 | + * @param string $value |
|
31 | + */ |
|
20 | 32 | public function setLastName($value){ $this->_LastName = $value; } |
21 | 33 | |
22 | 34 | public function getEmailAddress(){ return $this->_EmailAddress; } |
35 | + |
|
36 | + /** |
|
37 | + * @param string|null $value |
|
38 | + */ |
|
23 | 39 | public function setEmailAddress($value){ $this->_EmailAddress = $value; } |
24 | 40 | |
25 | 41 | public function getIDS(){ return $this->_IDS; } |
@@ -2,33 +2,33 @@ |
||
2 | 2 | |
3 | 3 | class Account |
4 | 4 | { |
5 | - private $_ID=0; |
|
6 | - private $_FirstName=''; |
|
7 | - private $_LastName=''; |
|
8 | - private $_EmailAddress=null; |
|
9 | - private $_IDS=''; |
|
10 | - private $_BannerOptions=0; |
|
11 | - private $_CartOptions=0; |
|
5 | + private $_ID = 0; |
|
6 | + private $_FirstName = ''; |
|
7 | + private $_LastName = ''; |
|
8 | + private $_EmailAddress = null; |
|
9 | + private $_IDS = ''; |
|
10 | + private $_BannerOptions = 0; |
|
11 | + private $_CartOptions = 0; |
|
12 | 12 | |
13 | - public function getID(){ return $this->_ID; } |
|
14 | - public function setID($value){ $this->_ID = intval($value); } |
|
13 | + public function getID() { return $this->_ID; } |
|
14 | + public function setID($value) { $this->_ID = intval($value); } |
|
15 | 15 | |
16 | - public function getFirstName(){ return $this->_FirstName; } |
|
17 | - public function setFirstName($value){ $this->_FirstName = $value; } |
|
16 | + public function getFirstName() { return $this->_FirstName; } |
|
17 | + public function setFirstName($value) { $this->_FirstName = $value; } |
|
18 | 18 | |
19 | - public function getLastName(){ return $this->_LastName; } |
|
20 | - public function setLastName($value){ $this->_LastName = $value; } |
|
19 | + public function getLastName() { return $this->_LastName; } |
|
20 | + public function setLastName($value) { $this->_LastName = $value; } |
|
21 | 21 | |
22 | - public function getEmailAddress(){ return $this->_EmailAddress; } |
|
23 | - public function setEmailAddress($value){ $this->_EmailAddress = $value; } |
|
22 | + public function getEmailAddress() { return $this->_EmailAddress; } |
|
23 | + public function setEmailAddress($value) { $this->_EmailAddress = $value; } |
|
24 | 24 | |
25 | - public function getIDS(){ return $this->_IDS; } |
|
26 | - public function setIDS($value){ $this->_IDS = $value; } |
|
25 | + public function getIDS() { return $this->_IDS; } |
|
26 | + public function setIDS($value) { $this->_IDS = $value; } |
|
27 | 27 | |
28 | - public function getBannerOptions(){ return $this->_BannerOptions; } |
|
29 | - public function setBannerOptions($value){ $this->_BannerOptions = $value; } |
|
28 | + public function getBannerOptions() { return $this->_BannerOptions; } |
|
29 | + public function setBannerOptions($value) { $this->_BannerOptions = $value; } |
|
30 | 30 | |
31 | - public function getCartOptions(){ return $this->_CartOptions; } |
|
32 | - public function setCartOptions($value){ $this->_CartOptions = $value; } |
|
31 | + public function getCartOptions() { return $this->_CartOptions; } |
|
32 | + public function setCartOptions($value) { $this->_CartOptions = $value; } |
|
33 | 33 | |
34 | 34 | } |
@@ -10,18 +10,38 @@ |
||
10 | 10 | private $_PictureData=''; |
11 | 11 | |
12 | 12 | public function getID(){ return $this->_ID; } |
13 | + |
|
14 | + /** |
|
15 | + * @param integer $value |
|
16 | + */ |
|
13 | 17 | public function setID($value){ $this->_ID = $value; } |
14 | 18 | |
15 | 19 | public function getOrder(){ return $this->_Order; } |
20 | + |
|
21 | + /** |
|
22 | + * @param Order $value |
|
23 | + */ |
|
16 | 24 | public function setOrder($value){ $this->_Order = $value; } |
17 | 25 | |
18 | 26 | public function getCode(){ return $this->_Code; } |
27 | + |
|
28 | + /** |
|
29 | + * @param string $value |
|
30 | + */ |
|
19 | 31 | public function setCode($value){ $this->_Code = $value; } |
20 | 32 | |
21 | 33 | public function getQuantity(){ return $this->_Quantity; } |
34 | + |
|
35 | + /** |
|
36 | + * @param integer $value |
|
37 | + */ |
|
22 | 38 | public function setQuantity($value){ $this->_Quantity = $value; } |
23 | 39 | |
24 | 40 | public function getPrice(){ return $this->_Price; } |
41 | + |
|
42 | + /** |
|
43 | + * @param double $value |
|
44 | + */ |
|
25 | 45 | public function setPrice($value){ $this->_Price = $value; } |
26 | 46 | |
27 | 47 | public function getPictureData(){ return $this->_PictureData; } |
@@ -2,29 +2,29 @@ |
||
2 | 2 | |
3 | 3 | class LineItem |
4 | 4 | { |
5 | - private $_ID=-1; |
|
6 | - private $_Order=''; |
|
7 | - private $_Code=''; |
|
8 | - private $_Quantity=-1; |
|
9 | - private $_Price=0.0; |
|
10 | - private $_PictureData=''; |
|
5 | + private $_ID = -1; |
|
6 | + private $_Order = ''; |
|
7 | + private $_Code = ''; |
|
8 | + private $_Quantity = -1; |
|
9 | + private $_Price = 0.0; |
|
10 | + private $_PictureData = ''; |
|
11 | 11 | |
12 | - public function getID(){ return $this->_ID; } |
|
13 | - public function setID($value){ $this->_ID = $value; } |
|
12 | + public function getID() { return $this->_ID; } |
|
13 | + public function setID($value) { $this->_ID = $value; } |
|
14 | 14 | |
15 | - public function getOrder(){ return $this->_Order; } |
|
16 | - public function setOrder($value){ $this->_Order = $value; } |
|
15 | + public function getOrder() { return $this->_Order; } |
|
16 | + public function setOrder($value) { $this->_Order = $value; } |
|
17 | 17 | |
18 | - public function getCode(){ return $this->_Code; } |
|
19 | - public function setCode($value){ $this->_Code = $value; } |
|
18 | + public function getCode() { return $this->_Code; } |
|
19 | + public function setCode($value) { $this->_Code = $value; } |
|
20 | 20 | |
21 | - public function getQuantity(){ return $this->_Quantity; } |
|
22 | - public function setQuantity($value){ $this->_Quantity = $value; } |
|
21 | + public function getQuantity() { return $this->_Quantity; } |
|
22 | + public function setQuantity($value) { $this->_Quantity = $value; } |
|
23 | 23 | |
24 | - public function getPrice(){ return $this->_Price; } |
|
25 | - public function setPrice($value){ $this->_Price = $value; } |
|
24 | + public function getPrice() { return $this->_Price; } |
|
25 | + public function setPrice($value) { $this->_Price = $value; } |
|
26 | 26 | |
27 | - public function getPictureData(){ return $this->_PictureData; } |
|
28 | - public function setPictureData($value){ $this->_PictureData = $value; } |
|
27 | + public function getPictureData() { return $this->_PictureData; } |
|
28 | + public function setPictureData($value) { $this->_PictureData = $value; } |
|
29 | 29 | |
30 | 30 | } |
@@ -8,14 +8,30 @@ |
||
8 | 8 | private $_Bool2=false; |
9 | 9 | |
10 | 10 | public function getBool2(){ return $this->_Bool2; } |
11 | + |
|
12 | + /** |
|
13 | + * @param boolean $value |
|
14 | + */ |
|
11 | 15 | public function setBool2($value){ $this->_Bool2 = $value; } |
12 | 16 | |
13 | 17 | public function getBool(){ return $this->_Bool; } |
18 | + |
|
19 | + /** |
|
20 | + * @param boolean $value |
|
21 | + */ |
|
14 | 22 | public function setBool($value){ $this->_Bool = $value; } |
15 | 23 | |
16 | 24 | public function getInt(){ return $this->_Int; } |
25 | + |
|
26 | + /** |
|
27 | + * @param integer $value |
|
28 | + */ |
|
17 | 29 | public function setInt($value){ $this->_Int = $value; } |
18 | 30 | |
19 | 31 | public function getLong(){ return $this->_Long; } |
32 | + |
|
33 | + /** |
|
34 | + * @param integer $value |
|
35 | + */ |
|
20 | 36 | public function setLong($value){ $this->_Long = $value; } |
21 | 37 | } |
@@ -2,20 +2,20 @@ |
||
2 | 2 | |
3 | 3 | class Other |
4 | 4 | { |
5 | - private $_Int=-1; |
|
6 | - private $_Long=-1; |
|
7 | - private $_Bool=false; |
|
8 | - private $_Bool2=false; |
|
5 | + private $_Int = -1; |
|
6 | + private $_Long = -1; |
|
7 | + private $_Bool = false; |
|
8 | + private $_Bool2 = false; |
|
9 | 9 | |
10 | - public function getBool2(){ return $this->_Bool2; } |
|
11 | - public function setBool2($value){ $this->_Bool2 = $value; } |
|
10 | + public function getBool2() { return $this->_Bool2; } |
|
11 | + public function setBool2($value) { $this->_Bool2 = $value; } |
|
12 | 12 | |
13 | - public function getBool(){ return $this->_Bool; } |
|
14 | - public function setBool($value){ $this->_Bool = $value; } |
|
13 | + public function getBool() { return $this->_Bool; } |
|
14 | + public function setBool($value) { $this->_Bool = $value; } |
|
15 | 15 | |
16 | - public function getInt(){ return $this->_Int; } |
|
17 | - public function setInt($value){ $this->_Int = $value; } |
|
16 | + public function getInt() { return $this->_Int; } |
|
17 | + public function setInt($value) { $this->_Int = $value; } |
|
18 | 18 | |
19 | - public function getLong(){ return $this->_Long; } |
|
20 | - public function setLong($value){ $this->_Long = $value; } |
|
19 | + public function getLong() { return $this->_Long; } |
|
20 | + public function setLong($value) { $this->_Long = $value; } |
|
21 | 21 | } |
@@ -95,12 +95,21 @@ discard block |
||
95 | 95 | $this->assertNewspaper($news, 4, "Le Canard enchaine", "Paris"); |
96 | 96 | } |
97 | 97 | |
98 | + /** |
|
99 | + * @param integer $id |
|
100 | + * @param string $title |
|
101 | + */ |
|
98 | 102 | function AssertDocument(Document $document, $id, $title) |
99 | 103 | { |
100 | 104 | $this->assertEqual($id, $document->getID()); |
101 | 105 | $this->assertEqual($title, $document->getTitle()); |
102 | 106 | } |
103 | 107 | |
108 | + /** |
|
109 | + * @param integer $id |
|
110 | + * @param string $title |
|
111 | + * @param integer $pageNumber |
|
112 | + */ |
|
104 | 113 | function AssertBook(Book $book, $id, $title, $pageNumber) |
105 | 114 | { |
106 | 115 | $this->assertEqual($id, $book->getId()); |
@@ -108,6 +117,11 @@ discard block |
||
108 | 117 | $this->assertEqual($pageNumber, (int)$book->getPageNumber()); |
109 | 118 | } |
110 | 119 | |
120 | + /** |
|
121 | + * @param integer $id |
|
122 | + * @param string $title |
|
123 | + * @param string $city |
|
124 | + */ |
|
111 | 125 | function AssertNewspaper(Newspaper $news, $id, $title, $city) |
112 | 126 | { |
113 | 127 | $this->assertEqual($id, $news->getId()); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once(dirname(__FILE__).'/BaseCase.php'); |
|
3 | +require_once(dirname(__FILE__) . '/BaseCase.php'); |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * @package System.DataAccess.SQLMap |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | { |
106 | 106 | $this->assertEqual($id, $book->getId()); |
107 | 107 | $this->assertEqual($title, $book->getTitle()); |
108 | - $this->assertEqual($pageNumber, (int)$book->getPageNumber()); |
|
108 | + $this->assertEqual($pageNumber, (int) $book->getPageNumber()); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | function AssertNewspaper(Newspaper $news, $id, $title, $city) |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | throw new TDataMapperException('not implemented'); |
138 | 138 | } |
139 | 139 | |
140 | - public function createNewInstance($data=null) |
|
140 | + public function createNewInstance($data = null) |
|
141 | 141 | { |
142 | 142 | throw new TDataMapperException('can not create'); |
143 | 143 | } |
@@ -56,6 +56,10 @@ discard block |
||
56 | 56 | $this->setSeleniumServerRequestsTimeout(static::$timeout); |
57 | 57 | } |
58 | 58 | |
59 | + /** |
|
60 | + * @param string $idattr |
|
61 | + * @param string|null $txt |
|
62 | + */ |
|
59 | 63 | protected function assertAttribute($idattr, $txt) |
60 | 64 | { |
61 | 65 | list($id, $attr) = explode('@', $idattr); |
@@ -91,6 +95,9 @@ discard block |
||
91 | 95 | $this->assertEquals($txt, $this->getElement($id)->text()); |
92 | 96 | } |
93 | 97 | |
98 | + /** |
|
99 | + * @param string $txt |
|
100 | + */ |
|
94 | 101 | protected function assertValue($id, $txt) |
95 | 102 | { |
96 | 103 | try{ |
@@ -185,11 +192,18 @@ discard block |
||
185 | 192 | $select->selectOptionByLabel($value); |
186 | 193 | } |
187 | 194 | |
195 | + /** |
|
196 | + * @param string $id |
|
197 | + * @param string $value |
|
198 | + */ |
|
188 | 199 | protected function selectAndWait($id, $value) |
189 | 200 | { |
190 | 201 | $this->select($id, $value); |
191 | 202 | } |
192 | 203 | |
204 | + /** |
|
205 | + * @param string $value |
|
206 | + */ |
|
193 | 207 | protected function addSelection($id, $value) |
194 | 208 | { |
195 | 209 | parent::select($this->getElement($id))->selectOptionByLabel($value); |
@@ -200,11 +214,18 @@ discard block |
||
200 | 214 | return parent::select($this->getElement($id))->selectedLabels(); |
201 | 215 | } |
202 | 216 | |
217 | + /** |
|
218 | + * @param string $id |
|
219 | + */ |
|
203 | 220 | protected function getSelectOptions($id) |
204 | 221 | { |
205 | 222 | return parent::select($this->getElement($id))->selectOptionLabels(); |
206 | 223 | } |
207 | 224 | |
225 | + /** |
|
226 | + * @param string $id |
|
227 | + * @param integer $value |
|
228 | + */ |
|
208 | 229 | protected function assertSelectedIndex($id, $value) |
209 | 230 | { |
210 | 231 | $options=parent::select($this->getElement($id))->selectOptionValues(); |
@@ -223,6 +244,9 @@ discard block |
||
223 | 244 | $this->fail('Current value '.$curval.' not found in: '.implode(',', $options)); |
224 | 245 | } |
225 | 246 | |
247 | + /** |
|
248 | + * @param string $label |
|
249 | + */ |
|
226 | 250 | protected function assertSelected($id, $label) |
227 | 251 | { |
228 | 252 | $this->assertSame($label, parent::select($this->getElement($id))->selectedLabel()); |
@@ -233,6 +257,9 @@ discard block |
||
233 | 257 | $this->assertSame(array(), $this->getSelectedLabels($id)); |
234 | 258 | } |
235 | 259 | |
260 | + /** |
|
261 | + * @param string $index |
|
262 | + */ |
|
236 | 263 | protected function assertSelectedValue($id, $index) |
237 | 264 | { |
238 | 265 | $this->assertSame($index, parent::select($this->getElement($id))->selectedValue()); |
@@ -264,6 +291,9 @@ discard block |
||
264 | 291 | $this->assertTrue($found, "Failed asserting that page source contains $text"); |
265 | 292 | } |
266 | 293 | |
294 | + /** |
|
295 | + * @param string $text |
|
296 | + */ |
|
267 | 297 | public function assertSourceNotContains($text) |
268 | 298 | { |
269 | 299 | $found = strpos($this->source(), $text) !== false; |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | */ |
46 | 46 | ); |
47 | 47 | |
48 | - static $baseurl='http://127.0.0.1/prado-master/tests/FunctionalTests/'; |
|
48 | + static $baseurl = 'http://127.0.0.1/prado-master/tests/FunctionalTests/'; |
|
49 | 49 | |
50 | - static $timeout=5; //seconds |
|
50 | + static $timeout = 5; //seconds |
|
51 | 51 | |
52 | 52 | protected function setUp() |
53 | 53 | { |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | list($id, $attr) = explode('@', $idattr); |
62 | 62 | |
63 | 63 | $element = $this->getElement($id); |
64 | - $value=$element->attribute($attr); |
|
64 | + $value = $element->attribute($attr); |
|
65 | 65 | |
66 | - if(strpos($txt, 'regexp:')===0) |
|
66 | + if (strpos($txt, 'regexp:') === 0) |
|
67 | 67 | { |
68 | - $this->assertRegExp('/'.substr($txt, 7).'/', $value); |
|
68 | + $this->assertRegExp('/' . substr($txt, 7) . '/', $value); |
|
69 | 69 | } else { |
70 | 70 | $this->assertEquals($txt, $value); |
71 | 71 | } |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | |
74 | 74 | protected function getElement($id) |
75 | 75 | { |
76 | - if(strpos($id, 'id=')===0) { |
|
76 | + if (strpos($id, 'id=') === 0) { |
|
77 | 77 | return $this->byId(substr($id, 3)); |
78 | - } elseif(strpos($id, 'name=')===0) { |
|
78 | + } elseif (strpos($id, 'name=') === 0) { |
|
79 | 79 | return $this->byName(substr($id, 5)); |
80 | - } elseif(strpos($id, '//')===0) { |
|
80 | + } elseif (strpos($id, '//') === 0) { |
|
81 | 81 | return $this->byXPath($id); |
82 | - } elseif(strpos($id, '$')!==false) { |
|
82 | + } elseif (strpos($id, '$') !== false) { |
|
83 | 83 | return $this->byName($id); |
84 | 84 | } else { |
85 | 85 | return $this->byId($id); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | protected function assertValue($id, $txt) |
95 | 95 | { |
96 | - try{ |
|
96 | + try { |
|
97 | 97 | $this->assertEquals($txt, $this->getElement($id)->value()); |
98 | 98 | } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) { |
99 | 99 | //stale element reference. try second time. |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | protected function assertVisible($id) |
106 | 106 | { |
107 | - try{ |
|
107 | + try { |
|
108 | 108 | $this->assertTrue($this->getElement($id)->displayed()); |
109 | 109 | } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) { |
110 | 110 | //stale element reference. try second time. |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | protected function assertNotVisible($id) |
117 | 117 | { |
118 | - try{ |
|
118 | + try { |
|
119 | 119 | $this->assertFalse($this->getElement($id)->displayed()); |
120 | 120 | } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) { |
121 | 121 | //stale element reference. try second time. |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | |
127 | 127 | protected function assertElementPresent($id) |
128 | 128 | { |
129 | - $this->assertTrue($this->getElement($id)!==null); |
|
129 | + $this->assertTrue($this->getElement($id) !== null); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | protected function assertElementNotPresent($id) |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | $this->assertEquals(PHPUnit_Extensions_Selenium2TestCase_WebDriverException::NoSuchElement, $e->getCode()); |
138 | 138 | return; |
139 | 139 | } |
140 | - $this->fail('The element '.$id.' shouldn\'t exist.'); |
|
140 | + $this->fail('The element ' . $id . ' shouldn\'t exist.'); |
|
141 | 141 | } |
142 | 142 | |
143 | - protected function type($id, $txt='') |
|
143 | + protected function type($id, $txt = '') |
|
144 | 144 | { |
145 | 145 | $element = $this->getElement($id); |
146 | 146 | $element->clear(); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $this->byCssSelector('body')->click(); |
150 | 150 | } |
151 | 151 | |
152 | - protected function typeSpecial($id, $txt='') |
|
152 | + protected function typeSpecial($id, $txt = '') |
|
153 | 153 | { |
154 | 154 | $element = $this->getElement($id); |
155 | 155 | // clear the textbox without using clear() that triggers onchange() |
@@ -159,16 +159,16 @@ discard block |
||
159 | 159 | // sequences of end+backspace and start+delete |
160 | 160 | |
161 | 161 | $element->click(); |
162 | - while(strlen($element->value())>0) |
|
162 | + while (strlen($element->value()) > 0) |
|
163 | 163 | { |
164 | 164 | $this->keys(PHPUnit_Extensions_Selenium2TestCase_Keys::END); |
165 | 165 | // the number 100 is purely empiric |
166 | - for($i=0;$i<100;$i++) |
|
166 | + for ($i = 0; $i < 100; $i++) |
|
167 | 167 | $this->keys(PHPUnit_Extensions_Selenium2TestCase_Keys::BACKSPACE); |
168 | 168 | |
169 | 169 | $this->keys(PHPUnit_Extensions_Selenium2TestCase_Keys::HOME); |
170 | 170 | // the number 100 is purely empiric |
171 | - for($i=0;$i<100;$i++) |
|
171 | + for ($i = 0; $i < 100; $i++) |
|
172 | 172 | $this->keys(PHPUnit_Extensions_Selenium2TestCase_Keys::DELETE); |
173 | 173 | } |
174 | 174 | |
@@ -207,20 +207,20 @@ discard block |
||
207 | 207 | |
208 | 208 | protected function assertSelectedIndex($id, $value) |
209 | 209 | { |
210 | - $options=parent::select($this->getElement($id))->selectOptionValues(); |
|
211 | - $curval=parent::select($this->getElement($id))->selectedValue(); |
|
210 | + $options = parent::select($this->getElement($id))->selectOptionValues(); |
|
211 | + $curval = parent::select($this->getElement($id))->selectedValue(); |
|
212 | 212 | |
213 | - $i=0; |
|
214 | - foreach($options as $option) |
|
213 | + $i = 0; |
|
214 | + foreach ($options as $option) |
|
215 | 215 | { |
216 | - if($option==$curval) |
|
216 | + if ($option == $curval) |
|
217 | 217 | { |
218 | 218 | $this->assertEquals($i, $value); |
219 | 219 | return; |
220 | 220 | } |
221 | 221 | $i++; |
222 | 222 | } |
223 | - $this->fail('Current value '.$curval.' not found in: '.implode(',', $options)); |
|
223 | + $this->fail('Current value ' . $curval . ' not found in: ' . implode(',', $options)); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | protected function assertSelected($id, $label) |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | protected function assertAlertNotPresent() |
242 | 242 | { |
243 | 243 | try { |
244 | - $foo=$this->alertText(); |
|
244 | + $foo = $this->alertText(); |
|
245 | 245 | } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) { |
246 | 246 | $this->assertEquals(PHPUnit_Extensions_Selenium2TestCase_WebDriverException::NoAlertOpenError, $e->getCode()); |
247 | 247 | return; |
@@ -251,13 +251,13 @@ discard block |
||
251 | 251 | |
252 | 252 | protected function pause($msec) |
253 | 253 | { |
254 | - usleep($msec*1000); |
|
254 | + usleep($msec * 1000); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | public function assertSourceContains($text) |
258 | 258 | { |
259 | 259 | $found = strpos($this->source(), $text) !== false; |
260 | - for($i=0;$i<10 && ! $found; $i++) { |
|
260 | + for ($i = 0; $i < 10 && !$found; $i++) { |
|
261 | 261 | $this->pause(20); |
262 | 262 | $found = strpos($this->source(), $text) !== false; |
263 | 263 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | public function assertSourceNotContains($text) |
268 | 268 | { |
269 | 269 | $found = strpos($this->source(), $text) !== false; |
270 | - for($i=0;$i<10 && $found; $i++) { |
|
270 | + for ($i = 0; $i < 10 && $found; $i++) { |
|
271 | 271 | $this->pause(20); |
272 | 272 | $found = strpos($this->source(), $text) !== false; |
273 | 273 | } |
@@ -163,13 +163,15 @@ |
||
163 | 163 | { |
164 | 164 | $this->keys(PHPUnit_Extensions_Selenium2TestCase_Keys::END); |
165 | 165 | // the number 100 is purely empiric |
166 | - for($i=0;$i<100;$i++) |
|
167 | - $this->keys(PHPUnit_Extensions_Selenium2TestCase_Keys::BACKSPACE); |
|
166 | + for($i=0;$i<100;$i++) { |
|
167 | + $this->keys(PHPUnit_Extensions_Selenium2TestCase_Keys::BACKSPACE); |
|
168 | + } |
|
168 | 169 | |
169 | 170 | $this->keys(PHPUnit_Extensions_Selenium2TestCase_Keys::HOME); |
170 | 171 | // the number 100 is purely empiric |
171 | - for($i=0;$i<100;$i++) |
|
172 | - $this->keys(PHPUnit_Extensions_Selenium2TestCase_Keys::DELETE); |
|
172 | + for($i=0;$i<100;$i++) { |
|
173 | + $this->keys(PHPUnit_Extensions_Selenium2TestCase_Keys::DELETE); |
|
174 | + } |
|
173 | 175 | } |
174 | 176 | |
175 | 177 | $element->value($txt); |
@@ -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; |