Changeset 6612
- Timestamp:
- 12/20/07 15:22:05 (1 year ago)
- Files:
-
- branches/1.1/lib/util/sfBrowser.class.php (modified) (6 diffs)
- branches/1.1/test/unit/util/sfBrowserTest.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/util/sfBrowser.class.php
r6551 r6612 28 28 $cookieJar = array(), 29 29 $fields = array(), 30 $files = array(), 30 31 $vars = array(), 31 32 $defaultServerArray = array(), … … 137 138 $_GET = $parameters; 138 139 } 140 141 // handle input type="file" fields 142 if (count($this->files)) 143 { 144 $_FILES = $this->files; 145 } 146 $this->files = array(); 147 139 148 parse_str($query_string, $qs); 140 149 if (is_array($qs)) … … 351 360 // merge form default values and arguments 352 361 $defaults = array(); 362 $arguments = sfToolkit::arrayDeepMerge($this->fields, $arguments); 363 353 364 foreach ($xpath->query('descendant::input | descendant::textarea | descendant::select', $form) as $element) 354 365 { … … 356 367 $nodeName = $element->nodeName; 357 368 $value = null; 369 358 370 if ($nodeName == 'input' && ($element->getAttribute('type') == 'checkbox' || $element->getAttribute('type') == 'radio')) 359 371 { … … 362 374 $value = $element->getAttribute('value'); 363 375 } 376 } 377 else if ($nodeName == 'input' && $element->getAttribute('type') == 'file') 378 { 379 $filename = isset($arguments[$elementName]) ? $arguments[$elementName] : ''; 380 381 if (is_readable($filename)) 382 { 383 $fileError = UPLOAD_ERR_OK; 384 $fileSize = filesize($filename); 385 } 386 else 387 { 388 $fileError = UPLOAD_ERR_NO_FILE; 389 $fileSize = 0; 390 } 391 392 $this->files[$elementName] = array('name' => basename($filename), 'type' => '', 'tmp_name' => $filename, 'error' => $fileError, 'size' => $fileSize); 364 393 } 365 394 else if ( … … 424 453 425 454 // create request parameters 426 $arguments = sfToolkit::arrayDeepMerge($defaults, $ this->fields, $arguments);455 $arguments = sfToolkit::arrayDeepMerge($defaults, $arguments); 427 456 if ('post' == $method) 428 457 { branches/1.1/test/unit/util/sfBrowserTest.php
r6130 r6612 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test( 43, new lime_output_color());13 $t = new lime_test(50, new lime_output_color()); 14 14 15 15 // ->click() … … 22 22 $this->dom->validateOnParse = true; 23 23 $this->dom->loadHTML($html); 24 } 25 26 public function getFiles() 27 { 28 $f = $this->files; 29 $this->files = array(); 30 31 return $f; 24 32 } 25 33 … … 68 76 <input name="myarray[]" value="value2" /> 69 77 <input name="myarray[]" value="value3" /> 78 <input type="file" name="myfile" /> 70 79 <input type="button" name="mybutton" value="mybuttonvalue" /> 71 80 <input type="submit" name="submit" value="submit" /> … … 100 109 </span></div> 101 110 </form> 111 102 112 </body> 103 113 </html> … … 218 228 $b->call('http://app-test/index.phpmain/index'); 219 229 $t->is($b->getDefaultServerArray('HTTPS'), null, '->call() preserve non-secure requests'); 230 231 // file uploads 232 $t->diag('file uploads'); 233 234 $unexistentFilename = sfConfig::get('sf_test_cache_dir') . DIRECTORY_SEPARATOR . 'unexistent-file-'.md5(getmypid().'-'.microtime()); 235 $existentFilename = sfConfig::get('sf_test_cache_dir') . DIRECTORY_SEPARATOR . 'existent-file-'.md5(getmypid().'-'.microtime()); 236 file_put_contents($existentFilename, 'test'); 237 238 list($method, $uri, $parameters) = $b->click('submit', array('myfile'=>$unexistentFilename)); 239 $files = $b->getFiles(); 240 $t->is($method, 'post', 'file upload is using right method'); 241 $t->is($parameters['myfile'], $unexistentFilename, 'file upload kept _REQUEST variable available @todo check'); 242 $t->is(isset($files['myfile'])&&is_array($files['myfile']), true, 'file upload set up a _FILE entry for our test file'); 243 $t->is(array_keys($files['myfile']), array('name','type','tmp_name','error','size'), 'file upload returns correctly formatted array'); 244 $t->is($files['myfile']['error'], UPLOAD_ERR_NO_FILE, 'unexistent file does not exists (UPLOAD_ERR_NO_FILE)'); 245 246 list($method, $uri, $parameters) = $b->click('submit', array('myfile'=>$existentFilename)); 247 $files = $b->getFiles(); 248 249 $t->is($files['myfile']['error'], UPLOAD_ERR_OK, 'existent file exists (UPLOAD_ERR_OK)'); 250 $t->is($files['myfile']['name'], basename($existentFilename), 'name key ok'); 251