Skip to content

Commit c455c1e

Browse files
committed
MAGETWO-88645: Error while deleting a Product Image
1 parent 4817632 commit c455c1e

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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\Catalog\Model\Product\Gallery;
10+
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Framework\Filesystem;
13+
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\ObjectManagerInterface;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use Magento\Framework\Filesystem\Directory\WriteInterface;
17+
18+
/**
19+
* Test for \Magento\Catalog\Model\Product\Gallery\UpdateHandler.
20+
*
21+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
22+
*/
23+
class UpdateHandlerTest extends \PHPUnit\Framework\TestCase
24+
{
25+
/**
26+
* @var ObjectManagerInterface
27+
*/
28+
private $objectManager;
29+
30+
/**
31+
* @var UpdateHandler
32+
*/
33+
private $updateHandler;
34+
35+
/**
36+
* @var WriteInterface
37+
*/
38+
private $rootDirectory;
39+
40+
/**
41+
* @var Filesystem
42+
*/
43+
private $filesystem;
44+
45+
/**
46+
* @var string
47+
*/
48+
private $fileName;
49+
50+
/**
51+
* @inheritdoc
52+
*/
53+
protected function setUp()
54+
{
55+
$this->fileName = 'test.txt';
56+
57+
$this->objectManager = Bootstrap::getObjectManager();
58+
$this->updateHandler = $this->objectManager->create(UpdateHandler::class);
59+
$this->filesystem = $this->objectManager->get(Filesystem::class);
60+
$this->rootDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
61+
62+
$filePath = $this->rootDirectory->getAbsolutePath($this->fileName);
63+
$file = fopen($filePath, "wb");
64+
fwrite($file, 'Test');
65+
}
66+
67+
/**
68+
* @return void
69+
*/
70+
public function testExecuteWithIllegalFilename(): void
71+
{
72+
$filePath = str_repeat('/..', 9) . '/' . $this->fileName;
73+
74+
/** @var $product Product */
75+
$product = Bootstrap::getObjectManager()->create(Product::class);
76+
$product->load(1);
77+
$product->setData(
78+
'media_gallery',
79+
[
80+
'images' => [
81+
'image' => [
82+
'value_id' => '100',
83+
'file' => $filePath,
84+
'label' => 'New image',
85+
'removed' => 1,
86+
],
87+
],
88+
]
89+
);
90+
91+
$this->updateHandler->execute($product);
92+
$this->assertFileExists($this->rootDirectory->getAbsolutePath($this->fileName));
93+
}
94+
95+
/**
96+
* @return void
97+
*/
98+
protected function tearDown(): void
99+
{
100+
parent::tearDown();
101+
unlink($this->rootDirectory->getAbsolutePath($this->fileName));
102+
}
103+
}

0 commit comments

Comments
 (0)