1
1
<?php
2
2
namespace Magento \Downloadable \Controller \Adminhtml \Downloadable ;
3
3
4
+ use Magento \Framework \Serialize \Serializer \Json ;
5
+ use Magento \TestFramework \Helper \Bootstrap ;
6
+
4
7
/**
5
8
* Magento\Downloadable\Controller\Adminhtml\Downloadable\File
6
9
*
10
13
*/
11
14
class FileTest extends \Magento \TestFramework \TestCase \AbstractBackendController
12
15
{
16
+ /**
17
+ * @inheritdoc
18
+ */
19
+ protected function tearDown ()
20
+ {
21
+ $ filePath = dirname (__DIR__ ) . '/_files/sample.tmp ' ;
22
+ if (is_file ($ filePath )) {
23
+ unlink ($ filePath );
24
+ }
25
+ }
26
+
13
27
public function testUploadAction ()
14
28
{
15
29
copy (dirname (__DIR__ ) . '/_files/sample.txt ' , dirname (__DIR__ ) . '/_files/sample.tmp ' );
@@ -25,11 +39,52 @@ public function testUploadAction()
25
39
26
40
$ this ->dispatch ('backend/admin/downloadable_file/upload/type/samples ' );
27
41
$ body = $ this ->getResponse ()->getBody ();
28
- $ result = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
29
- \Magento \Framework \Json \Helper \Data::class
30
- )->jsonDecode (
31
- $ body
32
- );
42
+ $ result = Bootstrap::getObjectManager ()->get (Json::class)->unserialize ($ body );
33
43
$ this ->assertEquals (0 , $ result ['error ' ]);
34
44
}
45
+
46
+ /**
47
+ * Checks a case when php files are not allowed to upload.
48
+ *
49
+ * @param string $fileName
50
+ * @dataProvider extensionsDataProvider
51
+ */
52
+ public function testUploadProhibitedExtensions ($ fileName )
53
+ {
54
+ $ path = dirname (__DIR__ ) . '/_files/ ' ;
55
+ copy ($ path . 'sample.txt ' , $ path . 'sample.tmp ' );
56
+
57
+ $ _FILES = [
58
+ 'samples ' => [
59
+ 'name ' => $ fileName ,
60
+ 'type ' => 'text/plain ' ,
61
+ 'tmp_name ' => $ path . 'sample.tmp ' ,
62
+ 'error ' => 0 ,
63
+ 'size ' => 0 ,
64
+ ],
65
+ ];
66
+
67
+ $ this ->dispatch ('backend/admin/downloadable_file/upload/type/samples ' );
68
+ $ body = $ this ->getResponse ()->getBody ();
69
+ $ result = Bootstrap::getObjectManager ()->get (Json::class)->unserialize ($ body );
70
+
71
+ self ::assertEquals (0 , $ result ['errorcode ' ]);
72
+ self ::assertEquals ('Disallowed file type. ' , $ result ['error ' ]);
73
+ }
74
+
75
+ /**
76
+ * Returns different php file extensions.
77
+ *
78
+ * @return array
79
+ */
80
+ public function extensionsDataProvider ()
81
+ {
82
+ return [
83
+ ['sample.php ' ],
84
+ ['sample.php3 ' ],
85
+ ['sample.php4 ' ],
86
+ ['sample.php5 ' ],
87
+ ['sample.php7 ' ],
88
+ ];
89
+ }
35
90
}
0 commit comments