Skip to content

Commit

Permalink
[HttpKernel] Fix and test previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Jun 14, 2011
1 parent ac0c00c commit 38b3b74
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Symfony/Component/HttpKernel/Client.php
Expand Up @@ -121,7 +121,14 @@ protected function filterFiles(array $files)
$filtered[$key] = $this->filterFiles($value);
} elseif ($value instanceof UploadedFile) {
// Create a test mode UploadedFile
$filtered[$key] = new UploadedFile($value->getPath(), $value->getName(), $value->getMimeType(), $value->getSize(), $value->getError(), true);
$filtered[$key] = new UploadedFile(
$value->getPathname(),
$value->getClientOriginalName(),
$value->getClientMimeType(),
$value->getClientSize(),
$value->getError(),
true
);
} else {
$filtered[$key] = $value;
}
Expand Down
29 changes: 29 additions & 0 deletions tests/Symfony/Tests/Component/HttpKernel/ClientTest.php
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\File\UploadedFile;

require_once __DIR__.'/TestHttpKernel.php';

Expand Down Expand Up @@ -76,4 +77,32 @@ public function testFilterResponseConvertsCookies()
$domResponse = $m->invoke($client, $response);
$this->assertEquals('foo=bar; expires=Sun, 15-Feb-2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly, foo1=bar1; expires=Sun, 15-Feb-2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly', $domResponse->getHeader('Set-Cookie'));
}

public function testUploadedFile()
{
$source = tempnam(sys_get_temp_dir(), 'source');
$target = sys_get_temp_dir().'/sf.moved.file';
@unlink($target);

$kernel = new TestHttpKernel();
$client = new Client($kernel);

$client->request('POST', '/', array(), array(new UploadedFile($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK)));

$files = $kernel->request->files->all();

$this->assertEquals(1, count($files));

$file = $files[0];

$this->assertEquals('original', $file->getClientOriginalName());
$this->assertEquals('mime/original', $file->getClientMimeType());
$this->assertEquals('123', $file->getClientSize());
$this->assertTrue($file->isValid());

$file->move(dirname($target), basename($target));

$this->assertFileExists($target);
unlink($target);
}
}
3 changes: 3 additions & 0 deletions tests/Symfony/Tests/Component/HttpKernel/TestHttpKernel.php
Expand Up @@ -19,6 +19,8 @@

class TestHttpKernel extends HttpKernel implements ControllerResolverInterface
{
public $request;

public function __construct()
{
parent::__construct(new EventDispatcher(), $this);
Expand All @@ -36,6 +38,7 @@ public function getArguments(Request $request, $controller)

public function callController(Request $request)
{
$this->request = $request;
return new Response('Request: '.$request->getRequestUri());
}
}

0 comments on commit 38b3b74

Please sign in to comment.