mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 12:33:26 +00:00

Conflicts: composer.lock lib/Alchemy/Phrasea/Application.php lib/Alchemy/Phrasea/Command/Setup/H264MappingGenerator.php lib/Alchemy/Phrasea/Controller/AbstractDelivery.php lib/Alchemy/Phrasea/Controller/Prod/DoDownload.php lib/Alchemy/Phrasea/Controller/Prod/Edit.php lib/Alchemy/Phrasea/Controller/Prod/Story.php lib/Alchemy/Phrasea/Controller/Prod/Upload.php lib/Alchemy/Phrasea/Controller/Report/Activity.php lib/Alchemy/Phrasea/Controller/Report/Root.php lib/Alchemy/Phrasea/Controller/Root/Account.php lib/Alchemy/Phrasea/Core/PhraseaEvents.php lib/Alchemy/Phrasea/Core/Version.php lib/classes/API/V1/adapter.php lib/classes/User/Adapter.php lib/classes/databox.php lib/classes/media/subdef.php lib/classes/module/report.php lib/classes/module/report/activity.php lib/classes/module/report/connexion.php lib/classes/module/report/download.php lib/classes/module/report/nav.php lib/classes/module/report/question.php lib/classes/module/report/sqlaction.php lib/classes/module/report/sqlconnexion.php lib/classes/module/report/sqldownload.php lib/classes/module/report/sqlfilter.php lib/classes/task/abstract.php locale/de_DE/LC_MESSAGES/phraseanet.mo locale/de_DE/LC_MESSAGES/phraseanet.po locale/en_GB/LC_MESSAGES/phraseanet.mo locale/en_GB/LC_MESSAGES/phraseanet.po locale/fr_FR/LC_MESSAGES/phraseanet.mo locale/fr_FR/LC_MESSAGES/phraseanet.po locale/nl_NL/LC_MESSAGES/phraseanet.mo locale/nl_NL/LC_MESSAGES/phraseanet.po locale/phraseanet.pot templates/web/prod/index.html.twig tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php tests/classes/api/v1/api_v1_adapterTest.php tests/classes/report/activityTest.php tests/classes/report/editTest.php
161 lines
6.4 KiB
PHP
161 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Tests\Phrasea\Http;
|
|
|
|
use Alchemy\Phrasea\Http\ServeFileResponseFactory;
|
|
use Alchemy\Phrasea\Http\XSendFile\NginxMode;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
class ServeFileResponseFactoryTest extends \PhraseanetWebTestCase
|
|
{
|
|
protected $factory;
|
|
|
|
public function testDeliverFileFactoryCreation()
|
|
{
|
|
$factory = ServeFileResponseFactory::create(self::$DI['app']);
|
|
$this->assertInstanceOf('Alchemy\Phrasea\Http\ServeFileResponseFactory', $factory);
|
|
}
|
|
|
|
public function testDeliverFile()
|
|
{
|
|
$this->factory = new ServeFileResponseFactory(new \unicode());
|
|
|
|
$response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg');
|
|
|
|
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response);
|
|
$this->assertEquals('inline; filename="cestlafete.jpg"', $response->headers->get('content-disposition'));
|
|
$this->assertEquals(0, $response->getMaxAge());
|
|
$response->setPrivate();
|
|
$this->assertTrue($response->headers->getCacheControlDirective('private'));
|
|
}
|
|
|
|
public function testDeliverFileWithDuration()
|
|
{
|
|
$this->factory = new ServeFileResponseFactory(new \unicode());
|
|
|
|
$response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'hello', 'attachment', 'application/json', 23456);
|
|
|
|
$this->assertEquals(23456, $response->getMaxAge());
|
|
}
|
|
|
|
public function testDeliverFileWithFilename()
|
|
{
|
|
$this->factory = new ServeFileResponseFactory(new \unicode());
|
|
|
|
$response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg');
|
|
|
|
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response);
|
|
$this->assertEquals('inline; filename="toto.jpg"', $response->headers->get('content-disposition'));
|
|
}
|
|
|
|
public function testDeliverFileWithFilenameAndDisposition()
|
|
{
|
|
$this->factory = new ServeFileResponseFactory(new \unicode());
|
|
|
|
$response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg', 'attachment');
|
|
|
|
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response);
|
|
$this->assertEquals('attachment; filename="toto.jpg"', $response->headers->get('content-disposition'));
|
|
}
|
|
|
|
public function testDeliverFileWithFilenameAndDispositionAndXSendFile()
|
|
{
|
|
BinaryFileResponse::trustXSendfileTypeHeader();
|
|
$this->factory = new ServeFileResponseFactory(new \unicode());
|
|
$mode = new NginxMode(
|
|
[
|
|
[
|
|
'directory' => __DIR__ . '/../../../../files/',
|
|
'mount-point' => '/protected/'
|
|
]
|
|
]
|
|
);
|
|
$request = Request::create('/');
|
|
$mode->setHeaders($request);
|
|
|
|
$response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg', 'attachment');
|
|
$response->prepare($request);
|
|
|
|
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response);
|
|
$this->assertEquals('attachment; filename="toto.jpg"', $response->headers->get('content-disposition'));
|
|
$this->assertEquals('/protected/cestlafete.jpg', $response->headers->get('x-accel-redirect'));
|
|
}
|
|
|
|
public function testDeliverFileWithFilenameAndDispositionAndXSendFileAndNoTrailingSlashes()
|
|
{
|
|
BinaryFileResponse::trustXSendfileTypeHeader();
|
|
$this->factory = new ServeFileResponseFactory(new \unicode());
|
|
$mode = new NginxMode(
|
|
[
|
|
[
|
|
'directory' => __DIR__ . '/../../../../files',
|
|
'mount-point' => '/protected'
|
|
]
|
|
]
|
|
);
|
|
$request = Request::create('/');
|
|
$mode->setHeaders($request);
|
|
|
|
$response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg', 'attachment');
|
|
$response->prepare($request);
|
|
|
|
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response);
|
|
$this->assertEquals('attachment; filename="toto.jpg"', $response->headers->get('content-disposition'));
|
|
$this->assertEquals('/protected/cestlafete.jpg', $response->headers->get('x-accel-redirect'));
|
|
}
|
|
|
|
/**
|
|
* @expectedException \Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException
|
|
*/
|
|
public function testDeliverUnexistingFile()
|
|
{
|
|
BinaryFileResponse::trustXSendfileTypeHeader();
|
|
$this->factory = new ServeFileResponseFactory(new \unicode());
|
|
|
|
$this->factory->deliverFile(__DIR__ . '/../../../../files/does_not_exists.jpg', 'toto.jpg', 'attachment');
|
|
}
|
|
|
|
public function testDeliverFileWithFilenameAndDispositionAndXSendFileButFileNotInXAccelMapping()
|
|
{
|
|
BinaryFileResponse::trustXSendfileTypeHeader();
|
|
$this->factory = new ServeFileResponseFactory(new \unicode());
|
|
$mode = new NginxMode(
|
|
[
|
|
[
|
|
'directory' => __DIR__ . '/../../../../files/',
|
|
'mount-point' => '/protected/'
|
|
]
|
|
]
|
|
);
|
|
$request = Request::create('/');
|
|
$mode->setHeaders($request);
|
|
|
|
$file = __DIR__ . '/../../../../classes/PhraseanetTestCase.php';
|
|
|
|
$response = $this->factory->deliverFile($file, 'PhraseanetTestCase.php', 'attachment');
|
|
$response->prepare($request);
|
|
|
|
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response);
|
|
$this->assertEquals('attachment; filename="PhraseanetTestCase.php"', $response->headers->get('content-disposition'));
|
|
$this->assertEquals(realpath($file), $response->headers->get('x-accel-redirect'));
|
|
}
|
|
|
|
public function testDeliverDatas()
|
|
{
|
|
$this->factory = new ServeFileResponseFactory(new \unicode());
|
|
|
|
$data = 'Sex,Name,Birthday
|
|
M,Alphonse,1932
|
|
F,Béatrice,1964
|
|
F,Charlotte,1988';
|
|
|
|
$response = $this->factory->deliverData($data, 'data.csv', 'text/csv', 'attachment');
|
|
|
|
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response);
|
|
$this->assertEquals('attachment; filename="data.csv"', $response->headers->get('content-disposition'));
|
|
$this->assertEquals('text/csv', $response->headers->get('content-type'));
|
|
$this->assertEquals($data, $response->getContent());
|
|
}
|
|
}
|