@@ -54,10 +54,6 @@ protected function setUp()
54
54
$ filePath = $ this ->fullDirectoryPath . DIRECTORY_SEPARATOR . $ this ->fileName ;
55
55
$ fixtureDir = realpath (__DIR__ . '/../../../../../Catalog/_files ' );
56
56
copy ($ fixtureDir . '/ ' . $ this ->fileName , $ filePath );
57
- $ path = '/.htaccess ' ;
58
- if (!$ this ->mediaDirectory ->isFile ($ path )) {
59
- $ this ->mediaDirectory ->writeFile ($ path , "Order deny,allow \nDeny from all " );
60
- }
61
57
$ this ->model = $ objectManager ->get (\Magento \Cms \Controller \Adminhtml \Wysiwyg \Images \DeleteFiles::class);
62
58
}
63
59
@@ -95,21 +91,54 @@ public static function tearDownAfterClass()
95
91
}
96
92
97
93
/**
98
- * Check that htaccess file couldn't be removed via
94
+ * Creates file and tried to delete it via
99
95
* \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
100
96
*
97
+ * @param string $fileName
101
98
* @return void
102
99
*/
103
- public function testDeleteHtaccess ( )
100
+ private function createFileAndExecuteDelete ( $ fileName )
104
101
{
102
+ $ path = '/ ' . $ fileName ;
103
+ if (!$ this ->mediaDirectory ->isFile ($ path )) {
104
+ $ this ->mediaDirectory ->writeFile ($ path , "Order deny,allow \nDeny from all " );
105
+ }
105
106
$ this ->model ->getRequest ()->setMethod ('POST ' )
106
- ->setPostValue ('files ' , [$ this ->imagesHelper ->idEncode (' .htaccess ' )]);
107
- $ this ->model ->getStorage ()->getSession ()->setCurrentPath ($ this ->fullDirectoryPath );
107
+ ->setPostValue ('files ' , [$ this ->imagesHelper ->idEncode ($ fileName )]);
108
+ $ this ->model ->getStorage ()->getSession ()->setCurrentPath ($ this ->mediaDirectory -> getAbsolutePath () );
108
109
$ this ->model ->execute ();
110
+ }
109
111
112
+ /**
113
+ * Check that htaccess file couldn't be removed via
114
+ * \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
115
+ *
116
+ * @return void
117
+ */
118
+ public function testCouldNotDeleteHtaccess ()
119
+ {
120
+ $ fileName = '.htaccess ' ;
121
+ $ this ->createFileAndExecuteDelete ($ fileName );
110
122
$ this ->assertTrue (
111
123
$ this ->mediaDirectory ->isExist (
112
- $ this ->mediaDirectory ->getRelativePath ('/ ' . '.htaccess ' )
124
+ $ this ->mediaDirectory ->getRelativePath ('/ ' . $ fileName )
125
+ )
126
+ );
127
+ }
128
+
129
+ /**
130
+ * Check that random file could be removed via
131
+ * \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
132
+ *
133
+ * @return void
134
+ */
135
+ public function testDeleteAnyFile ()
136
+ {
137
+ $ fileName = 'thtaccess ' ;
138
+ $ this ->createFileAndExecuteDelete ($ fileName );
139
+ $ this ->assertFalse (
140
+ $ this ->mediaDirectory ->isExist (
141
+ $ this ->mediaDirectory ->getRelativePath ('/ ' . $ fileName )
113
142
)
114
143
);
115
144
}
0 commit comments