Skip to content

Commit 3e2e9d4

Browse files
MC-29874: [Magento Cloud] Unable to delete CSV files from Export Grid
1 parent db3b74a commit 3e2e9d4

File tree

2 files changed

+97
-29
lines changed

2 files changed

+97
-29
lines changed

dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Export/File/DeleteTest.php

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,78 @@ class DeleteTest extends AbstractBackendController
2929
*/
3030
private $fileName = 'catalog_product.csv';
3131

32+
/**
33+
* @var Filesystem
34+
*/
35+
private $fileSystem;
36+
37+
/**
38+
* @var string
39+
*/
40+
private $sourceFilePath;
41+
3242
/**
3343
* @inheritdoc
3444
*/
3545
protected function setUp()
3646
{
3747
parent::setUp();
3848

39-
$filesystem = $this->_objectManager->get(Filesystem::class);
40-
$sourceFilePath = __DIR__ . '/../../Import/_files' . DIRECTORY_SEPARATOR . $this->fileName;
41-
$destinationFilePath = 'export' . DIRECTORY_SEPARATOR . $this->fileName;
49+
$this->fileSystem = $this->_objectManager->get(Filesystem::class);
50+
$this->sourceFilePath = __DIR__ . '/../../Import/_files' . DIRECTORY_SEPARATOR . $this->fileName;
4251
//Refers to tests 'var' directory
43-
$this->varDirectory = $filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
44-
//Refers to application root directory
45-
$rootDirectory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
46-
$rootDirectory->copyFile($sourceFilePath, $this->varDirectory->getAbsolutePath($destinationFilePath));
52+
$this->varDirectory = $this->fileSystem->getDirectoryRead(DirectoryList::VAR_DIR);
4753
}
4854

4955
/**
5056
* Check that file can be removed under var/export directory.
5157
*
58+
* @param string $file
59+
* @dataProvider testExecuteProvider
5260
* @return void
5361
* @magentoConfigFixture default_store admin/security/use_form_key 1
5462
*/
55-
public function testExecute(): void
63+
public function testExecute($file): void
5664
{
65+
$fullPath = 'export/' . $file;
66+
$this->copyFile($fullPath);
5767
$request = $this->getRequest();
58-
$request->setParam('filename', $this->fileName);
68+
$request->setParam('filename', $file);
5969
$request->setMethod(Http::METHOD_POST);
6070

61-
if ($this->varDirectory->isExist('export/' . $this->fileName)) {
71+
if ($this->varDirectory->isExist($fullPath)) {
6272
$this->dispatch('backend/admin/export_file/delete');
6373
} else {
6474
throw new \AssertionError('Export product file supposed to exist');
6575
}
6676

67-
$this->assertFalse($this->varDirectory->isExist('export/' . $this->fileName));
77+
$this->assertFalse($this->varDirectory->isExist($fullPath));
78+
}
79+
80+
/**
81+
* Copy csv file from sourceFilePath to destinationFilePath
82+
*
83+
* @param $destinationFilePath
84+
* @return void
85+
*/
86+
private function copyFile($destinationFilePath): void
87+
{
88+
//Refers to application root directory
89+
$rootDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::ROOT);
90+
$rootDirectory->copyFile($this->sourceFilePath, $this->varDirectory->getAbsolutePath($destinationFilePath));
91+
}
92+
93+
/**
94+
* Csv file path for copying from sourceFilePath and for future deleting
95+
*
96+
* @return array
97+
*/
98+
public static function testExecuteProvider(): array
99+
{
100+
return [
101+
['catalog_product.csv'],
102+
['test/catalog_product.csv']
103+
];
68104
}
69105

70106
/**

dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Export/File/DownloadTest.php

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\ImportExport\Controller\Adminhtml\Export\File;
99

10-
use Magento\Backend\Model\Auth\Session;
1110
use Magento\Framework\App\Filesystem\DirectoryList;
1211
use Magento\Framework\App\Request\Http;
1312
use Magento\Framework\Filesystem;
@@ -16,7 +15,6 @@
1615
use Magento\TestFramework\TestCase\AbstractBackendController;
1716
use Magento\Backend\Model\UrlInterface as BackendUrl;
1817
use Magento\Backend\Model\Auth;
19-
use Magento\TestFramework\Bootstrap as TestBootstrap;
2018

2119
/**
2220
* Test for \Magento\ImportExport\Controller\Adminhtml\Export\File\Download class.
@@ -28,11 +26,6 @@ class DownloadTest extends AbstractBackendController
2826
*/
2927
private $fileName = 'catalog_product.csv';
3028

