Skip to content

Commit 74cac07

Browse files
author
Magento CICD
authored
merge magento/2.3-develop into magento-borg/MAGETWO-91528
2 parents 45a5117 + 21990f7 commit 74cac07

File tree

22 files changed

+805
-549
lines changed

22 files changed

+805
-549
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Uploader.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,25 @@ public function move($fileName, $renameFileOff = false)
170170
}
171171
}
172172

173+
if ($this->getTmpDir()) {
174+
$filePath = $this->getTmpDir() . '/';
175+
} else {
176+
$filePath = '';
177+
}
173178
$fileName = preg_replace('/[^a-z0-9\._-]+/i', '', $fileName);
179+
$filePath = $this->_directory->getRelativePath($filePath . $fileName);
174180
$this->_directory->writeFile(
175-
$this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName),
181+
$filePath,
176182
$read->readAll()
177183
);
178184
}
179185

180-
$filePath = $this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName);
186+
if ($this->getTmpDir()) {
187+
$filePath = $this->getTmpDir() . '/';
188+
} else {
189+
$filePath = '';
190+
}
191+
$filePath = $this->_directory->getRelativePath($filePath . $fileName);
181192
$this->_setUploadFile($filePath);
182193
$destDir = $this->_directory->getAbsolutePath($this->getDestDir());
183194
$result = $this->save($destDir);

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected function setUp()
103103
public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName)
104104
{
105105
$destDir = 'var/dest/dir';
106-
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $expectedFileName;
106+
$expectedRelativeFilePath = $expectedFileName;
107107
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
108108
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);
109109
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)
@@ -139,7 +139,7 @@ public function testMoveFileName()
139139
{
140140
$destDir = 'var/dest/dir';
141141
$fileName = 'test_uploader_file';
142-
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $fileName;
142+
$expectedRelativeFilePath = $fileName;
143143
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
144144
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);
145145
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)

app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Delete.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ public function execute()
5353
$sitemap->load($id);
5454
// delete file
5555
$sitemapPath = $sitemap->getSitemapPath();
56+
if ($sitemapPath && $sitemapPath[0] === DIRECTORY_SEPARATOR) {
57+
$sitemapPath = mb_substr($sitemapPath, 1);
58+
}
5659
$sitemapFilename = $sitemap->getSitemapFilename();
57-
58-
$path = $directory->getRelativePath($sitemapPath . $sitemapFilename);
60+
$path = $directory->getRelativePath(
61+
$sitemapPath .$sitemapFilename
62+
);
5963
if ($sitemap->getSitemapFilename() && $directory->isFile($path)) {
6064
$directory->delete($path);
6165
}

app/code/Magento/Sitemap/Test/Unit/Controller/Adminhtml/Sitemap/DeleteTest.php

Lines changed: 0 additions & 149 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/UploaderTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ protected function setUp()
4848
$mediaPath = $appParams[DirectoryList::MEDIA][DirectoryList::PATH];
4949
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
5050
$tmpDir = $this->directory->getRelativePath($mediaPath . '/import');
51-
$this->uploader->setTmpDir($tmpDir);
51+
if (!$this->directory->create($tmpDir)) {
52+
throw new \RuntimeException('Failed to create temporary directory');
53+
}
54+
if (!$this->uploader->setTmpDir($tmpDir)) {
55+
throw new \RuntimeException(
56+
'Failed to set temporary directory for files.'
57+
);
58+
}
5259

5360
parent::setUp();
5461
}
@@ -70,6 +77,7 @@ public function testMoveWithValidFile(): void
7077
* @magentoAppIsolation enabled
7178
* @return void
7279
* @expectedException \Exception
80+
* @expectedExceptionMessage Disallowed file type
7381
*/
7482
public function testMoveWithInvalidFile(): void
7583
{

dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFilesTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ public function testExecuteWithWrongFileName()
101101
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
102102
$this->model->execute();
103103

104-
$this->assertTrue(
105-
$this->mediaDirectory->isExist(
106-
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . $fileName)
107-
)
108-
);
104+
$this->assertFileExists($this->fullDirectoryPath . $fileName);
109105
}
110106

111107
/**

dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFolderTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,7 @@ public function testExecuteWithWrongDirectoryName()
112112
$this->model->getRequest()->setParams(['node' => $this->imagesHelper->idEncode($directoryName)]);
113113
$this->model->execute();
114114

115-
$this->assertTrue(
116-
$this->mediaDirectory->isExist(
117-
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . $directoryName)
118-
)
119-
);
115+
$this->assertFileExists($this->fullDirectoryPath . $directoryName);
120116
}
121117

122118
/**

dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/NewFolderTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,8 @@ public function testExecuteWithWrongPath()
111111
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath . $dirPath);
112112
$this->model->execute();
113113

114-
$this->assertFalse(
115-
$this->mediaDirectory->isExist(
116-
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . $dirPath . $this->dirName)
117-
)
114+
$this->assertFileNotExists(
115+
$this->fullDirectoryPath . $dirPath . $this->dirName
118116
);
119117
}
120118

dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/UploadTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ public function testExecuteWithWrongPath()
125125
$this->model->getStorage()->getSession()->setCurrentPath($dirPath);
126126
$this->model->execute();
127127

128-
$this->assertFalse(
129-
$this->mediaDirectory->isExist(
130-
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . $dirPath . $this->fileName)
131-
)
128+
$this->assertFileNotExists(
129+
$this->fullDirectoryPath . $dirPath . $this->fileName
132130
);
133131
}
134132

@@ -147,11 +145,7 @@ public function testExecuteWithWrongFileName()
147145
$this->model->getStorage()->getSession()->setCurrentPath($this->fullDirectoryPath);
148146
$this->model->execute();
149147

150-
$this->assertFalse(
151-
$this->mediaDirectory->isExist(
152-
$this->mediaDirectory->getRelativePath($this->fullDirectoryPath . $newFilename)
153-
)
154-
);
148+
$this->assertFileNotExists($this->fullDirectoryPath . $newFilename);
155149
}
156150

157151
/**

dev/tests/integration/testsuite/Magento/Framework/App/Filesystem/DirectoryResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testValidatePath($path, $directoryConfig, $expectation)
5252
{
5353
$directory = $this->filesystem
5454
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
55-
$path = $directory->getAbsolutePath($path);
55+
$path = $directory->getAbsolutePath() .'/' .$path;
5656
$this->assertEquals($expectation, $this->directoryResolver->validatePath($path, $directoryConfig));
5757
}
5858

0 commit comments

Comments
 (0)