7
7
8
8
namespace Magento \ImportExport \Controller \Adminhtml \Export \File ;
9
9
10
- use Magento \Backend \Model \Auth \Session ;
11
10
use Magento \Framework \App \Filesystem \DirectoryList ;
12
11
use Magento \Framework \App \Request \Http ;
13
12
use Magento \Framework \Filesystem ;
16
15
use Magento \TestFramework \TestCase \AbstractBackendController ;
17
16
use Magento \Backend \Model \UrlInterface as BackendUrl ;
18
17
use Magento \Backend \Model \Auth ;
19
- use Magento \TestFramework \Bootstrap as TestBootstrap ;
20
18
21
19
/**
22
20
* Test for \Magento\ImportExport\Controller\Adminhtml\Export\File\Download class.
@@ -28,11 +26,6 @@ class DownloadTest extends AbstractBackendController
28
26
*/
29
27
private $ fileName = 'catalog_product.csv ' ;
30
28
31
- /**
32
- * @var string
33
- */
34
- private $ filesize ;
35
-
36
29
/**
37
30
* @var Auth
38
31
*/
@@ -43,38 +36,51 @@ class DownloadTest extends AbstractBackendController
43
36
*/
44
37
private $ backendUrl ;
45
38
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
+
46
54
/**
47
55
* @inheritdoc
48
56
*/
49
57
protected function setUp ()
50
58
{
51
59
parent ::setUp ();
52
60
53
- $ filesystem = $ this ->_objectManager ->get (Filesystem::class);
61
+ $ this -> fileSystem = $ this ->_objectManager ->get (Filesystem::class);
54
62
$ auth = $ this ->_objectManager ->get (Auth::class);
55
63
$ auth ->getAuthStorage ()->setIsFirstPageAfterLogin (false );
56
64
$ this ->backendUrl = $ this ->_objectManager ->get (BackendUrl::class);
57
65
$ 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 ;
61
67
//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 );
67
69
}
68
70
69
71
/**
70
72
* Check that file can be downloaded.
71
73
*
74
+ * @param string $file
75
+ * @dataProvider testExecuteProvider
72
76
* @return void
73
77
* @magentoConfigFixture default_store admin/security/use_form_key 1
74
78
* @magentoAppArea adminhtml
75
79
*/
76
- public function testExecute (): void
80
+ public function testExecute ($ file ): void
77
81
{
82
+ $ this ->copyFile ('export/ ' . $ file );
83
+ $ fileSize = $ this ->varDirectory ->stat ('export/ ' . $ file )['size ' ];
78
84
$ request = $ this ->getRequest ();
79
85
list ($ routeName , $ controllerName , $ actionName ) = explode ('/ ' , Download::URL );
80
86
$ request ->setMethod (Http::METHOD_GET )
@@ -104,12 +110,38 @@ public function testExecute(): void
104
110
'Incorrect response header "content-disposition" '
105
111
);
106
112
$ this ->assertEquals (
107
- $ this -> filesize ,
113
+ $ fileSize ,
108
114
$ contentLength ->getFieldValue (),
109
115
'Incorrect response header "content-length" '
110
116
);
111
117
}
112
118
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
+
113
145
/**
114
146
* @inheritdoc
115
147
*/
0 commit comments