@@ -60,10 +60,6 @@ protected function setUp()
60
60
$ this ->mediaDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::MEDIA );
61
61
$ this ->model = $ this ->objectManager ->get (\Magento \Cms \Controller \Adminhtml \Wysiwyg \Images \DeleteFiles::class);
62
62
$ this ->fullDirectoryPath = $ this ->imagesHelper ->getStorageRoot () . '/directory1 ' ;
63
- $ path = $ this ->fullDirectoryPath . '/.htaccess ' ;
64
- if (!$ this ->mediaDirectory ->isFile ($ path )) {
65
- $ this ->mediaDirectory ->writeFile ($ path , "Order deny,allow \nDeny from all " );
66
- }
67
63
}
68
64
69
65
/**
@@ -74,20 +70,15 @@ protected function setUp()
74
70
*/
75
71
public function testExecute ()
76
72
{
77
- $ directoryName = 'directory1 ' ;
78
- $ fullDirectoryPath = $ this ->imagesHelper ->getStorageRoot () . '/ ' . $ directoryName ;
79
- $ this ->mediaDirectory ->create ($ this ->mediaDirectory ->getRelativePath ($ fullDirectoryPath ));
80
- $ filePath = $ fullDirectoryPath . DIRECTORY_SEPARATOR . $ this ->fileName ;
73
+ $ this ->mediaDirectory ->create ($ this ->mediaDirectory ->getRelativePath ($ this ->fullDirectoryPath ));
74
+ $ filePath = $ this ->fullDirectoryPath . DIRECTORY_SEPARATOR . $ this ->fileName ;
81
75
$ fixtureDir = realpath (__DIR__ . '/../../../../../Catalog/_files ' );
82
76
copy ($ fixtureDir . '/ ' . $ this ->fileName , $ filePath );
83
77
84
- $ this ->model ->getRequest ()->setMethod ('POST ' )
85
- ->setPostValue ('files ' , [$ this ->imagesHelper ->idEncode ($ this ->fileName )]);
86
- $ this ->model ->getStorage ()->getSession ()->setCurrentPath ($ fullDirectoryPath );
87
- $ this ->model ->execute ();
78
+ $ this ->executeFileDelete ($ this ->fullDirectoryPath , $ this ->fileName );
88
79
$ this ->assertFalse (
89
80
$ this ->mediaDirectory ->isExist (
90
- $ this ->mediaDirectory ->getRelativePath ($ fullDirectoryPath . '/ ' . $ this ->fileName )
81
+ $ this ->mediaDirectory ->getRelativePath ($ this -> fullDirectoryPath . '/ ' . $ this ->fileName )
91
82
)
92
83
);
93
84
}
@@ -109,10 +100,7 @@ public function testExecuteWithLinkedMedia()
109
100
copy ($ fixtureDir . '/ ' . $ this ->fileName , $ filePath );
110
101
111
102
$ wysiwygDir = $ this ->mediaDirectory ->getAbsolutePath () . '/wysiwyg ' ;
112
- $ this ->model ->getRequest ()->setMethod ('POST ' )
113
- ->setPostValue ('files ' , [$ this ->imagesHelper ->idEncode ($ this ->fileName )]);
114
- $ this ->model ->getStorage ()->getSession ()->setCurrentPath ($ wysiwygDir );
115
- $ this ->model ->execute ();
103
+ $ this ->executeFileDelete ($ wysiwygDir , $ this ->fileName );
116
104
$ this ->assertFalse (is_file ($ fullDirectoryPath . DIRECTORY_SEPARATOR . $ this ->fileName ));
117
105
}
118
106
@@ -124,18 +112,64 @@ public function testExecuteWithLinkedMedia()
124
112
*/
125
113
public function testDeleteHtaccess ()
126
114
{
127
- $ this ->model ->getRequest ()->setMethod ('POST ' )
128
- ->setPostValue ('files ' , [$ this ->imagesHelper ->idEncode ('.htaccess ' )]);
129
- $ this ->model ->getStorage ()->getSession ()->setCurrentPath ($ this ->fullDirectoryPath );
130
- $ this ->model ->execute ();
115
+ $ this ->createFile ($ this ->fullDirectoryPath , '.htaccess ' );
116
+ $ this ->executeFileDelete ($ this ->fullDirectoryPath , '.htaccess ' );
131
117
132
118
$ this ->assertTrue (
133
119
$ this ->mediaDirectory ->isExist (
134
- $ this ->mediaDirectory ->getRelativePath ($ this ->fullDirectoryPath . '/ ' . '.htaccess ' )
120
+ $ this ->mediaDirectory ->getRelativePath ($ this ->fullDirectoryPath . '/.htaccess ' )
121
+ )
122
+ );
123
+ }
124
+
125
+ /**
126
+ * Check that random file could be removed via
127
+ * \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
128
+ *
129
+ * @return void
130
+ */
131
+ public function testDeleteAnyFile ()
132
+ {
133
+ $ this ->createFile ($ this ->fullDirectoryPath , 'ahtaccess ' );
134
+ $ this ->executeFileDelete ($ this ->fullDirectoryPath , 'ahtaccess ' );
135
+
136
+ $ this ->assertFalse (
137
+ $ this ->mediaDirectory ->isExist (
138
+ $ this ->mediaDirectory ->getRelativePath ($ this ->fullDirectoryPath . '/ahtaccess ' )
135
139
)
136
140
);
137
141
}
138
142
143
+ /**
144
+ * Create file.
145
+ *
146
+ * @param string $path
147
+ * @param string $fileName
148
+ * @return void
149
+ */
150
+ private function createFile (string $ path , string $ fileName )
151
+ {
152
+ $ file = $ path . '/ ' . $ fileName ;
153
+ if (!$ this ->mediaDirectory ->isFile ($ file )) {
154
+ $ this ->mediaDirectory ->writeFile ($ file , 'Content ' );
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Execute file delete operation.
160
+ *
161
+ * @param string $path
162
+ * @param string $fileName
163
+ * @return void
164
+ */
165
+ private function executeFileDelete (string $ path , string $ fileName )
166
+ {
167
+ $ this ->model ->getRequest ()->setMethod ('POST ' )
168
+ ->setPostValue ('files ' , [$ this ->imagesHelper ->idEncode ($ fileName )]);
169
+ $ this ->model ->getStorage ()->getSession ()->setCurrentPath ($ path );
170
+ $ this ->model ->execute ();
171
+ }
172
+
139
173
/**
140
174
* @inheritdoc
141
175
*/
0 commit comments