@@ -88,5 +88,64 @@ public static function tearDownAfterClass()
8888 if ($ directory ->isExist ('wysiwyg ' )) {
8989 $ directory ->delete ('wysiwyg ' );
9090 }
91+ if ($ directory ->isExist ('.htaccess ' )) {
92+ $ directory ->delete ('.htaccess ' );
93+ }
94+ if ($ directory ->isExist ('thtaccess ' )) {
95+ $ directory ->delete ('thtaccess ' );
96+ }
97+ }
98+
99+ /**
100+ * Creates file and tries to delete it via
101+ * \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
102+ *
103+ * @param string $fileName
104+ * @return void
105+ */
106+ private function createFileAndExecuteDelete ($ fileName )
107+ {
108+ $ path = '/ ' . $ fileName ;
109+ if (!$ this ->mediaDirectory ->isFile ($ path )) {
110+ $ this ->mediaDirectory ->writeFile ($ path , "Order deny,allow \nDeny from all " );
111+ }
112+ $ this ->model ->getRequest ()->setMethod ('POST ' )
113+ ->setPostValue ('files ' , [$ this ->imagesHelper ->idEncode ($ fileName )]);
114+ $ this ->model ->getStorage ()->getSession ()->setCurrentPath ($ this ->mediaDirectory ->getAbsolutePath ());
115+ $ this ->model ->execute ();
116+ }
117+
118+ /**
119+ * Check that htaccess file couldn't be removed via
120+ * \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
121+ *
122+ * @return void
123+ */
124+ public function testCouldNotDeleteHtaccess ()
125+ {
126+ $ fileName = '.htaccess ' ;
127+ $ this ->createFileAndExecuteDelete ($ fileName );
128+ $ this ->assertTrue (
129+ $ this ->mediaDirectory ->isExist (
130+ $ this ->mediaDirectory ->getRelativePath ($ fileName )
131+ )
132+ );
133+ }
134+
135+ /**
136+ * Check that random file could be removed via
137+ * \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
138+ *
139+ * @return void
140+ */
141+ public function testDeleteAnyFile ()
142+ {
143+ $ fileName = 'thtaccess ' ;
144+ $ this ->createFileAndExecuteDelete ($ fileName );
145+ $ this ->assertFalse (
146+ $ this ->mediaDirectory ->isExist (
147+ $ this ->mediaDirectory ->getRelativePath ($ fileName )
148+ )
149+ );
91150 }
92151}
0 commit comments