Skip to content

Commit cb53146

Browse files
committed
Merge remote-tracking branch 'origin/MC-15448' into 2.3.2-develop-pr51
2 parents 41c37b3 + 0c3cb38 commit cb53146

File tree

5 files changed

+225
-7
lines changed

5 files changed

+225
-7
lines changed

app/code/Magento/ImportExport/Controller/Adminhtml/Export/File/Delete.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Magento\ImportExport\Controller\Adminhtml\Export\File;
99

1010
use Magento\Backend\App\Action;
11-
use Magento\Framework\App\Action\HttpGetActionInterface;
11+
use Magento\Framework\App\Action\HttpPostActionInterface;
1212
use Magento\Framework\Controller\ResultFactory;
1313
use Magento\Framework\Exception\FileSystemException;
1414
use Magento\Framework\Exception\LocalizedException;
@@ -20,12 +20,12 @@
2020
/**
2121
* Controller that delete file by name.
2222
*/
23-
class Delete extends ExportController implements HttpGetActionInterface
23+
class Delete extends ExportController implements HttpPostActionInterface
2424
{
2525
/**
26-
* url to this controller
26+
* Url to this controller
2727
*/
28-
const URL = 'admin/export_file/delete';
28+
const URL = 'adminhtml/export_file/delete';
2929

3030
/**
3131
* @var Filesystem

app/code/Magento/ImportExport/Controller/Adminhtml/Export/File/Download.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
class Download extends ExportController implements HttpGetActionInterface
2222
{
2323
/**
24-
* url to this controller
24+
* Url to this controller
2525
*/
26-
const URL = 'admin/export_file/download/';
26+
const URL = 'adminhtml/export_file/download/';
2727

2828
/**
2929
* @var FileFactory

app/code/Magento/ImportExport/Ui/Component/Columns/ExportGridActions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public function prepareDataSource(array $dataSource)
6565
'confirm' => [
6666
'title' => __('Delete'),
6767
'message' => __('Are you sure you wan\'t to delete a file?')
68-
]
68+
],
69+
'post' => true,
6970
];
7071
}
7172
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ImportExport\Controller\Adminhtml\Export\File;
9+
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\App\Request\Http;
12+
use Magento\Framework\Filesystem;
13+
use Magento\Framework\Filesystem\Directory\WriteInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\TestCase\AbstractBackendController;
16+
17+
/**
18+
* Test for \Magento\ImportExport\Controller\Adminhtml\Export\File\Delete class.
19+
*/
20+
class DeleteTest extends AbstractBackendController
21+
{
22+
/**
23+
* @var WriteInterface
24+
*/
25+
private $varDirectory;
26+
27+
/**
28+
* @var string
29+
*/
30+
private $fileName = 'catalog_product.csv';
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
protected function setUp()
36+
{
37+
parent::setUp();
38+
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));
47+
}
48+
49+
/**
50+
* Check that file can be removed under var/export directory.
51+
*
52+
* @return void
53+
* @magentoConfigFixture default_store admin/security/use_form_key 1
54+
*/
55+
public function testExecute(): void
56+
{
57+
$request = $this->getRequest();
58+
$request->setParam('filename', $this->fileName);
59+
$request->setMethod(Http::METHOD_POST);
60+
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));
68+
}
69+
70+
/**
71+
* @inheritdoc
72+
*/
73+
public static function tearDownAfterClass()
74+
{
75+
$filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
76+
/** @var WriteInterface $directory */
77+
$directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
78+
if ($directory->isExist('export')) {
79+
$directory->delete('export');
80+
}
81+
}
82+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ImportExport\Controller\Adminhtml\Export\File;
9+
10+
use Magento\Backend\Model\Auth\Session;
11+
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\App\Request\Http;
13+
use Magento\Framework\Filesystem;
14+
use Magento\Framework\Filesystem\Directory\WriteInterface;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use Magento\TestFramework\TestCase\AbstractBackendController;
17+
use Magento\Backend\Model\UrlInterface as BackendUrl;
18+
use Magento\Backend\Model\Auth;
19+
use Magento\TestFramework\Bootstrap as TestBootstrap;
20+
21+
/**
22+
* Test for \Magento\ImportExport\Controller\Adminhtml\Export\File\Download class.
23+
*/
24+
class DownloadTest extends AbstractBackendController
25+
{
26+
/**
27+
* @var string
28+
*/
29+
private $fileName = 'catalog_product.csv';
30+
31+
/**
32+
* @var string
33+
*/
34+
private $filesize;
35+
36+
/**
37+
* @var Auth
38+
*/
39+
private $auth;
40+
41+
/**
42+
* @var BackendUrl
43+
*/
44+
private $backendUrl;
45+
46+
/**
47+
* @inheritdoc
48+
*/
49+
protected function setUp()
50+
{
51+
parent::setUp();
52+
53+
$filesystem = $this->_objectManager->get(Filesystem::class);
54+
$auth = $this->_objectManager->get(Auth::class);
55+
$auth->getAuthStorage()->setIsFirstPageAfterLogin(false);
56+
$this->backendUrl = $this->_objectManager->get(BackendUrl::class);
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'];
67+
}
68+
69+
/**
70+
* Check that file can be downloaded.
71+
*
72+
* @return void
73+
* @magentoConfigFixture default_store admin/security/use_form_key 1
74+
* @magentoAppArea adminhtml
75+
*/
76+
public function testExecute(): void
77+
{
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());
86+
87+
ob_start();
88+
$this->dispatch('backend/admin/export_file/download');
89+
ob_end_clean();
90+
91+
$contentType = $this->getResponse()->getHeader('content-type');
92+
$contentLength = $this->getResponse()->getHeader('content-length');
93+
$contentDisposition = $this->getResponse()->getHeader('content-disposition');
94+
95+
$this->assertEquals(200, $this->getResponse()->getStatusCode(), 'Incorrect response status code');
96+
$this->assertEquals(
97+
'application/octet-stream',
98+
$contentType->getFieldValue(),
99+
'Incorrect response header "content-type"'
100+
);
101+
$this->assertEquals(
102+
'attachment; filename="export/' . $this->fileName . '"',
103+
$contentDisposition->getFieldValue(),
104+
'Incorrect response header "content-disposition"'
105+
);
106+
$this->assertEquals(
107+
$this->filesize,
108+
$contentLength->getFieldValue(),
109+
'Incorrect response header "content-length"'
110+
);
111+
}
112+
113+
/**
114+
* @inheritdoc
115+
*/
116+
protected function tearDown()
117+
{
118+
$this->auth = null;
119+
120+
parent::tearDown();
121+
}
122+
123+
/**
124+
* @inheritdoc
125+
*/
126+
public static function tearDownAfterClass()
127+
{
128+
$filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
129+
/** @var WriteInterface $directory */
130+
$directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
131+
if ($directory->isExist('export')) {
132+
$directory->delete('export');
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)