4
4
5
5
use Illuminate \Http \UploadedFile ;
6
6
use PHPUnit \Framework \TestCase ;
7
+ use Symfony \Component \HttpFoundation \File \UploadedFile as SymfonyUploadedFile ;
7
8
8
9
class HttpUploadedFileTest extends TestCase
9
10
{
@@ -19,4 +20,49 @@ public function testUploadedFileCanRetrieveContentsFromTextFile()
19
20
20
21
$ this ->assertSame ('This is a story about something that happened long ago when your grandfather was a child. ' , trim ($ file ->get ()));
21
22
}
23
+
24
+ public function testUploadedFileInRequestContainsOriginalPathAndName ()
25
+ {
26
+ $ symfonyFile = new SymfonyUploadedFile (__FILE__ , '' );
27
+ $ this ->assertSame ('' , $ symfonyFile ->getClientOriginalName ());
28
+ $ this ->assertSame ('' , $ symfonyFile ->getClientOriginalPath ());
29
+ $ file = UploadedFile::createFromBase ($ symfonyFile );
30
+ $ this ->assertSame ('' , $ file ->getClientOriginalName ());
31
+ $ this ->assertSame ('' , $ file ->getClientOriginalPath ());
32
+
33
+ $ symfonyFile = new SymfonyUploadedFile (__FILE__ , 'test.txt ' );
34
+ $ this ->assertSame ('test.txt ' , $ symfonyFile ->getClientOriginalName ());
35
+ $ this ->assertSame ('test.txt ' , $ symfonyFile ->getClientOriginalPath ());
36
+ $ file = UploadedFile::createFromBase ($ symfonyFile );
37
+ $ this ->assertSame ('test.txt ' , $ file ->getClientOriginalName ());
38
+ $ this ->assertSame ('test.txt ' , $ file ->getClientOriginalPath ());
39
+
40
+ $ symfonyFile = new SymfonyUploadedFile (__FILE__ , '/test.txt ' );
41
+ $ this ->assertSame ('test.txt ' , $ symfonyFile ->getClientOriginalName ());
42
+ $ this ->assertSame ('/test.txt ' , $ symfonyFile ->getClientOriginalPath ());
43
+ $ file = UploadedFile::createFromBase ($ symfonyFile );
44
+ $ this ->assertSame ('test.txt ' , $ file ->getClientOriginalName ());
45
+ $ this ->assertSame ('/test.txt ' , $ file ->getClientOriginalPath ());
46
+
47
+ $ symfonyFile = new SymfonyUploadedFile (__FILE__ , '/foo/bar/test.txt ' );
48
+ $ this ->assertSame ('test.txt ' , $ symfonyFile ->getClientOriginalName ());
49
+ $ this ->assertSame ('/foo/bar/test.txt ' , $ symfonyFile ->getClientOriginalPath ());
50
+ $ file = UploadedFile::createFromBase ($ symfonyFile );
51
+ $ this ->assertSame ('test.txt ' , $ file ->getClientOriginalName ());
52
+ $ this ->assertSame ('/foo/bar/test.txt ' , $ file ->getClientOriginalPath ());
53
+
54
+ $ symfonyFile = new SymfonyUploadedFile (__FILE__ , '/foo/bar/test.txt ' );
55
+ $ this ->assertSame ('test.txt ' , $ symfonyFile ->getClientOriginalName ());
56
+ $ this ->assertSame ('/foo/bar/test.txt ' , $ symfonyFile ->getClientOriginalPath ());
57
+ $ file = UploadedFile::createFromBase ($ symfonyFile );
58
+ $ this ->assertSame ('test.txt ' , $ file ->getClientOriginalName ());
59
+ $ this ->assertSame ('/foo/bar/test.txt ' , $ file ->getClientOriginalPath ());
60
+
61
+ $ symfonyFile = new SymfonyUploadedFile (__FILE__ , 'file: \\foo \\test.txt ' );
62
+ $ this ->assertSame ('test.txt ' , $ symfonyFile ->getClientOriginalName ());
63
+ $ this ->assertSame ('file:/foo/test.txt ' , $ symfonyFile ->getClientOriginalPath ());
64
+ $ file = UploadedFile::createFromBase ($ symfonyFile );
65
+ $ this ->assertSame ('test.txt ' , $ file ->getClientOriginalName ());
66
+ $ this ->assertSame ('file:/foo/test.txt ' , $ file ->getClientOriginalPath ());
67
+ }
22
68
}
0 commit comments