Skip to content

Commit d38b533

Browse files
MC-15385: Path check for images
1 parent 04960f3 commit d38b533

File tree

1 file changed

+53
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images

1 file changed

+53
-0
lines changed

dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/StorageTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,31 @@ public function testGetThumbsPath(): void
107107
);
108108
}
109109

110+
/**
111+
* @return void
112+
*/
113+
public function testDeleteDirectory(): void
114+
{
115+
$path = $this->objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class)->getCurrentPath();
116+
$dir = 'testDeleteDirectory';
117+
$fullPath = $path . $dir;
118+
$this->storage->createDirectory($dir, $path);
119+
$this->assertFileExists($fullPath);
120+
$this->storage->deleteDirectory($fullPath);
121+
$this->assertFileNotExists($fullPath);
122+
}
123+
124+
/**
125+
* @return void
126+
* @expectedException \Magento\Framework\Exception\LocalizedException
127+
* @expectedExceptionMessage We cannot delete directory /downloadable.
128+
*/
129+
public function testDeleteDirectoryWithExcludedDirPath(): void
130+
{
131+
$dir = $this->objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class)->getCurrentPath() . 'downloadable';
132+
$this->storage->deleteDirectory($dir);
133+
}
134+
110135
/**
111136
* @return void
112137
*/
@@ -126,11 +151,39 @@ public function testUploadFile(): void
126151
'error' => 0,
127152
'size' => 12500,
128153
];
154+
129155
$this->storage->uploadFile(self::$_baseDir);
130156
$this->assertTrue(is_file(self::$_baseDir . DIRECTORY_SEPARATOR . $fileName));
131157
// phpcs:enable
132158
}
133159

160+
/**
161+
* @return void
162+
* @expectedException \Magento\Framework\Exception\LocalizedException
163+
* @expectedExceptionMessage We can't upload the file to current folder right now. Please try another folder.
164+
*/
165+
public function testUploadFileWithExcludedDirPath(): void
166+
{
167+
$fileName = 'magento_small_image.jpg';
168+
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
169+
$filePath = $tmpDirectory->getAbsolutePath($fileName);
170+
// phpcs:disable
171+
$fixtureDir = realpath(__DIR__ . '/../../../../Catalog/_files');
172+
copy($fixtureDir . DIRECTORY_SEPARATOR . $fileName, $filePath);
173+
174+
$_FILES['image'] = [
175+
'name' => $fileName,
176+
'type' => 'image/jpeg',
177+
'tmp_name' => $filePath,
178+
'error' => 0,
179+
'size' => 12500,
180+
];
181+
182+
$dir = $this->objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class)->getCurrentPath() . 'downloadable';
183+
$this->storage->uploadFile($dir);
184+
// phpcs:enable
185+
}
186+
134187
/**
135188
* @param string $fileName
136189
* @param string $fileType

0 commit comments

Comments
 (0)