File tree Expand file tree Collapse file tree 6 files changed +34
-10
lines changed
tests/Symfony/Tests/Component Expand file tree Collapse file tree 6 files changed +34
-10
lines changed Original file line number Diff line number Diff line change 13
13
14
14
use Symfony \Component \HttpFoundation \File \File ;
15
15
use Symfony \Component \Form \Exception \FormException ;
16
+ use Symfony \Component \HttpFoundation \File \UploadedFile ;
16
17
17
18
/**
18
19
* A file field to upload files.
@@ -66,6 +67,9 @@ protected function configure()
66
67
protected function preprocessData (array $ data )
67
68
{
68
69
if ($ data ['file ' ]) {
70
+ if (!$ data ['file ' ] instanceof UploadedFile) {
71
+ throw new \UnexpectedValueException ('Uploaded file is not of type UploadedFile, your form tag is probably missing the enctype="multipart/form-data" attribute. ' );
72
+ }
69
73
switch ($ data ['file ' ]->getError ()) {
70
74
case UPLOAD_ERR_INI_SIZE :
71
75
$ this ->iniSizeExceeded = true ;
@@ -86,7 +90,7 @@ protected function preprocessData(array $data)
86
90
default :
87
91
$ data ['file ' ]->move ($ this ->getTmpDir ());
88
92
$ data ['file ' ]->rename ($ this ->getTmpName ($ data ['token ' ]));
89
- $ data ['original_name ' ] = $ data ['file ' ]->getOriginalName ();
93
+ $ data ['original_name ' ] = $ data ['file ' ]->getName ();
90
94
$ data ['file ' ] = '' ;
91
95
break ;
92
96
}
Original file line number Diff line number Diff line change 2
2
3
3
/*
4
4
* This file is part of the Symfony package.
5
- *
5
+ *
6
6
* (c) Fabien Potencier <fabien@symfony.com>
7
7
*
8
8
* For the full copyright and license information, please view the LICENSE
@@ -497,7 +497,7 @@ public function __construct($path)
497
497
*/
498
498
public function __toString ()
499
499
{
500
- return null === $ this ->getPath () ? '' : $ this ->getPath () ;
500
+ return null === $ this ->path ? '' : $ this ->path ;
501
501
}
502
502
503
503
/**
Original file line number Diff line number Diff line change 2
2
3
3
/*
4
4
* This file is part of the Symfony package.
5
- *
5
+ *
6
6
* (c) Fabien Potencier <fabien@symfony.com>
7
7
*
8
8
* For the full copyright and license information, please view the LICENSE
@@ -101,13 +101,18 @@ public function getMimeType()
101
101
}
102
102
103
103
/**
104
- * Returns the original file name including its extension.
104
+ * Returns the absolute file name without dots
105
+ *
106
+ * Until the uploaded file is moved, it will return the name of the temporary file
105
107
*
106
- * @returns string The file name
108
+ * @returns string The file path
107
109
*/
108
- public function getOriginalName ()
110
+ public function getName ()
109
111
{
110
- return $ this ->originalName ;
112
+ if (!$ this ->moved ) {
113
+ return $ this ->originalName ;
114
+ }
115
+ return parent ::getName ();
111
116
}
112
117
113
118
/**
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ public function testSubmitUploadsNewFiles()
70
70
$ that ->createTmpFile ($ tmpPath );
71
71
}));
72
72
$ file ->expects ($ this ->any ())
73
- ->method ('getOriginalName ' )
73
+ ->method ('getName ' )
74
74
->will ($ this ->returnValue ('original_name.jpg ' ));
75
75
76
76
$ this ->field ->submit (array (
@@ -111,6 +111,18 @@ public function testSubmitKeepsUploadedFilesOnErrors()
111
111
$ this ->assertEquals (realpath ($ tmpPath ), realpath ($ this ->field ->getData ()));
112
112
}
113
113
114
+ /**
115
+ * @expectedException UnexpectedValueException
116
+ */
117
+ public function testSubmitFailsOnMissingMultipart ()
118
+ {
119
+ $ this ->field ->submit (array (
120
+ 'file ' => 'foo.jpg ' ,
121
+ 'token ' => '12345 ' ,
122
+ 'original_name ' => 'original_name.jpg ' ,
123
+ ));
124
+ }
125
+
114
126
public function testSubmitKeepsOldFileIfNotOverwritten ()
115
127
{
116
128
$ oldPath = tempnam (sys_get_temp_dir (), 'FileFieldTest ' );
Original file line number Diff line number Diff line change @@ -59,6 +59,9 @@ public function testGuessWithIncorrectPath()
59
59
60
60
public function testGuessWithNonReadablePath ()
61
61
{
62
+ if (strstr (PHP_OS , 'WIN ' )) {
63
+ $ this ->markTestSkipped ('Can not verify chmod operations on Windows ' );
64
+ }
62
65
$ path = __DIR__ .'/../Fixtures/to_delete ' ;
63
66
touch ($ path );
64
67
chmod ($ path , 0333 );
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ public function testGetOriginalName()
95
95
null
96
96
);
97
97
98
- $ this ->assertEquals ('original.gif ' , $ file ->getOriginalName ());
98
+ $ this ->assertEquals ('original.gif ' , $ file ->getName ());
99
99
}
100
100
}
101
101
}
You can’t perform that action at this time.
0 commit comments