This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*
*/
declare(strict_types=1);
namespace Magento\Framework\App\Filesystem;
use Magento\Framework\App\Response\Http\FileFactory;
use Magento\Framework\Filesystem;
use Magento\TestFramework\Helper\Bootstrap;
use Laminas\Http\Header\ContentType;
/**
* Class CreatePdfFileTest
*
* Integration test for testing a file creation from string
*/
class CreatePdfFileTest extends \PHPUnit\Framework\TestCase
{
/**
* @throws \Exception
*/
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);
ob_start();
$response->sendResponse();
ob_end_clean();
/** @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];
$response = $fileFactory->create($filename, $fileContent, DirectoryList::VAR_DIR, $contentType);
ob_start();
$response->sendResponse();
ob_end_clean();
self::assertFalse($varDirectory->isFile($filename));
}
}
@@ -0,0 +1,124 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\App\Filesystem;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Test class for the \Magento\Framework\App\Filesystem\DirectoryResolver verification.
*/
class DirectoryResolverTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var \Magento\Framework\App\Filesystem\DirectoryResolver
*/
private $directoryResolver;
/**
* @var \Magento\Framework\Filesystem
*/
private $filesystem;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->directoryResolver = $this->objectManager
->create(\Magento\Framework\App\Filesystem\DirectoryResolver::class);
$this->filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
}
/**
* @param string $path
* @param string $directoryConfig
* @param bool $expectation
* @dataProvider validatePathDataProvider
* @throws \Magento\Framework\Exception\FileSystemException
* @magentoAppIsolation enabled
* @return void
*/
public function testValidatePath($path, $directoryConfig, $expectation)
{
$directory = $this->filesystem
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
$path = $directory->getAbsolutePath() .'/' .$path;
$this->assertEquals($expectation, $this->directoryResolver->validatePath($path, $directoryConfig));
}
/**
* @magentoAppIsolation enabled
* @return void
*/
public function testValidatePathWithException()
{
$this->expectException(\Magento\Framework\Exception\FileSystemException::class);
$directory = $this->filesystem
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
$path = $directory->getAbsolutePath();
$this->directoryResolver->validatePath($path, 'wrong_dir');
}
/**
* @param string $path
* @param string $directoryConfig
* @param bool $expectation
* @dataProvider validatePathDataProvider
* @throws \Magento\Framework\Exception\FileSystemException
* @magentoAppIsolation enabled
* @return void
*/
public function testValidatePathWithSymlink($path, $directoryConfig, $expectation)
{
$directory = $this->filesystem
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::PUB);
$driver = $directory->getDriver();
$mediaPath = $directory->getAbsolutePath('media');
$mediaMovedPath = $directory->getAbsolutePath('moved-media');
try {
$driver->rename($mediaPath, $mediaMovedPath);
$driver->symlink($mediaMovedPath, $mediaPath);
$this->testValidatePath($path, $directoryConfig, $expectation);
} finally {
// be defensive in case some operations failed
if ($driver->isExists($mediaPath) && $driver->isExists($mediaMovedPath)) {
$driver->deleteFile($mediaPath);
$driver->rename($mediaMovedPath, $mediaPath);
} elseif ($driver->isExists($mediaMovedPath)) {
$driver->rename($mediaMovedPath, $mediaPath);
}
}
}
/**
* @return array
*/
public function validatePathDataProvider()
{
return [
[
'/',
DirectoryList::MEDIA,
true,
],
[
'/../../pub/',
DirectoryList::MEDIA,
false,
],
];
}
}