-
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.
Merge pull request #6564 from magento-tsg/2.4-develop-sidecar-pr13
[Sidecar] Fixes for 2.4 (pr13)
- Loading branch information
Showing
10 changed files
with
635 additions
and
50 deletions.
There are no files selected for viewing
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
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
97 changes: 97 additions & 0 deletions
97
.../integration/testsuite/Magento/Catalog/Controller/Adminhtml/Category/Image/UploadTest.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,97 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Catalog\Controller\Adminhtml\Category\Image; | ||
|
||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\App\Request\Http as HttpRequest; | ||
use Magento\Framework\Filesystem; | ||
use Magento\Framework\Filesystem\Directory\WriteInterface; | ||
use Magento\Framework\Serialize\SerializerInterface; | ||
use Magento\TestFramework\TestCase\AbstractBackendController; | ||
|
||
/** | ||
* Test cases related to upload category image. | ||
* | ||
* @see \Magento\Catalog\Controller\Adminhtml\Category\Image\Upload | ||
* @magentoAppArea adminhtml | ||
* @magentoDbIsolation enabled | ||
*/ | ||
class UploadTest extends AbstractBackendController | ||
{ | ||
/** @var Filesystem */ | ||
private $filesystem; | ||
|
||
/** @var WriteInterface */ | ||
private $tmpDirectory; | ||
|
||
/** @var SerializerInterface */ | ||
private $json; | ||
|
||
/** @var string */ | ||
private $fileToRemove; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->filesystem = $this->_objectManager->get(Filesystem::class); | ||
$this->tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::TMP); | ||
$this->json = $this->_objectManager->get(SerializerInterface::class); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function tearDown(): void | ||
{ | ||
if (file_exists($this->fileToRemove)) { | ||
unlink($this->fileToRemove); | ||
} | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testWithNotAllowedFileExtension(): void | ||
{ | ||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST); | ||
$this->getRequest()->setPostValue('param_name', 'image'); | ||
$this->prepareFile('empty.csv'); | ||
$this->dispatch('backend/catalog/category_image/upload'); | ||
$responseBody = $this->json->unserialize($this->getResponse()->getBody()); | ||
$this->assertNotEmpty($responseBody['error']); | ||
$this->assertStringContainsString((string)__('File validation failed.'), $responseBody['error']); | ||
} | ||
|
||
/** | ||
* Prepare file | ||
* | ||
* @param string $fileName | ||
* @return void | ||
*/ | ||
private function prepareFile(string $fileName): void | ||
{ | ||
$this->tmpDirectory->create($this->tmpDirectory->getAbsolutePath()); | ||
$filePath = $this->tmpDirectory->getAbsolutePath($fileName); | ||
$this->fileToRemove = $filePath; | ||
$fixtureDir = realpath(__DIR__ . '/../../../../_files'); | ||
$this->tmpDirectory->getDriver()->copy($fixtureDir . DIRECTORY_SEPARATOR . $fileName, $filePath); | ||
$_FILES['image'] = [ | ||
'name' => $fileName, | ||
'type' => 'image', | ||
'tmp_name' => $filePath, | ||
'error' => 0, | ||
'size' => 12500, | ||
]; | ||
} | ||
} |
Oops, something went wrong.