22
33namespace Gedmo \SoftDeleteable ;
44
5+ use SoftDeleteable \Fixture \Entity \UserNoHardDelete ;
56use Tool \BaseTestCaseORM ;
67use Doctrine \Common \EventManager ;
78use SoftDeleteable \Fixture \Entity \Article ;
@@ -35,6 +36,7 @@ class SoftDeleteableEntityTest extends BaseTestCaseORM
3536 const USER_CLASS = 'SoftDeleteable\Fixture\Entity\User ' ;
3637 const MAPPED_SUPERCLASS_CHILD_CLASS = 'SoftDeleteable\Fixture\Entity\Child ' ;
3738 const SOFT_DELETEABLE_FILTER_NAME = 'soft-deleteable ' ;
39+ const USER_NO_HARD_DELETE_CLASS = 'SoftDeleteable\Fixture\Entity\UserNoHardDelete ' ;
3840
3941 private $ softDeleteableListener ;
4042
@@ -370,6 +372,42 @@ public function testPostSoftDeleteEventIsDispatched()
370372 $ this ->em ->flush ();
371373 }
372374
375+ /**
376+ * @test
377+ */
378+ public function shouldNotDeleteIfColumnNameDifferFromPropertyName ()
379+ {
380+ $ repo = $ this ->em ->getRepository (self ::USER_NO_HARD_DELETE_CLASS );
381+
382+ $ newUser = new UserNoHardDelete ();
383+ $ username = 'test_user ' ;
384+ $ newUser ->setUsername ($ username );
385+
386+ $ this ->em ->persist ($ newUser );
387+ $ this ->em ->flush ();
388+
389+ $ user = $ repo ->findOneBy (array ('username ' => $ username ));
390+
391+ $ this ->assertNull ($ user ->getDeletedAt ());
392+
393+ $ this ->em ->remove ($ user );
394+ $ this ->em ->flush ();
395+
396+ $ user = $ repo ->findOneBy (array ('username ' => $ username ));
397+ $ this ->assertNull ($ user , "User should be filtered out " );
398+
399+ // now deactivate filter and attempt to hard delete
400+ $ this ->em ->getFilters ()->disable (self ::SOFT_DELETEABLE_FILTER_NAME );
401+ $ user = $ repo ->findOneBy (array ('username ' => $ username ));
402+ $ this ->assertNotNull ($ user , "User should be fetched when filter is disabled " );
403+
404+ $ this ->em ->remove ($ user );
405+ $ this ->em ->flush ();
406+
407+ $ user = $ repo ->findOneBy (array ('username ' => $ username ));
408+ $ this ->assertNotNull ($ user , "User is still available, hard delete done " );
409+ }
410+
373411 protected function getUsedEntityFixtures ()
374412 {
375413 return array (
@@ -382,6 +420,7 @@ protected function getUsedEntityFixtures()
382420 self ::OTHER_ARTICLE_CLASS ,
383421 self ::OTHER_COMMENT_CLASS ,
384422 self ::MAPPED_SUPERCLASS_CHILD_CLASS ,
423+ self ::USER_NO_HARD_DELETE_CLASS ,
385424 );
386425 }
387426}
0 commit comments