mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-08-10 17:33:56 +02:00
fix #42
This commit is contained in:
@@ -61,12 +61,12 @@ class ZipFileAddDirTest extends ZipTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ZipFileInterface $zipFile
|
||||
* @param array $actualResultFiles
|
||||
* @param string $localPath
|
||||
* @param ZipFile $zipFile
|
||||
* @param array $actualResultFiles
|
||||
* @param string $localPath
|
||||
*/
|
||||
protected static function assertFilesResult(
|
||||
ZipFileInterface $zipFile,
|
||||
ZipFile $zipFile,
|
||||
array $actualResultFiles = [],
|
||||
$localPath = '/'
|
||||
) {
|
||||
|
@@ -2212,4 +2212,60 @@ class ZipFileTest extends ZipTestCase
|
||||
static::assertFalse($zipFile->getEntryInfo('file 2')->isEncrypted());
|
||||
$zipFile->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @dataProvider provideOutputAsAttachment
|
||||
*
|
||||
* @param string $zipFilename
|
||||
* @param string|null $mimeType
|
||||
* @param string $expectedMimeType
|
||||
* @param bool $attachment
|
||||
* @param string $expectedAttachment
|
||||
*
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testOutputAsAttachment($zipFilename, $mimeType, $expectedMimeType, $attachment, $expectedAttachment)
|
||||
{
|
||||
$zipFile = new ZipFile();
|
||||
$file1Contents = 'content 1';
|
||||
$zipFile['file 1'] = $file1Contents;
|
||||
|
||||
ob_start();
|
||||
$zipFile->outputAsAttachment($zipFilename, $mimeType, $attachment);
|
||||
$zipContents = ob_get_clean();
|
||||
|
||||
$zipFile->close();
|
||||
|
||||
$length = \strlen($zipContents);
|
||||
static::assertTrue($length > 0);
|
||||
|
||||
$zipFile->openFromString($zipContents);
|
||||
static::assertSame($zipFile['file 1'], $file1Contents);
|
||||
$zipFile->close();
|
||||
|
||||
if (\function_exists('xdebug_get_headers')) {
|
||||
$expectedHeaders = [
|
||||
'Content-Disposition: ' . $expectedAttachment . '; filename="' . $zipFilename . '"',
|
||||
'Content-Type: ' . $expectedMimeType,
|
||||
'Content-Length: ' . $length,
|
||||
];
|
||||
/** @noinspection ForgottenDebugOutputInspection */
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
static::assertSame($expectedHeaders, xdebug_get_headers());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function provideOutputAsAttachment()
|
||||
{
|
||||
return [
|
||||
['file.zip', null, 'application/zip', true, 'attachment'],
|
||||
['file.zip', 'application/x-zip', 'application/x-zip', false, 'inline'],
|
||||
['file.apk', null, 'application/vnd.android.package-archive', true, 'attachment'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user