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,48 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Cms\Controller\Adminhtml\Block;
use Magento\Framework\App\Request\Http;
use Magento\Framework\Message\MessageInterface;
use Magento\TestFramework\TestCase\AbstractBackendController;
/**
* @magentoAppArea adminhtml
*/
class CreateTest extends AbstractBackendController
{
/**
* Test create CMS block with invalid URL
*
* @return void
*/
public function testCreateBlockWithInvalidUrl(): void
{
$identifier = 'admin';
$reservedWords = 'admin, soap, rest, graphql, standard';
$sessionMessages = [sprintf(
'URL key &quot;%s&quot; matches a reserved endpoint name (%s). Use another URL key.',
$identifier,
$reservedWords
)];
$requestData = [
'title' => 'block title',
'identifier' => $identifier,
'content' => '',
'is_active' => 1,
];
$this->getRequest()->setMethod(Http::METHOD_POST);
$this->getRequest()->setPostValue($requestData);
$this->dispatch('backend/cms/block/save');
$this->assertSessionMessages(
self::equalTo($sessionMessages),
MessageInterface::TYPE_ERROR
);
}
}
@@ -0,0 +1,67 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Cms\Controller\Adminhtml\Block;
use Magento\Cms\Api\Data\BlockInterface;
use Magento\Cms\Api\GetBlockByIdentifierInterface;
use Magento\Framework\App\Request\Http;
use Magento\Framework\Message\MessageInterface;
use Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\TestCase\AbstractBackendController;
/**
* Checks that cms block can be successfully deleted
*
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
*/
class DeleteTest extends AbstractBackendController
{
/** @var GetBlockByIdentifierInterface */
private $getBlockByIdentifier;
/** @var StoreManagerInterface */
private $storeManager;
/** @var CollectionFactory */
private $collectionFactory;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->getBlockByIdentifier = $this->_objectManager->get(GetBlockByIdentifierInterface::class);
$this->storeManager = $this->_objectManager->get(StoreManagerInterface::class);
$this->collectionFactory = $this->_objectManager->get(CollectionFactory::class);
}
/**
* @magentoDataFixture Magento/Cms/_files/block_default_store.php
*
* @return void
*/
public function testDeleteBlock(): void
{
$defaultStoreId = (int)$this->storeManager->getStore('default')->getId();
$blockId = $this->getBlockByIdentifier->execute('default_store_block', $defaultStoreId)->getId();
$this->getRequest()->setMethod(Http::METHOD_POST)
->setParams(['block_id' => $blockId]);
$this->dispatch('backend/cms/block/delete');
$this->assertSessionMessages(
$this->containsEqual((string)__('You deleted the block.')),
MessageInterface::TYPE_SUCCESS
);
$this->assertRedirect($this->stringContains('cms/block/index'));
$collection = $this->collectionFactory->getReport('cms_block_listing_data_source');
$this->assertNull($collection->getItemByColumnValue(BlockInterface::IDENTIFIER, 'default_store_block'));
}
}
@@ -0,0 +1,69 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Cms\Controller\Adminhtml;
use Magento\TestFramework\TestCase\AbstractBackendController;
/**
* Testing seach in grid.
*
* @magentoAppArea adminhtml
* @magentoDataFixture Magento/Cms/Fixtures/page_list.php
*/
class FulltextGridSearchTest extends AbstractBackendController
{
/**
* Checks a fulltext grid search by CMS page title.
*
* @param string $query
* @param int $expectedRows
* @param array $expectedTitles
* @dataProvider queryDataProvider
*/
public function testSearchByTitle(string $query, int $expectedRows, array $expectedTitles)
{
$url = 'backend/mui/index/render/?namespace=cms_page_listing&search=' . $query;
$this->getRequest()
->getHeaders()
->addHeaderLine('Accept', 'application/json');
$this->dispatch($url);
$response = $this->getResponse();
$data = json_decode($response->getBody(), true);
self::assertEquals($expectedRows, $data['totalRecords']);
$titleList = array_column($data['items'], 'title');
self::assertEquals($expectedTitles, $titleList);
}
/**
* Gets list of variations with different search queries.
*
* @return array
*/
public function queryDataProvider(): array
{
return [
[
'query' => 'simple',
'expectedRows' => 3,
'expectedTitles' => ['simplePage', 'simplePage01', '01simplePage']
],
[
'query' => 'page01',
'expectedRows' => 1,
'expectedTitles' => ['simplePage01']
],
[
'query' => '01simple',
'expectedRows' => 1,
'expectedTitles' => ['01simplePage']
],
];
}
}
@@ -0,0 +1,336 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Cms\Controller\Adminhtml;
use Magento\Cms\Api\Data\PageInterface;
use Magento\Cms\Api\GetPageByIdentifierInterface;
use Magento\Cms\Controller\Adminhtml\Page\PostDataProcessor;
use Magento\Cms\Model\Page;
use Magento\Cms\Model\Page\CustomLayout\CustomLayoutManager;
use Magento\Cms\Model\Page\CustomLayoutManagerInterface;
use Magento\Framework\Acl\Builder;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Request\Http as HttpRequest;
use Magento\Framework\Message\MessageInterface;
use Magento\TestFramework\Bootstrap;
use Magento\TestFramework\Helper\Bootstrap as BootstrapHelper;
use Magento\TestFramework\TestCase\AbstractBackendController;
use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection;
use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollectionFactory;
use Magento\UrlRewrite\Model\UrlRewrite;
/**
* Test the saving CMS pages design via admin area interface.
*
* @magentoAppArea adminhtml
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PageDesignTest extends AbstractBackendController
{
/**
* @var string
*/
protected $resource = 'Magento_Cms::save';
/**
* @var string
*/
protected $uri = 'backend/cms/page/save';
/**
* @var string
*/
protected $httpMethod = HttpRequest::METHOD_POST;
/**
* @var Builder
*/
private $aclBuilder;
/**
* @var GetPageByIdentifierInterface
*/
private $pageRetriever;
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var string[]
*/
private $pagesToDelete = [];
/**
* @var PostDataProcessor
*/
private $postDataProcessor;
/**
* @inheritDoc
*/
protected function setUp(): void
{
BootstrapHelper::getObjectManager()->configure([
'preferences' => [
CustomLayoutManagerInterface::class => CustomLayoutManager::class
]
]);
parent::setUp();
$this->aclBuilder = BootstrapHelper::getObjectManager()->get(Builder::class);
$this->pageRetriever = BootstrapHelper::getObjectManager()->get(GetPageByIdentifierInterface::class);
$this->scopeConfig = BootstrapHelper::getObjectManager()->get(ScopeConfigInterface::class);
$this->pagesToDelete = [];
$this->postDataProcessor = BootstrapHelper::getObjectManager()->get(PostDataProcessor::class);
}
/**
* @inheritDoc
*/
protected function tearDown(): void
{
parent::tearDown();
$pageIds = [];
foreach ($this->pagesToDelete as $identifier) {
$pageIds[] = $identifier;
$page = $this->pageRetriever->execute($identifier, 0);
$page->delete();
}
$this->removeUrlRewrites();
}
/**
* Removes url rewrites created during test execution.
*
* @return void
*/
private function removeUrlRewrites(): void
{
if (!empty($this->pagesToDelete)) {
$urlRewriteCollectionFactory = BootstrapHelper::getObjectManager()->get(
UrlRewriteCollectionFactory::class
);
/** @var UrlRewriteCollection $urlRewriteCollection */
$urlRewriteCollection = $urlRewriteCollectionFactory->create();
$urlRewriteCollection->addFieldToFilter('request_path', ['in' => $this->pagesToDelete]);
$urlRewrites = $urlRewriteCollection->getItems();
/** @var UrlRewrite $urlRewrite */
foreach ($urlRewrites as $urlRewrite) {
try {
$urlRewrite->delete();
} catch (\Exception $exception) {
// already removed
}
}
}
}
/**
* Check whether additional authorization is required for the design fields.
*
* @magentoDbIsolation disabled
* @return void
*/
public function testSaveDesign(): void
{
//Expected list of sessions messages collected throughout the controller calls.
$sessionMessages = ['You are not allowed to change CMS pages design settings'];
//Test page data.
$id = 'test-page' .rand(1111, 9999);
$requestData = [
PageInterface::IDENTIFIER => $id,
PageInterface::TITLE => 'Page title',
PageInterface::CUSTOM_THEME => '1',
PageInterface::PAGE_LAYOUT => 'empty'
];
//Creating a new page with design properties without the required permissions.
$this->aclBuilder->getAcl()->deny(
Bootstrap::ADMIN_ROLE_ID,
'Magento_Cms::save_design'
);
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
$this->getRequest()->setPostValue($requestData);
$this->dispatch($this->uri);
$this->assertSessionMessages(
self::equalTo($sessionMessages),
MessageInterface::TYPE_ERROR
);
//Trying again with the permissions.
$this->aclBuilder->getAcl()->allow(
Bootstrap::ADMIN_ROLE_ID,
['Magento_Cms::save', 'Magento_Cms::save_design']
);
$this->getRequest()->setDispatched(false);
$this->dispatch($this->uri);
/** @var Page $page */
$page = BootstrapHelper::getObjectManager()->create(PageInterface::class);
$page->load($id, PageInterface::IDENTIFIER);
$this->assertNotEmpty($page->getId());
$this->assertEquals(1, $page->getCustomTheme());
$requestData['page_id'] = $page->getId();
$this->getRequest()->setPostValue($requestData);
//Updating the page without the permissions but not touching design settings.
$this->aclBuilder->getAcl()->deny(
Bootstrap::ADMIN_ROLE_ID,
'Magento_Cms::save_design'
);
$this->getRequest()->setDispatched(false);
$this->dispatch($this->uri);
$this->assertSessionMessages(self::equalTo($sessionMessages), MessageInterface::TYPE_ERROR);
//Updating design settings without the permissions.
$requestData[PageInterface::CUSTOM_THEME] = '2';
$this->getRequest()->setPostValue($requestData);
$this->getRequest()->setDispatched(false);
$this->dispatch($this->uri);
$sessionMessages[] = $sessionMessages[0];
$this->assertSessionMessages(
self::equalTo($sessionMessages),
MessageInterface::TYPE_ERROR
);
$this->pagesToDelete = [$id];
}
/**
* Check that default design values are accepted without the permissions.
*
* @magentoDbIsolation disabled
* @return void
*/
public function testSaveDesignWithDefaults(): void
{
//Test page data.
$id = 'test-page' .rand(1111, 9999);
$defaultLayout = $this->scopeConfig->getValue('web/default_layouts/default_cms_layout');
$requestData = [
PageInterface::IDENTIFIER => $id,
PageInterface::TITLE => 'Page title',
PageInterface::PAGE_LAYOUT => $defaultLayout
];
//Creating a new page with design properties without the required permissions but with default values.
$this->aclBuilder->getAcl()->deny(
Bootstrap::ADMIN_ROLE_ID,
'Magento_Cms::save_design'
);
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
$this->getRequest()->setPostValue($requestData);
$this->dispatch($this->uri);
//Validating saved page
/** @var Page $page */
$page = BootstrapHelper::getObjectManager()->create(PageInterface::class);
$page->load($id, PageInterface::IDENTIFIER);
$this->assertNotEmpty($page->getId());
$this->assertNotNull($page->getPageLayout());
$this->assertEquals($defaultLayout, $page->getPageLayout());
$this->pagesToDelete = [$id];
}
/**
* Test that custom layout update fields are dealt with properly.
*
* @magentoDataFixture Magento/Cms/_files/pages_with_layout_xml.php
* @throws \Throwable
* @return void
*/
public function testSaveLayoutXml(): void
{
$page = $this->pageRetriever->execute('test_custom_layout_page_1', 0);
$requestData = [
Page::PAGE_ID => $page->getId(),
PageInterface::IDENTIFIER => 'test_custom_layout_page_1',
PageInterface::TITLE => 'Page title',
PageInterface::CUSTOM_LAYOUT_UPDATE_XML => $page->getCustomLayoutUpdateXml(),
PageInterface::LAYOUT_UPDATE_XML => $page->getLayoutUpdateXml(),
'layout_update_selected' => '_existing_'
];
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
$this->getRequest()->setPostValue($requestData);
$this->dispatch($this->uri);
$this->getRequest()->setDispatched(false);
$updated = $this->pageRetriever->execute('test_custom_layout_page_1', 0);
$this->assertEquals($updated->getCustomLayoutUpdateXml(), $page->getCustomLayoutUpdateXml());
$this->assertEquals($updated->getLayoutUpdateXml(), $page->getLayoutUpdateXml());
$requestData = [
Page::PAGE_ID => $page->getId(),
PageInterface::IDENTIFIER => 'test_custom_layout_page_1',
PageInterface::TITLE => 'Page title',
PageInterface::CUSTOM_LAYOUT_UPDATE_XML => $page->getCustomLayoutUpdateXml(),
PageInterface::LAYOUT_UPDATE_XML => $page->getLayoutUpdateXml(),
'layout_update_selected' => '_no_update_'
];
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
$this->getRequest()->setPostValue($requestData);
$this->dispatch($this->uri);
$this->getRequest()->setDispatched(false);
$updated = $this->pageRetriever->execute('test_custom_layout_page_1', 0);
$this->assertEmpty($updated->getCustomLayoutUpdateXml());
$this->assertEmpty($updated->getLayoutUpdateXml());
$this->pagesToDelete = ['test_custom_layout_page_1'];
}
/**
* Test create CMS page with invalid URL
*
* @return void
*/
public function testSaveWithInlavidIdentifier(): void
{
$identifier = 'admin';
$reservedWords = 'admin, soap, rest, graphql, standard';
//Expected list of sessions messages collected throughout the controller calls.
$sessionMessages = [sprintf(
'URL key "%s" matches a reserved endpoint name (%s). Use another URL key.',
$identifier,
$reservedWords
)];
$requestData = [
PageInterface::IDENTIFIER => $identifier,
PageInterface::TITLE => 'page title',
PageInterface::CUSTOM_THEME => '1',
PageInterface::PAGE_LAYOUT => 'empty',
];
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
$this->getRequest()->setPostValue($requestData);
$this->dispatch($this->uri);
$this->assertSessionMessages(
self::equalTo($sessionMessages),
MessageInterface::TYPE_ERROR
);
}
/**
* Test create CMS page with invalid layout update
*
* @return void
*/
public function testSaveWithCustomLayoutUpdate(): void
{
$requestData = [
PageInterface::IDENTIFIER => 'randomidentified',
PageInterface::TITLE => 'page title',
PageInterface::CUSTOM_THEME => '1',
PageInterface::PAGE_LAYOUT => 'empty',
PageInterface::CUSTOM_LAYOUT_UPDATE_XML => '<container />',
PageInterface::LAYOUT_UPDATE_XML => '<container />',
];
$this->assertFalse($this->postDataProcessor->validate($requestData));
}
}
@@ -0,0 +1,286 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem\Directory\DenyListPathValidator;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\Framework\Filesystem\Driver\File;
use Magento\RemoteStorage\Driver\DriverPool;
use Magento\RemoteStorage\Model\Filesystem\Directory\WriteFactory;
/**
* Test for \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles class.
*
* @magentoAppArea adminhtml
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class DeleteFilesTest extends \PHPUnit\Framework\TestCase
{
private const MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH
= 'system/media_storage_configuration/allowed_resources/media_gallery_image_folders';
/**
* @var array
*/
private $origConfigValue;
/**
* @var \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles
*/
private $model;
/**
* @var \Magento\Cms\Helper\Wysiwyg\Images
*/
private $imagesHelper;
/**
* @var WriteInterface
*/
private $mediaDirectory;
/**
* @var string
*/
private $fullDirectoryPath;
/**
* @var string
*/
private $fileName = 'magento_small_image.jpg';
/**
* @var \Magento\Framework\Filesystem
*/
private $filesystem;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var DirectoryList
*/
private $directoryList;
/**
* @var WriteInterface
*/
private $bypassDenyListWrite;
/**
* @inheritdoc
* @throws FileSystemException
*/
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$directoryName = 'testDir';
$this->directoryList = $this->objectManager->get(DirectoryList::class);
$this->filesystem = $this->objectManager->get(\Magento\Framework\Filesystem::class);
/** @var \Magento\Cms\Helper\Wysiwyg\Images $imagesHelper */
$this->imagesHelper = $this->objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$this->fullDirectoryPath = $this->imagesHelper->getStorageRoot() . $directoryName;
$this->mediaDirectory->create($this->mediaDirectory->getRelativePath($this->fullDirectoryPath));
$filePath = $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName;
$fixtureDir = realpath(__DIR__ . '/../../../../../Catalog/_files');
$this->copyFile($fixtureDir . '/' . $this->fileName, $filePath);
$this->model = $this->objectManager->get(\Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::class);
$config = $this->objectManager->get(ScopeConfigInterface::class);
$this->origConfigValue = $config->getValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
'default'
);
$scopeConfig = $this->objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
$scopeConfig->setValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
array_merge($this->origConfigValue, ['testDir']),
);
}
protected function tearDown(): void
{
$this->mediaDirectory->delete($this->mediaDirectory->getRelativePath($this->fullDirectoryPath));
$this->mediaDirectory->delete('secondDir');
$scopeConfig = $this->objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
$scopeConfig->setValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
$this->origConfigValue
);
}
/**
* Execute method with correct directory path and file name to check that files under WYSIWYG media directory
* can be removed.
*
* @param string $filename
* @return void
* @dataProvider executeDataProvider
*/
public function testExecute(string $filename)
{
$filePath = $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $filename;
$fixtureDir = realpath(__DIR__ . '/../../../../../Catalog/_files');
$this->copyFile($fixtureDir . '/' . $this->fileName, $filePath);
$this->model->getRequest()->setMethod('POST')
->setPostValue('files', [$this->imagesHelper->idEncode($filename)]);
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
$this->model->execute();
$this->assertFalse(
$this->mediaDirectory->isExist(
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . '/' . $filename)
)
);
}
/**
* DataProvider for testExecute
*
* @return array
*/
public function executeDataProvider(): array
{
return [
['name with spaces.jpg'],
['name with, comma.jpg'],
['name with* asterisk.jpg'],
['name with[ bracket.jpg'],
['magento_small_image.jpg'],
['_.jpg'],
[' - .jpg'],
['-.jpg'],
];
}
/**
* Check that htaccess file couldn't be removed via
* \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
*
* @return void
*/
public function testDeleteHtaccess()
{
$testDir = $this->imagesHelper->getStorageRoot() . "directory1";
$this->mediaDirectory->create($this->mediaDirectory->getRelativePath($testDir));
$path = $testDir . '/.htaccess';
$denyListPathValidator = $this->objectManager
->create(DenyListPathValidator::class, ['driver' => $this->mediaDirectory->getDriver()]);
$denyListPathValidator->addException($path);
$bypassDenyListWriteFactory = $this->objectManager->create(WriteFactory::class, [
'denyListPathValidator' => $denyListPathValidator
]);
$this->bypassDenyListWrite = $bypassDenyListWriteFactory->create(
$this->mediaDirectory->getAbsolutePath(),
$this->mediaDirectory->getDriver() instanceof File ? DriverPool::FILE : DriverPool::REMOTE,
null,
DirectoryList::MEDIA
);
if (!$this->bypassDenyListWrite->isFile($path)) {
$this->bypassDenyListWrite->writeFile($path, "Order deny,allow\nDeny from all");
}
$this->model->getRequest()->setMethod('POST')
->setPostValue('files', [$this->imagesHelper->idEncode('.htaccess')]);
$this->model->getStorage()->getSession()->setCurrentPath($testDir);
$this->model->execute();
$this->assertTrue(
$this->bypassDenyListWrite->isExist(
$this->bypassDenyListWrite->getRelativePath($testDir . '/' . '.htaccess')
)
);
$this->bypassDenyListWrite->delete($testDir);
}
/**
* Execute method with traversal file path to check that there is no ability to remove file which is not
* under media directory.
*
* @return void
*/
public function testExecuteWithWrongFileName()
{
$fixtureDir = realpath(__DIR__ . '/../../../../../Catalog/_files');
$this->mediaDirectory->create('secondDir');
$driver = $this->mediaDirectory->getDriver();
$driver->filePutContents(
$this->mediaDirectory->getAbsolutePath('secondDir' . DIRECTORY_SEPARATOR . $this->fileName),
file_get_contents($fixtureDir . '/' . $this->fileName)
);
$fileName = '/../secondDir/' . $this->fileName;
$this->model->getRequest()->setMethod('POST')
->setPostValue('files', [$this->imagesHelper->idEncode($fileName)]);
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
$this->model->execute();
$this->assertTrue($this->mediaDirectory->isExist($this->fullDirectoryPath . $fileName));
}
/**
* Execute method with correct directory path and file name to check that files under linked media directory
* can be removed.
*
* @return void
* @magentoDataFixture Magento/Cms/_files/linked_media.php
*/
public function testExecuteWithLinkedMedia()
{
if (!$this->mediaDirectory->getDriver() instanceof File) {
self::markTestSkipped('Remote storages like AWS S3 doesn\'t support symlinks');
}
$directoryName = 'linked_media';
$fullDirectoryPath = $this->filesystem->getDirectoryRead(DirectoryList::PUB)
->getAbsolutePath() . DIRECTORY_SEPARATOR . $directoryName;
$filePath = $fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName;
$fixtureDir = realpath(__DIR__ . '/../../../../../Catalog/_files');
$this->copyFile($fixtureDir . '/' . $this->fileName, $filePath);
$wysiwygDir = $this->mediaDirectory->getAbsolutePath() . '/wysiwyg';
$this->model->getRequest()->setMethod('POST')
->setPostValue('files', [$this->imagesHelper->idEncode($this->fileName)]);
$this->model->getStorage()->getSession()->setCurrentPath($wysiwygDir);
$this->model->execute();
$this->assertFalse(is_file($fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName));
}
/**
* @inheritdoc
*/
public static function tearDownAfterClass(): void
{
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Framework\Filesystem::class);
/** @var WriteInterface $directory */
$directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
if ($directory->isExist('wysiwyg')) {
$directory->delete('wysiwyg');
}
}
/**
* @param string $source
* @param string $destination
* @throws FileSystemException
*/
private function copyFile(string $source, string $destination)
{
$driver = $this->mediaDirectory->getDriver();
$driver->createDirectory(dirname($destination));
$driver->filePutContents($destination, file_get_contents($source));
}
}
@@ -0,0 +1,213 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\Response\HttpFactory as ResponseFactory;
use Magento\Framework\Filesystem\Driver\File;
/**
* Test for \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFolder class.
*
* @magentoAppArea adminhtml
*/
class DeleteFolderTest extends \PHPUnit\Framework\TestCase
{
private const MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH
= 'system/media_storage_configuration/allowed_resources/media_gallery_image_folders';
/**
* @var array
*/
private $origConfigValue;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFolder
*/
private $model;
/**
* @var \Magento\Cms\Helper\Wysiwyg\Images
*/
private $imagesHelper;
/**
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
*/
private $mediaDirectory;
/**
* @var string
*/
private $fullDirectoryPath;
/**
* @var \Magento\Framework\Filesystem
*/
private $filesystem;
/**
* @var HttpFactory
*/
private $responseFactory;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->filesystem = $this->objectManager->get(\Magento\Framework\Filesystem::class);
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
/** @var \Magento\Cms\Helper\Wysiwyg\Images $imagesHelper */
$this->imagesHelper = $this->objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
$this->fullDirectoryPath = $this->imagesHelper->getStorageRoot();
$this->mediaDirectory->create($this->mediaDirectory->getRelativePath($this->fullDirectoryPath));
$this->responseFactory = $this->objectManager->get(ResponseFactory::class);
$this->model = $this->objectManager->get(\Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFolder::class);
$config = $this->objectManager->get(ScopeConfigInterface::class);
$this->origConfigValue = $config->getValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
'default'
);
$scopeConfig = $this->objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
$scopeConfig->setValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
array_merge($this->origConfigValue, ['testDir']),
);
}
protected function tearDown(): void
{
$directoryName = 'testDir';
$this->mediaDirectory->delete(
$this->mediaDirectory->getRelativePath($this->imagesHelper->getStorageRoot() . '/' . $directoryName)
);
$this->mediaDirectory->delete('secondDir');
$scopeConfig = $this->objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
$scopeConfig->setValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
$this->origConfigValue
);
}
/**
* Execute method with correct directory path to check that directories under WYSIWYG media directory
* can be removed.
*
* @return void
* @magentoAppIsolation enabled
*/
public function testExecute()
{
$directoryName = 'testDir/NewDirectory';
$path = $this->mediaDirectory->getRelativePath($this->fullDirectoryPath . $directoryName);
$this->mediaDirectory->create($path);
$this->model->getRequest()->setParams(['node' => $this->imagesHelper->idEncode($path)]);
$this->model->getRequest()->setMethod('POST');
$this->model->execute();
$this->assertFalse($this->mediaDirectory->isExist($path));
}
/**
* Execute method with correct directory path to check that directories under linked media directory
* can be removed.
*
* @magentoDataFixture Magento/Cms/_files/linked_media.php
* @magentoAppIsolation enabled
*/
public function testExecuteWithLinkedMedia()
{
if (!$this->mediaDirectory->getDriver() instanceof File) {
self::markTestSkipped('Remote storages like AWS S3 doesn\'t support symlinks');
}
$linkedDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::PUB);
$linkedDirectoryPath = $this->filesystem->getDirectoryRead(DirectoryList::PUB)
->getAbsolutePath() . 'linked_media';
$directoryName = 'NewDirectory';
$linkedDirectory->create(
$linkedDirectory->getRelativePath($linkedDirectoryPath . DIRECTORY_SEPARATOR . $directoryName)
);
$this->model->getRequest()->setParams(
['node' => $this->imagesHelper->idEncode('wysiwyg' . DIRECTORY_SEPARATOR . $directoryName)]
);
$this->model->execute();
$this->assertFalse(is_dir($linkedDirectoryPath . DIRECTORY_SEPARATOR . $directoryName));
}
/**
* Execute method with traversal directory path to check that there is no ability to remove folder which is not
* under media directory.
*
* @return void
* @magentoAppIsolation enabled
*/
public function testExecuteWithWrongDirectoryName()
{
$secondDir = $this->mediaDirectory->getRelativePath($this->fullDirectoryPath . 'secondDir');
$this->mediaDirectory->create($secondDir);
$testDir = $this->mediaDirectory->getRelativePath($this->fullDirectoryPath . 'testDir');
$this->mediaDirectory->create($testDir);
$directoryName = 'testDir/../secondDir/';
$this->assertTrue($this->mediaDirectory->isExist($this->fullDirectoryPath . $directoryName));
$this->model->getRequest()->setParams(['node' => $this->imagesHelper->idEncode($directoryName)]);
$this->model->execute();
$this->assertTrue($this->mediaDirectory->isExist($this->fullDirectoryPath . $directoryName));
}
/**
* Execute method to check that there is no ability to remove folder which is in excluded directories list.
*
* @return void
* @magentoAppIsolation enabled
*/
public function testExecuteWithExcludedDirectoryName()
{
$directoryName = 'downloadable';
$expectedResponseMessage = 'We cannot delete the selected directory.';
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$mediaDirectory->create($directoryName);
$this->assertTrue($this->mediaDirectory->isExist($this->fullDirectoryPath . $directoryName));
$this->model->getRequest()->setParams(['node' => $this->imagesHelper->idEncode($directoryName)]);
$this->model->getRequest()->setMethod('POST');
$jsonResponse = $this->model->execute();
$jsonResponse->renderResult($response = $this->responseFactory->create());
$data = json_decode($response->getBody(), true);
$this->assertTrue($data['error']);
$this->assertEquals($expectedResponseMessage, $data['message']);
$this->assertTrue($this->mediaDirectory->isExist($this->fullDirectoryPath . $directoryName));
}
/**
* @inheritdoc
*/
public static function tearDownAfterClass(): void
{
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Framework\Filesystem::class);
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */
$directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
if ($directory->isExist('wysiwyg')) {
$directory->delete('wysiwyg');
}
if ($directory->isExist('downloadable')) {
$directory->delete('downloadable');
}
}
}
@@ -0,0 +1,19 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
{
public function testViewAction()
{
$this->dispatch('backend/cms/wysiwyg_images/index/target_element_id/page_content/store/undefined/type/image/');
$content = $this->getResponse()->getBody();
$this->assertStringNotContainsString('<html', $content);
$this->assertStringNotContainsString('<head', $content);
$this->assertStringNotContainsString('<body', $content);
}
}
@@ -0,0 +1,174 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem\Driver\File;
/**
* Test for \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\NewFolder class.
*
* @magentoAppArea adminhtml
*/
class NewFolderTest extends \PHPUnit\Framework\TestCase
{
private const MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH
= 'system/media_storage_configuration/allowed_resources/media_gallery_image_folders';
/**
* @var array
*/
private $origConfigValue;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\NewFolder
*/
private $model;
/**
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
*/
private $mediaDirectory;
/**
* @var string
*/
private $fullDirectoryPath;
/**
* @var string
*/
private $dirName= 'NewDirectory';
/**
* @var \Magento\Framework\Filesystem
*/
private $filesystem;
/**
* @var \Magento\Cms\Helper\Wysiwyg\Images
*/
private $imagesHelper;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->filesystem = $this->objectManager->get(\Magento\Framework\Filesystem::class);
/** @var \Magento\Cms\Helper\Wysiwyg\Images $imagesHelper */
$this->imagesHelper = $this->objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$this->fullDirectoryPath = $this->imagesHelper->getStorageRoot() . '/testDir';
$this->mediaDirectory->create($this->mediaDirectory->getRelativePath($this->fullDirectoryPath));
$this->model = $this->objectManager->get(\Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\NewFolder::class);
$config = $this->objectManager->get(ScopeConfigInterface::class);
$this->origConfigValue = $config->getValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
'default'
);
$scopeConfig = $this->objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
$scopeConfig->setValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
array_merge($this->origConfigValue, ['testDir']),
);
}
protected function tearDown(): void
{
$this->mediaDirectory->delete($this->mediaDirectory->getRelativePath($this->fullDirectoryPath));
$scopeConfig = $this->objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
$scopeConfig->setValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
$this->origConfigValue
);
}
/**
* Execute method with correct directory path to check that new folder can be created under WYSIWYG media directory.
*
* @return void
*/
public function testExecute()
{
$this->model->getRequest()->setMethod('POST')
->setPostValue('name', $this->dirName);
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
$this->model->execute();
$this->assertTrue(
$this->mediaDirectory->isExist(
$this->mediaDirectory->getRelativePath(
$this->fullDirectoryPath . DIRECTORY_SEPARATOR . $this->dirName
)
)
);
}
/**
* Execute method with correct directory path to check that new folder can be created under WYSIWYG media directory.
*
* @magentoDataFixture Magento/Cms/_files/linked_media.php
*/
public function testExecuteWithLinkedMedia()
{
if (!$this->mediaDirectory->getDriver() instanceof File) {
self::markTestSkipped('Remote storages like AWS S3 doesn\'t support symlinks');
}
$linkedDirectoryPath = $this->filesystem->getDirectoryRead(DirectoryList::PUB)
->getAbsolutePath() . 'linked_media';
$this->model->getRequest()->setMethod('POST')
->setPostValue('name', $this->dirName);
$this->model->getStorage()
->getSession()
->setCurrentPath($this->imagesHelper->getStorageRoot() . DIRECTORY_SEPARATOR . 'wysiwyg');
$this->model->execute();
$this->assertTrue(is_dir($linkedDirectoryPath . DIRECTORY_SEPARATOR . $this->dirName));
}
/**
* Execute method with traversal directory path to check that there is no ability to create new folder not
* under media directory.
*
* @return void
*/
public function testExecuteWithWrongPath()
{
$dirPath = '/../../../';
$this->model->getRequest()->setMethod('POST')
->setPostValue('name', $this->dirName);
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath . $dirPath);
$this->model->execute();
$this->assertFileDoesNotExist(
$this->fullDirectoryPath . $dirPath . $this->dirName
);
}
/**
* @inheritdoc
*/
public static function tearDownAfterClass(): void
{
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Framework\Filesystem::class);
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */
$directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
if ($directory->isExist('wysiwyg')) {
$directory->delete('wysiwyg');
}
}
}
@@ -0,0 +1,267 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Controller\Result\Json as JsonResponse;
use Magento\Framework\App\Response\HttpFactory as ResponseFactory;
use Magento\Framework\App\Response\Http as Response;
use Magento\Framework\Filesystem\Driver\File;
/**
* Test for \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\Upload class.
*
* @magentoAppArea adminhtml
*/
class UploadTest extends \PHPUnit\Framework\TestCase
{
private const MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH
= 'system/media_storage_configuration/allowed_resources/media_gallery_image_folders';
/**
* @var array
*/
private $origConfigValue;
/**
* @var \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\Upload
*/
private $model;
/**
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
*/
private $mediaDirectory;
/**
* @var string
*/
private $fullDirectoryPath;
/**
* @var string
*/
private $fullExcludedDirectoryPath;
/**
* @var string
*/
private $fileName = 'magento_small_image.jpg';
/**
* @var \Magento\Framework\Filesystem
*/
private $filesystem;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var HttpFactory
*/
private $responseFactory;
/**
* @var \Magento\Cms\Helper\Wysiwyg\Images
*/
private $imagesHelper;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$directoryName = 'testDir';
$excludedDirName = 'downloadable';
$this->filesystem = $this->objectManager->get(\Magento\Framework\Filesystem::class);
/** @var \Magento\Cms\Helper\Wysiwyg\Images $imagesHelper */
$this->imagesHelper = $this->objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$this->fullDirectoryPath = rtrim($this->imagesHelper->getStorageRoot(), '/')
. DIRECTORY_SEPARATOR . $directoryName;
$this->fullExcludedDirectoryPath = $this->imagesHelper->getStorageRoot()
. DIRECTORY_SEPARATOR . $excludedDirName;
$this->mediaDirectory->create($this->mediaDirectory->getRelativePath($this->fullDirectoryPath));
$this->responseFactory = $this->objectManager->get(ResponseFactory::class);
$this->model = $this->objectManager->get(\Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\Upload::class);
$fixtureDir = realpath(__DIR__ . '/../../../../../Catalog/_files');
$tmpFile = $this->filesystem->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath() . $this->fileName;
copy($fixtureDir . DIRECTORY_SEPARATOR . $this->fileName, $tmpFile);
$_FILES = [
'image' => [
'name' => $this->fileName,
'type' => 'image/png',
'tmp_name' => $tmpFile,
'error' => 0,
'size' => filesize($fixtureDir),
],
];
$config = $this->objectManager->get(ScopeConfigInterface::class);
$this->origConfigValue = $config->getValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
'default'
);
$scopeConfig = $this->objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
$scopeConfig->setValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
array_merge($this->origConfigValue, ['testDir']),
);
}
protected function tearDown(): void
{
$directoryName = 'testDir';
$this->mediaDirectory->delete(
$this->mediaDirectory->getRelativePath($this->imagesHelper->getStorageRoot() . '/' . $directoryName)
);
$scopeConfig = $this->objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class);
$scopeConfig->setValue(
self::MEDIA_GALLERY_IMAGE_FOLDERS_CONFIG_PATH,
$this->origConfigValue
);
}
/**
* Execute method with correct directory path and file name to check that file can be uploaded to the directory
* located under WYSIWYG media.
*
* @return void
* @magentoAppIsolation enabled
*/
public function testExecute()
{
$this->model->getRequest()->setParams(['type' => 'image/png']);
$this->model->getRequest()->setMethod('POST');
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
/** @var JsonResponse $jsonResponse */
$jsonResponse = $this->model->execute();
/** @var Response $response */
$jsonResponse->renderResult($response = $this->responseFactory->create());
$data = json_decode($response->getBody(), true);
$this->assertTrue(
$this->mediaDirectory->isExist(
$this->mediaDirectory->getRelativePath(
$this->fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName
)
)
);
//Asserting that response contains only data needed by clients.
$keys = ['name', 'type', 'error', 'size', 'file'];
sort($keys);
$dataKeys = array_keys($data);
sort($dataKeys);
$this->assertEquals($keys, $dataKeys);
}
/**
* Execute method with excluded directory path and file name to check that file can't be uploaded.
*
* @return void
* @magentoAppIsolation enabled
*/
public function testExecuteWithExcludedDirectory()
{
$expectedError = 'We can\'t upload the file to the current folder right now. Please try another folder.';
$this->model->getRequest()->setParams(['type' => 'image/png']);
$this->model->getRequest()->setMethod('POST');
$this->model->getStorage()->getSession()->setCurrentPath($this->fullExcludedDirectoryPath);
/** @var JsonResponse $jsonResponse */
$jsonResponse = $this->model->execute();
/** @var Response $response */
$jsonResponse->renderResult($response = $this->responseFactory->create());
$data = json_decode($response->getBody(), true);
$this->assertEquals($expectedError, $data['error']);
$this->assertFalse(
$this->mediaDirectory->isExist(
$this->mediaDirectory->getRelativePath(
$this->fullExcludedDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName
)
)
);
}
/**
* Execute method with correct directory path and file name to check that file can be uploaded to the directory
* located under linked folder.
*
* @return void
* @magentoDataFixture Magento/Cms/_files/linked_media.php
*/
public function testExecuteWithLinkedMedia()
{
if (!$this->mediaDirectory->getDriver() instanceof File) {
self::markTestSkipped('Remote storages like AWS S3 doesn\'t support symlinks');
}
$directoryName = 'linked_media';
$fullDirectoryPath = $this->filesystem->getDirectoryRead(DirectoryList::PUB)
->getAbsolutePath() . $directoryName;
$wysiwygDir = $this->mediaDirectory->getAbsolutePath() . '/wysiwyg';
$this->model->getRequest()->setParams(['type' => 'image/png']);
$this->model->getStorage()->getSession()->setCurrentPath($wysiwygDir);
$this->model->execute();
$this->assertTrue(is_file($fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName));
}
/**
* Execute method with traversal directory path to check that there is no ability to create file not
* under media directory.
*
* @return void
*/
public function testExecuteWithWrongPath()
{
$dirPath = '/../../../etc/';
$this->model->getRequest()->setParams(['type' => 'image/png']);
$this->model->getStorage()->getSession()->setCurrentPath($dirPath);
$this->model->execute();
$this->assertFileDoesNotExist(
$this->fullDirectoryPath . $dirPath . $this->fileName
);
}
/**
* Execute method with traversal file path to check that there is no ability to create file not
* under media directory.
*
* @return void
*/
public function testExecuteWithWrongFileName()
{
$newFilename = '/../../../../etc/new_file.png';
$_FILES['image']['name'] = $newFilename;
$_FILES['image']['tmp_name'] = __DIR__ . DIRECTORY_SEPARATOR . $this->fileName;
$this->model->getRequest()->setParams(['type' => 'image/png']);
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
$this->model->execute();
$this->assertFileDoesNotExist($this->fullDirectoryPath . $newFilename);
}
/**
* @inheritdoc
*/
public static function tearDownAfterClass(): void
{
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Framework\Filesystem::class);
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $directory */
$directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
if ($directory->isExist('wysiwyg')) {
$directory->delete('wysiwyg');
}
}
}