File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed
src/Symfony/Component/DomCrawler Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -59,11 +59,17 @@ public function setValue($value)
59
59
if (null !== $ value && is_readable ($ value )) {
60
60
$ error = UPLOAD_ERR_OK ;
61
61
$ size = filesize ($ value );
62
- $ name = basename ($ value );
62
+ $ info = pathinfo ($ value );
63
+ $ name = $ info ['basename ' ];
63
64
64
65
// copy to a tmp location
65
- $ tmp = tempnam (sys_get_temp_dir (), 'upload ' );
66
- unlink ($ tmp );
66
+ $ tmp = sys_get_temp_dir ().'/ ' .sha1 (uniqid (mt_rand (), true ));
67
+ if (array_key_exists ('extension ' , $ info )) {
68
+ $ tmp .= '. ' .$ info ['extension ' ];
69
+ }
70
+ if (is_file ($ tmp )) {
71
+ unlink ($ tmp );
72
+ }
67
73
copy ($ value , $ tmp );
68
74
$ value = $ tmp ;
69
75
} else {
Original file line number Diff line number Diff line change @@ -56,8 +56,26 @@ public function testSetValue($method)
56
56
$ this ->assertEquals (basename (__FILE__ ), $ value ['name ' ], "-> $ method() sets the name of the file field " );
57
57
$ this ->assertEquals ('' , $ value ['type ' ], "-> $ method() sets the type of the file field " );
58
58
$ this ->assertInternalType ('string ' , $ value ['tmp_name ' ], "-> $ method() sets the tmp_name of the file field " );
59
+ $ this ->assertFileExists ($ value ['tmp_name ' ], "-> $ method() creates a copy of the file at the tmp_name path " );
59
60
$ this ->assertEquals (0 , $ value ['error ' ], "-> $ method() sets the error of the file field " );
60
61
$ this ->assertEquals (filesize (__FILE__ ), $ value ['size ' ], "-> $ method() sets the size of the file field " );
62
+
63
+ $ origInfo = pathinfo (__FILE__ );
64
+ $ tmpInfo = pathinfo ($ value ['tmp_name ' ]);
65
+ $ this ->assertEquals (
66
+ $ origInfo ['extension ' ],
67
+ $ tmpInfo ['extension ' ],
68
+ "-> $ method() keeps the same file extension in the tmp_name copy "
69
+ );
70
+
71
+ $ field ->$ method (__DIR__ .'/../Fixtures/no-extension ' );
72
+ $ value = $ field ->getValue ();
73
+
74
+ $ this ->assertArrayNotHasKey (
75
+ 'extension ' ,
76
+ pathinfo ($ value ['tmp_name ' ]),
77
+ "-> $ method() does not add a file extension in the tmp_name copy "
78
+ );
61
79
}
62
80
63
81
public function getSetValueMethods ()
Original file line number Diff line number Diff line change
1
+ Test
You can’t perform that action at this time.
0 commit comments