-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration test for checking file generation and removing process
- Loading branch information
1 parent
d3a7b97
commit 5f1e0bf
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
dev/tests/integration/testsuite/Magento/Framework/App/Filesystem/CreatePdfFileTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
* | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Framework\App\Filesystem\Images; | ||
|
||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\App\Response\Http\FileFactory; | ||
use Magento\Framework\Filesystem; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Zend\Http\Header\ContentType; | ||
|
||
/** | ||
* Class CreatePdfFileTest | ||
* | ||
* Integration test for testing a file creation from string | ||
*/ | ||
class CreatePdfFileTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
public function testGenerateFileFromString() | ||
{ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
/** @var FileFactory $fileFactory */ | ||
$fileFactory = $objectManager->get(FileFactory::class); | ||
/** @var Filesystem $filesystem */ | ||
$filesystem = $objectManager->get(Filesystem::class); | ||
$filename = 'test.pdf'; | ||
$contentType = 'application/pdf'; | ||
$fileContent = ['type' => 'string', 'value' => '']; | ||
$response = $fileFactory->create($filename, $fileContent, DirectoryList::VAR_DIR, $contentType); | ||
/** @var ContentType $contentTypeHeader */ | ||
$contentTypeHeader = $response->getHeader('Content-type'); | ||
|
||
/* Check the system returns the correct type */ | ||
self::assertEquals("Content-Type: $contentType", $contentTypeHeader->toString()); | ||
|
||
$varDirectory = $filesystem->getDirectoryRead(DirectoryList::VAR_DIR); | ||
$varDirectory->isFile($filename); | ||
|
||
/* Check the file is generated */ | ||
self::assertTrue($varDirectory->isFile($filename)); | ||
|
||
/* Check the file is removed after generation if the corresponding option is set */ | ||
$fileContent = ['type' => 'string', 'value' => '', 'rm' => true]; | ||
$fileFactory->create($filename, $fileContent, DirectoryList::VAR_DIR, $contentType); | ||
|
||
self::assertFalse($varDirectory->isFile($filename)); | ||
} | ||
} |