@@ -22,6 +22,7 @@ public function setup()
22
22
'error ' => UPLOAD_ERR_OK ,
23
23
'size ' => 1 ,
24
24
'type ' => 'text ' ,
25
+ 'keepFilesOnDelete ' => false
25
26
]
26
27
];
27
28
$ this ->dataError = [
@@ -201,6 +202,54 @@ public function testBeforeSaveOk()
201
202
$ this ->assertNull ($ behavior ->beforeSave (new Event ('fake.event ' ), $ this ->entity , new ArrayObject ));
202
203
}
203
204
205
+ public function testAfterDeleteOk ()
206
+ {
207
+ $ methods = array_diff ($ this ->behaviorMethods , ['config ' , 'afterDelete ' ]);
208
+ $ behavior = $ this ->getMock ('Josegonzalez\Upload\Model\Behavior\UploadBehavior ' , $ methods , [$ this ->table , $ this ->dataOk ]);
209
+ $ behavior ->config ($ this ->dataOk );
210
+
211
+ $ behavior ->expects ($ this ->any ())
212
+ ->method ('getWriter ' )
213
+ ->will ($ this ->returnValue ($ this ->writer ));
214
+ $ this ->writer ->expects ($ this ->any ())
215
+ ->method ('delete ' )
216
+ ->will ($ this ->returnValue ([true ]));
217
+
218
+ $ this ->assertNull ($ behavior ->afterDelete (new Event ('fake.event ' ), $ this ->entity , new ArrayObject ));
219
+ }
220
+
221
+ public function testAfterDeleteFail ()
222
+ {
223
+ $ methods = array_diff ($ this ->behaviorMethods , ['config ' , 'afterDelete ' ]);
224
+ $ behavior = $ this ->getMock ('Josegonzalez\Upload\Model\Behavior\UploadBehavior ' , $ methods , [$ this ->table , $ this ->dataOk ]);
225
+ $ behavior ->config ($ this ->dataOk );
226
+
227
+ $ behavior ->expects ($ this ->any ())
228
+ ->method ('getWriter ' )
229
+ ->will ($ this ->returnValue ($ this ->writer ));
230
+ $ this ->writer ->expects ($ this ->any ())
231
+ ->method ('delete ' )
232
+ ->will ($ this ->returnValue ([false ]));
233
+
234
+ $ this ->assertFalse ($ behavior ->afterDelete (new Event ('fake.event ' ), $ this ->entity , new ArrayObject ));
235
+ }
236
+
237
+ public function testAfterDeleteSkip ()
238
+ {
239
+ $ methods = array_diff ($ this ->behaviorMethods , ['config ' , 'afterDelete ' ]);
240
+ $ behavior = $ this ->getMock ('Josegonzalez\Upload\Model\Behavior\UploadBehavior ' , $ methods , [$ this ->table , $ this ->dataError ]);
241
+ $ behavior ->config ($ this ->dataError );
242
+
243
+ $ behavior ->expects ($ this ->any ())
244
+ ->method ('getWriter ' )
245
+ ->will ($ this ->returnValue ($ this ->writer ));
246
+ $ this ->writer ->expects ($ this ->any ())
247
+ ->method ('delete ' )
248
+ ->will ($ this ->returnValue ([true ]));
249
+
250
+ $ this ->assertNull ($ behavior ->afterDelete (new Event ('fake.event ' ), $ this ->entity , new ArrayObject ));
251
+ }
252
+
204
253
public function testGetWriter ()
205
254
{
206
255
$ processor = $ this ->behavior ->getWriter ($ this ->entity , [], 'field ' , []);
0 commit comments