@@ -72,8 +72,9 @@ class DownloadTest extends \PHPUnit\Framework\TestCase
72
72
*/
73
73
protected function setUp ()
74
74
{
75
- $ this ->request = $ this ->createPartialMock (\Magento \Framework \App \Request \Http::class, ['getParam ' ]);
76
- $ this ->request ->expects ($ this ->any ())->method ('getParam ' )->with ('filename ' )->willReturn ('filename ' );
75
+ $ this ->request = $ this ->getMockBuilder (\Magento \Framework \App \Request \Http::class)
76
+ ->disableOriginalConstructor ()
77
+ ->getMock ();
77
78
$ this ->reportHelper = $ this ->createPartialMock (
78
79
\Magento \ImportExport \Helper \Report::class,
79
80
['importFileExists ' , 'getReportSize ' , 'getReportOutput ' ]
@@ -126,21 +127,44 @@ protected function setUp()
126
127
}
127
128
128
129
/**
129
- * Test execute()
130
+ * Tests download controller with different file names in request.
131
+ *
132
+ * @param string $requestFilename
133
+ * @param string $processedFilename
134
+ * @dataProvider executeDataProvider
130
135
*/
131
- public function testExecute ()
136
+ public function testExecute ($ requestFilename , $ processedFilename )
132
137
{
133
- $ this ->reportHelper ->expects ($ this ->any ())->method ('importFileExists ' )->willReturn (true );
138
+ $ this ->request ->method ('getParam ' )
139
+ ->with ('filename ' )
140
+ ->willReturn ($ requestFilename );
141
+
142
+ $ this ->reportHelper ->method ('importFileExists ' )
143
+ ->with ($ processedFilename )
144
+ ->willReturn (true );
134
145
$ this ->resultRaw ->expects ($ this ->once ())->method ('setContents ' );
135
146
$ this ->downloadController ->execute ();
136
147
}
137
148
149
+ /**
150
+ * @return array
151
+ */
152
+ public function executeDataProvider ()
153
+ {
154
+ return [
155
+ 'Normal file name ' => ['filename.csv ' , 'filename.csv ' ],
156
+ 'Relative file name ' => ['../../../../../../../../etc/passwd ' , 'passwd ' ],
157
+ 'Empty file name ' => ['' , '' ],
158
+ ];
159
+ }
160
+
138
161
/**
139
162
* Test execute() with not found file
140
163
*/
141
164
public function testExecuteFileNotFound ()
142
165
{
143
- $ this ->reportHelper ->expects ($ this ->any ())->method ('importFileExists ' )->willReturn (false );
166
+ $ this ->request ->method ('getParam ' )->with ('filename ' )->willReturn ('filename ' );
167
+ $ this ->reportHelper ->method ('importFileExists ' )->willReturn (false );
144
168
$ this ->resultRaw ->expects ($ this ->never ())->method ('setContents ' );
145
169
$ this ->downloadController ->execute ();
146
170
}
0 commit comments