@@ -1327,4 +1327,72 @@ public static function htmlFieldSubmissionDataProvider(): array
13271327 ],
13281328 ];
13291329 }
1330+
1331+ public function testAllRelatedEntitiesGetsDeletedIfFormGetsDeleted (): void
1332+ {
1333+ $ payload = [
1334+ 'name ' => 'Submission test form ' ,
1335+ 'description ' => 'Form created via submission test ' ,
1336+ 'formType ' => 'standalone ' ,
1337+ 'isPublished ' => true ,
1338+ 'fields ' => [
1339+ [
1340+ 'label ' => 'Name ' ,
1341+ 'type ' => 'text ' ,
1342+ 'alias ' => 'name ' ,
1343+ ],
1344+ [
1345+ 'label ' => 'Submit ' ,
1346+ 'type ' => 'button ' ,
1347+ ],
1348+ ],
1349+ ];
1350+
1351+ $ this ->client ->request (Request::METHOD_POST , '/api/forms/new ' , $ payload );
1352+ $ clientResponse = $ this ->client ->getResponse ();
1353+ $ response = json_decode ($ clientResponse ->getContent (), true );
1354+ $ formId = $ response ['form ' ]['id ' ];
1355+ $ formAlias = $ response ['form ' ]['alias ' ];
1356+
1357+ $ this ->assertSame (Response::HTTP_CREATED , $ clientResponse ->getStatusCode (), $ clientResponse ->getContent ());
1358+
1359+ // Submit the form:
1360+ $ crawler = $ this ->client ->request (Request::METHOD_GET , "/form/ {$ formId }" );
1361+ $ formCrawler = $ crawler ->filter ('form[id=mauticform_submissiontestform] ' );
1362+ $ this ->assertCount (1 , $ formCrawler );
1363+ $ form = $ formCrawler ->form ();
1364+ $ form ->setValues ([
1365+ 'mauticform[name] ' => 'Name ' ,
1366+ ]);
1367+ $ this ->client ->submit ($ form );
1368+
1369+ $ clientResponse = $ this ->client ->getResponse ();
1370+
1371+ $ this ->assertSame (Response::HTTP_OK , $ clientResponse ->getStatusCode (), $ clientResponse ->getContent ());
1372+
1373+ /** @var SubmissionRepository $submissionRepository */
1374+ $ submissionRepository = $ this ->em ->getRepository (Submission::class);
1375+
1376+ // Ensure the submission was created properly.
1377+ $ submissions = $ submissionRepository ->findBy (['form ' => $ formId ]);
1378+
1379+ Assert::assertCount (1 , $ submissions );
1380+
1381+ // The previous request changes user to anonymous. We have to configure API again.
1382+ $ this ->setUpSymfony ($ this ->configParams );
1383+
1384+ $ this ->client ->request (Request::METHOD_DELETE , "/api/forms/ {$ formId }/delete " );
1385+ $ clientResponse = $ this ->client ->getResponse ();
1386+
1387+ $ this ->assertSame (Response::HTTP_OK , $ clientResponse ->getStatusCode (), $ clientResponse ->getContent ());
1388+
1389+ $ tablePrefix = static ::getContainer ()->getParameter ('mautic.db_table_prefix ' );
1390+
1391+ // we are expecting form results table to be deleted in background, so the table should exists
1392+ $ this ->assertTrue ($ this ->connection ->createSchemaManager ()->tablesExist ("{$ tablePrefix }form_results_ {$ formId }_ {$ formAlias }" ));
1393+
1394+ $ submissions = $ submissionRepository ->findBy (['form ' => $ formId ]);
1395+
1396+ Assert::assertCount (0 , $ submissions );
1397+ }
13301398}
0 commit comments