31-
/**
32-
* @var string
33-
*/
34-
private $filesize;
35-
3629
/**
3730
* @var Auth
3831
*/
@@ -43,38 +36,51 @@ class DownloadTest extends AbstractBackendController
4336
*/
4437
private $backendUrl;
4538

39+
/**
40+
* @var WriteInterface
41+
*/
42+
private $varDirectory;
43+
44+
/**
45+
* @var Filesystem
46+
*/
47+
private $fileSystem;
48+
49+
/**
50+
* @var string
51+
*/
52+
private $sourceFilePath;
53+
4654
/**
4755
* @inheritdoc
4856
*/
4957
protected function setUp()
5058
{
5159
parent::setUp();
5260

53-
$filesystem = $this->_objectManager->get(Filesystem::class);
61+
$this->fileSystem = $this->_objectManager->get(Filesystem::class);
5462
$auth = $this->_objectManager->get(Auth::class);
5563
$auth->getAuthStorage()->setIsFirstPageAfterLogin(false);
5664
$this->backendUrl = $this->_objectManager->get(BackendUrl::class);
5765
$this->backendUrl->turnOnSecretKey();
58-
59-
$sourceFilePath = __DIR__ . '/../../Import/_files' . DIRECTORY_SEPARATOR . $this->fileName;
60-
$destinationFilePath = 'export' . DIRECTORY_SEPARATOR . $this->fileName;
66+
$this->sourceFilePath = __DIR__ . '/../../Import/_files' . DIRECTORY_SEPARATOR . $this->fileName;
6167
//Refers to tests 'var' directory
62-
$varDirectory = $filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
63-
//Refers to application root directory
64-
$rootDirectory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
65-
$rootDirectory->copyFile($sourceFilePath, $varDirectory->getAbsolutePath($destinationFilePath));
66-
$this->filesize = $varDirectory->stat($destinationFilePath)['size'];
68+
$this->varDirectory = $this->fileSystem->getDirectoryRead(DirectoryList::VAR_DIR);
6769
}
6870

6971
/**
7072
* Check that file can be downloaded.
7173
*
74+
* @param string $file
75+
* @dataProvider testExecuteProvider
7276
* @return void
7377
* @magentoConfigFixture default_store admin/security/use_form_key 1
7478
* @magentoAppArea adminhtml
7579
*/
76-
public function testExecute(): void
80+
public function testExecute($file): void
7781
{
82+
$this->copyFile('export/' . $file);
83+
$fileSize = $this->varDirectory->stat('export/' . $file)['size'];
7884
$request = $this->getRequest();
7985
list($routeName, $controllerName, $actionName) = explode('/', Download::URL);
8086
$request->setMethod(Http::METHOD_GET)
@@ -104,12 +110,38 @@ public function testExecute(): void
104110
'Incorrect response header "content-disposition"'
105111
);
106112
$this->assertEquals(
107-
$this->filesize,
113+
$fileSize,
108114
$contentLength->getFieldValue(),
109115
'Incorrect response header "content-length"'
110116
);
111117
}
112118

119+
/**
120+
* Copy csv file from sourceFilePath to destinationFilePath
121+
*
122+
* @param $destinationFilePath
123+
* @return void
124+
*/
125+
private function copyFile($destinationFilePath): void
126+
{
127+
//Refers to application root directory
128+
$rootDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::ROOT);
129+
$rootDirectory->copyFile($this->sourceFilePath, $this->varDirectory->getAbsolutePath($destinationFilePath));
130+
}
131+
132+
/**
133+
* Csv file path for copying from sourceFilePath and for future deleting
134+
*
135+
* @return array
136+
*/
137+
public static function testExecuteProvider(): array
138+
{
139+
return [
140+
['catalog_product.csv'],
141+
['test/catalog_product.csv']
142+
];
143+
}
144+
113145
/**
114146
* @inheritdoc
115147
*/

0 commit comments

Comments
 (0)