Skip to content

Commit 5f1e0bf

Browse files
rogyartiagosampaio
authored andcommitted
Integration test for checking file generation and removing process
1 parent d3a7b97 commit 5f1e0bf

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\Framework\App\Filesystem\Images;
10+
11+
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\App\Response\Http\FileFactory;
13+
use Magento\Framework\Filesystem;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Zend\Http\Header\ContentType;
16+
17+
/**
18+
* Class CreatePdfFileTest
19+
*
20+
* Integration test for testing a file creation from string
21+
*/
22+
class CreatePdfFileTest extends \PHPUnit\Framework\TestCase
23+
{
24+
public function testGenerateFileFromString()
25+
{
26+
$objectManager = Bootstrap::getObjectManager();
27+
/** @var FileFactory $fileFactory */
28+
$fileFactory = $objectManager->get(FileFactory::class);
29+
/** @var Filesystem $filesystem */
30+
$filesystem = $objectManager->get(Filesystem::class);
31+
$filename = 'test.pdf';
32+
$contentType = 'application/pdf';
33+
$fileContent = ['type' => 'string', 'value' => ''];
34+
$response = $fileFactory->create($filename, $fileContent, DirectoryList::VAR_DIR, $contentType);
35+
/** @var ContentType $contentTypeHeader */
36+
$contentTypeHeader = $response->getHeader('Content-type');
37+
38+
/* Check the system returns the correct type */
39+
self::assertEquals("Content-Type: $contentType", $contentTypeHeader->toString());
40+
41+
$varDirectory = $filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
42+
$varDirectory->isFile($filename);
43+
44+
/* Check the file is generated */
45+
self::assertTrue($varDirectory->isFile($filename));
46+
47+
/* Check the file is removed after generation if the corresponding option is set */
48+
$fileContent = ['type' => 'string', 'value' => '', 'rm' => true];
49+
$fileFactory->create($filename, $fileContent, DirectoryList::VAR_DIR, $contentType);
50+
51+
self::assertFalse($varDirectory->isFile($filename));
52+
}
53+
}

0 commit comments

Comments
 (0)