Skip to content

Commit 0c3cb38

Browse files
committed
MC-15448: One can't download or delete export csv file from export index page grid
1 parent 2e51795 commit 0c3cb38

File tree

2 files changed

+40
-79
lines changed

2 files changed

+40
-79
lines changed

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

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,26 @@ class DeleteTest extends AbstractBackendController
2424
*/
2525
private $varDirectory;
2626

27-
/**
28-
* @var string
29-
*/
30-
private $fullDirectoryPath;
31-
3227
/**
3328
* @var string
3429
*/
3530
private $fileName = 'catalog_product.csv';
3631

37-
/**
38-
* @var Filesystem
39-
*/
40-
private $filesystem;
41-
4232
/**
4333
* @inheritdoc
4434
*/
4535
protected function setUp()
4636
{
4737
parent::setUp();
4838

49-
$this->filesystem = $this->_objectManager->get(Filesystem::class);
50-
$baseDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
51-
$this->varDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
52-
$this->varDirectory->create($this->varDirectory->getRelativePath('export'));
53-
$this->fullDirectoryPath = $this->varDirectory->getAbsolutePath('export');
54-
$filePath = $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName;
55-
$fixtureDir = realpath(__DIR__ . '/../../Import/_files');
56-
$baseDirectory->copyFile($fixtureDir . '/' . $this->fileName, $filePath);
39+
$filesystem = $this->_objectManager->get(Filesystem::class);
40+
$sourceFilePath = __DIR__ . '/../../Import/_files' . DIRECTORY_SEPARATOR . $this->fileName;
41+
$destinationFilePath = 'export' . DIRECTORY_SEPARATOR . $this->fileName;
42+
//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));
5747
}
5848

5949
/**
@@ -64,15 +54,17 @@ protected function setUp()
6454
*/
6555
public function testExecute(): void
6656
{
67-
$uri = 'backend/admin/export_file/delete/filename/' . $this->fileName;
6857
$request = $this->getRequest();
58+
$request->setParam('filename', $this->fileName);
6959
$request->setMethod(Http::METHOD_POST);
70-
$request->setRequestUri($uri);
71-
$this->dispatch($uri);
7260

73-
$this->assertFalse(
74-
$this->varDirectory->isExist($this->varDirectory->getRelativePath('export/' . $this->fileName))
75-
);
61+
if ($this->varDirectory->isExist('export/' . $this->fileName)) {
62+
$this->dispatch('backend/admin/export_file/delete');
63+
} else {
64+
throw new \AssertionError('Export product file supposed to exist');
65+
}
66+
67+
$this->assertFalse($this->varDirectory->isExist('export/' . $this->fileName));
7668
}
7769

7870
/**

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

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323
*/
2424
class DownloadTest extends AbstractBackendController
2525
{
26-
/**
27-
* @var WriteInterface
28-
*/
29-
private $varDirectory;
30-
31-
/**
32-
* @var string
33-
*/
34-
private $fullDirectoryPath;
35-
3626
/**
3727
* @var string
3828
*/
@@ -43,11 +33,6 @@ class DownloadTest extends AbstractBackendController
4333
*/
4434
private $filesize;
4535

46-
/**
47-
* @var Filesystem
48-
*/
49-
private $filesystem;
50-
5136
/**
5237
* @var Auth
5338
*/
@@ -65,17 +50,20 @@ protected function setUp()
6550
{
6651
parent::setUp();
6752

68-
$this->filesystem = $this->_objectManager->get(Filesystem::class);
69-
$this->auth = $this->_objectManager->get(Auth::class);
53+
$filesystem = $this->_objectManager->get(Filesystem::class);
54+
$auth = $this->_objectManager->get(Auth::class);
55+
$auth->getAuthStorage()->setIsFirstPageAfterLogin(false);
7056
$this->backendUrl = $this->_objectManager->get(BackendUrl::class);
71-
$baseDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
72-
$this->varDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
73-
$this->varDirectory->create($this->varDirectory->getRelativePath('export'));
74-
$this->fullDirectoryPath = $this->varDirectory->getAbsolutePath('export');
75-
$filePath = $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName;
76-
$fixtureDir = realpath(__DIR__ . '/../../Import/_files');
77-
$baseDirectory->copyFile($fixtureDir . '/' . $this->fileName, $filePath);
78-
$this->filesize = filesize($filePath);
57+
$this->backendUrl->turnOnSecretKey();
58+
59+
$sourceFilePath = __DIR__ . '/../../Import/_files' . DIRECTORY_SEPARATOR . $this->fileName;
60+
$destinationFilePath = 'export' . DIRECTORY_SEPARATOR . $this->fileName;
61+
//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'];
7967
}
8068

8169
/**
@@ -87,10 +75,18 @@ protected function setUp()
8775
*/
8876
public function testExecute(): void
8977
{
90-
$uri = 'backend/admin/export_file/download/filename/' . $this->fileName;
91-
$this->prepareRequest($uri);
78+
$request = $this->getRequest();
79+
list($routeName, $controllerName, $actionName) = explode('/', Download::URL);
80+
$request->setMethod(Http::METHOD_GET)
81+
->setRouteName($routeName)
82+
->setControllerName($controllerName)
83+
->setActionName($actionName);
84+
$request->setParam('filename', $this->fileName);
85+
$request->setParam(BackendUrl::SECRET_KEY_PARAM_NAME, $this->backendUrl->getSecretKey());
9286

93-
$this->dispatch($uri);
87+
ob_start();
88+
$this->dispatch('backend/admin/export_file/download');
89+
ob_end_clean();
9490

9591
$contentType = $this->getResponse()->getHeader('content-type');
9692
$contentLength = $this->getResponse()->getHeader('content-length');
@@ -114,33 +110,6 @@ public function testExecute(): void
114110
);
115111
}
116112

117-
/**
118-
* Prepares GET request to download file.
119-
*
120-
* @param string $uri
121-
* @return void
122-
*/
123-
private function prepareRequest(string $uri): void
124-
{
125-
$authSession = $this->_objectManager->create(Session::class);
126-
$authSession->setIsFirstPageAfterLogin(false);
127-
$this->auth->login(
128-
TestBootstrap::ADMIN_NAME,
129-
TestBootstrap::ADMIN_PASSWORD
130-
);
131-
$this->auth->setAuthStorage($authSession);
132-
133-
list($routeName, $controllerName, $actionName) = explode('/', Download::URL);
134-
$request = $this->getRequest();
135-
$request->setMethod(Http::METHOD_GET)
136-
->setRouteName($routeName)
137-
->setControllerName($controllerName)
138-
->setActionName($actionName)
139-
->setParam(BackendUrl::SECRET_KEY_PARAM_NAME, $this->backendUrl->getSecretKey())
140-
->setRequestUri($uri);
141-
$this->backendUrl->turnOnSecretKey();
142-
}
143-
144113
/**
145114
* @inheritdoc
146115
*/

0 commit comments

Comments
 (0)