mirror of
https://github.com/Combodo/iTop.git
synced 2026-08-01 03:18:18 +02:00
Package operations: 2 installs, 23 updates, 0 removals - Updating psr/log (1.1.0 => 1.1.2) - Updating symfony/debug (v3.4.30 => v3.4.35) - Updating symfony/console (v3.4.30 => v3.4.35) - Updating symfony/dotenv (v3.4.30 => v3.4.35) - Updating symfony/routing (v3.4.30 => v3.4.35) - Updating symfony/finder (v3.4.30 => v3.4.35) - Updating symfony/filesystem (v3.4.30 => v3.4.35) - Installing symfony/polyfill-util (v1.12.0) - Installing symfony/polyfill-php56 (v1.12.0) - Updating symfony/http-foundation (v3.4.30 => v3.4.35) - Updating symfony/event-dispatcher (v3.4.30 => v3.4.35) - Updating symfony/http-kernel (v3.4.30 => v3.4.35) - Updating symfony/config (v3.4.30 => v3.4.35) - Updating symfony/dependency-injection (v3.4.30 => v3.4.35) - Updating symfony/class-loader (v3.4.30 => v3.4.35) - Updating symfony/cache (v3.4.30 => v3.4.35) - Updating symfony/framework-bundle (v3.4.30 => v3.4.35) - Updating twig/twig (v1.42.2 => v1.42.4) - Updating symfony/twig-bridge (v3.4.30 => v3.4.35) - Updating symfony/twig-bundle (v3.4.30 => v3.4.35) - Updating symfony/yaml (v3.4.30 => v3.4.35) - Updating symfony/stopwatch (v3.4.30 => v3.4.35) - Updating symfony/var-dumper (v3.4.30 => v3.4.35) - Updating symfony/web-profiler-bundle (v3.4.30 => v3.4.35) - Updating symfony/css-selector (v3.4.30 => v3.4.35)
174 lines
4.7 KiB
PHP
174 lines
4.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Symfony\Component\HttpFoundation\Tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|
use Symfony\Component\HttpFoundation\FileBag;
|
|
|
|
/**
|
|
* FileBagTest.
|
|
*
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
|
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
|
|
*/
|
|
class FileBagTest extends TestCase
|
|
{
|
|
public function testFileMustBeAnArrayOrUploadedFile()
|
|
{
|
|
$this->expectException('InvalidArgumentException');
|
|
new FileBag(['file' => 'foo']);
|
|
}
|
|
|
|
public function testShouldConvertsUploadedFiles()
|
|
{
|
|
$tmpFile = $this->createTempFile();
|
|
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
|
|
|
|
$bag = new FileBag(['file' => [
|
|
'name' => basename($tmpFile),
|
|
'type' => 'text/plain',
|
|
'tmp_name' => $tmpFile,
|
|
'error' => 0,
|
|
'size' => 100,
|
|
]]);
|
|
|
|
$this->assertEquals($file, $bag->get('file'));
|
|
}
|
|
|
|
public function testShouldSetEmptyUploadedFilesToNull()
|
|
{
|
|
$bag = new FileBag(['file' => [
|
|
'name' => '',
|
|
'type' => '',
|
|
'tmp_name' => '',
|
|
'error' => UPLOAD_ERR_NO_FILE,
|
|
'size' => 0,
|
|
]]);
|
|
|
|
$this->assertNull($bag->get('file'));
|
|
}
|
|
|
|
public function testShouldRemoveEmptyUploadedFilesForMultiUpload()
|
|
{
|
|
$bag = new FileBag(['files' => [
|
|
'name' => [''],
|
|
'type' => [''],
|
|
'tmp_name' => [''],
|
|
'error' => [UPLOAD_ERR_NO_FILE],
|
|
'size' => [0],
|
|
]]);
|
|
|
|
$this->assertSame([], $bag->get('files'));
|
|
}
|
|
|
|
public function testShouldNotRemoveEmptyUploadedFilesForAssociativeArray()
|
|
{
|
|
$bag = new FileBag(['files' => [
|
|
'name' => ['file1' => ''],
|
|
'type' => ['file1' => ''],
|
|
'tmp_name' => ['file1' => ''],
|
|
'error' => ['file1' => UPLOAD_ERR_NO_FILE],
|
|
'size' => ['file1' => 0],
|
|
]]);
|
|
|
|
$this->assertSame(['file1' => null], $bag->get('files'));
|
|
}
|
|
|
|
public function testShouldConvertUploadedFilesWithPhpBug()
|
|
{
|
|
$tmpFile = $this->createTempFile();
|
|
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
|
|
|
|
$bag = new FileBag([
|
|
'child' => [
|
|
'name' => [
|
|
'file' => basename($tmpFile),
|
|
],
|
|
'type' => [
|
|
'file' => 'text/plain',
|
|
],
|
|
'tmp_name' => [
|
|
'file' => $tmpFile,
|
|
],
|
|
'error' => [
|
|
'file' => 0,
|
|
],
|
|
'size' => [
|
|
'file' => 100,
|
|
],
|
|
],
|
|
]);
|
|
|
|
$files = $bag->all();
|
|
$this->assertEquals($file, $files['child']['file']);
|
|
}
|
|
|
|
public function testShouldConvertNestedUploadedFilesWithPhpBug()
|
|
{
|
|
$tmpFile = $this->createTempFile();
|
|
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
|
|
|
|
$bag = new FileBag([
|
|
'child' => [
|
|
'name' => [
|
|
'sub' => ['file' => basename($tmpFile)],
|
|
],
|
|
'type' => [
|
|
'sub' => ['file' => 'text/plain'],
|
|
],
|
|
'tmp_name' => [
|
|
'sub' => ['file' => $tmpFile],
|
|
],
|
|
'error' => [
|
|
'sub' => ['file' => 0],
|
|
],
|
|
'size' => [
|
|
'sub' => ['file' => 100],
|
|
],
|
|
],
|
|
]);
|
|
|
|
$files = $bag->all();
|
|
$this->assertEquals($file, $files['child']['sub']['file']);
|
|
}
|
|
|
|
public function testShouldNotConvertNestedUploadedFiles()
|
|
{
|
|
$tmpFile = $this->createTempFile();
|
|
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain', 100, 0);
|
|
$bag = new FileBag(['image' => ['file' => $file]]);
|
|
|
|
$files = $bag->all();
|
|
$this->assertEquals($file, $files['image']['file']);
|
|
}
|
|
|
|
protected function createTempFile()
|
|
{
|
|
return tempnam(sys_get_temp_dir().'/form_test', 'FormTest');
|
|
}
|
|
|
|
protected function setUp()
|
|
{
|
|
mkdir(sys_get_temp_dir().'/form_test', 0777, true);
|
|
}
|
|
|
|
protected function tearDown()
|
|
{
|
|
foreach (glob(sys_get_temp_dir().'/form_test/*') as $file) {
|
|
unlink($file);
|
|
}
|
|
|
|
rmdir(sys_get_temp_dir().'/form_test');
|
|
}
|
|
}
|