2018-07-21 20:43:25 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Illuminate\Tests\Http;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\UploadedFile;
|
2019-09-10 17:16:05 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2024-12-17 07:09:56 -08:00
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile;
|
2018-07-21 20:43:25 -05:00
|
|
|
|
|
|
|
|
class HttpUploadedFileTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
public function testUploadedFileCanRetrieveContentsFromTextFile()
|
|
|
|
|
{
|
|
|
|
|
$file = new UploadedFile(
|
2018-07-22 10:53:49 -05:00
|
|
|
__DIR__.'/fixtures/test.txt',
|
2018-07-23 22:44:14 -05:00
|
|
|
'test.txt',
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
true
|
2018-07-21 20:43:25 -05:00
|
|
|
);
|
|
|
|
|
|
2019-08-27 14:48:17 +02:00
|
|
|
$this->assertSame('This is a story about something that happened long ago when your grandfather was a child.', trim($file->get()));
|
2018-07-21 20:43:25 -05:00
|
|
|
}
|
2024-12-17 07:09:56 -08:00
|
|
|
|
|
|
|
|
public function testUploadedFileInRequestContainsOriginalPathAndName()
|
|
|
|
|
{
|
|
|
|
|
$symfonyFile = new SymfonyUploadedFile(__FILE__, '');
|
|
|
|
|
$this->assertSame('', $symfonyFile->getClientOriginalName());
|
|
|
|
|
$this->assertSame('', $symfonyFile->getClientOriginalPath());
|
|
|
|
|
$file = UploadedFile::createFromBase($symfonyFile);
|
|
|
|
|
$this->assertSame('', $file->getClientOriginalName());
|
|
|
|
|
$this->assertSame('', $file->getClientOriginalPath());
|
|
|
|
|
|
|
|
|
|
$symfonyFile = new SymfonyUploadedFile(__FILE__, 'test.txt');
|
|
|
|
|
$this->assertSame('test.txt', $symfonyFile->getClientOriginalName());
|
|
|
|
|
$this->assertSame('test.txt', $symfonyFile->getClientOriginalPath());
|
|
|
|
|
$file = UploadedFile::createFromBase($symfonyFile);
|
|
|
|
|
$this->assertSame('test.txt', $file->getClientOriginalName());
|
|
|
|
|
$this->assertSame('test.txt', $file->getClientOriginalPath());
|
|
|
|
|
|
|
|
|
|
$symfonyFile = new SymfonyUploadedFile(__FILE__, '/test.txt');
|
|
|
|
|
$this->assertSame('test.txt', $symfonyFile->getClientOriginalName());
|
|
|
|
|
$this->assertSame('/test.txt', $symfonyFile->getClientOriginalPath());
|
|
|
|
|
$file = UploadedFile::createFromBase($symfonyFile);
|
|
|
|
|
$this->assertSame('test.txt', $file->getClientOriginalName());
|
|
|
|
|
$this->assertSame('/test.txt', $file->getClientOriginalPath());
|
|
|
|
|
|
|
|
|
|
$symfonyFile = new SymfonyUploadedFile(__FILE__, '/foo/bar/test.txt');
|
|
|
|
|
$this->assertSame('test.txt', $symfonyFile->getClientOriginalName());
|
|
|
|
|
$this->assertSame('/foo/bar/test.txt', $symfonyFile->getClientOriginalPath());
|
|
|
|
|
$file = UploadedFile::createFromBase($symfonyFile);
|
|
|
|
|
$this->assertSame('test.txt', $file->getClientOriginalName());
|
|
|
|
|
$this->assertSame('/foo/bar/test.txt', $file->getClientOriginalPath());
|
|
|
|
|
|
|
|
|
|
$symfonyFile = new SymfonyUploadedFile(__FILE__, '/foo/bar/test.txt');
|
|
|
|
|
$this->assertSame('test.txt', $symfonyFile->getClientOriginalName());
|
|
|
|
|
$this->assertSame('/foo/bar/test.txt', $symfonyFile->getClientOriginalPath());
|
|
|
|
|
$file = UploadedFile::createFromBase($symfonyFile);
|
|
|
|
|
$this->assertSame('test.txt', $file->getClientOriginalName());
|
|
|
|
|
$this->assertSame('/foo/bar/test.txt', $file->getClientOriginalPath());
|
|
|
|
|
|
|
|
|
|
$symfonyFile = new SymfonyUploadedFile(__FILE__, 'file:\\foo\\test.txt');
|
|
|
|
|
$this->assertSame('test.txt', $symfonyFile->getClientOriginalName());
|
|
|
|
|
$this->assertSame('file:/foo/test.txt', $symfonyFile->getClientOriginalPath());
|
|
|
|
|
$file = UploadedFile::createFromBase($symfonyFile);
|
|
|
|
|
$this->assertSame('test.txt', $file->getClientOriginalName());
|
|
|
|
|
$this->assertSame('file:/foo/test.txt', $file->getClientOriginalPath());
|
|
|
|
|
}
|
2018-07-21 20:43:25 -05:00
|
|
|
}
|