option to move entries from one entity to another upon deletion (#409)

This commit is contained in:
Kevin Papst
2018-11-12 00:01:49 +01:00
committed by GitHub
parent 1dabeedaa0
commit f9dc42d1f9
18 changed files with 524 additions and 23 deletions

View File

@@ -9,6 +9,7 @@
namespace App\Tests\Controller\Admin;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Tests\Controller\ControllerBaseTest;
use App\Tests\DataFixtures\CustomerFixtures;
@@ -112,6 +113,14 @@ class CustomerControllerTest extends ControllerBaseTest
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));
/** @var Timesheet $entry */
foreach($timesheets as $entry) {
$this->assertEquals(1, $entry->getActivity()->getId());
}
$this->request($client, '/admin/customer/1/delete');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -124,6 +133,60 @@ class CustomerControllerTest extends ControllerBaseTest
$this->assertHasDataTable($client);
$this->assertHasFlashSuccess($client);
// SQLIte does not necessarly support onCascade delete, so these timesheet will stay after deletion
// $em->clear();
// $timesheets = $em->getRepository(Timesheet::class)->findAll();
// $this->assertEquals(0, count($timesheets));
$this->request($client, '/admin/customer/1/edit');
$this->assertFalse($client->getResponse()->isSuccessful());
}
public function testDeleteActionWithTimesheetEntriesAndReplacement()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$fixture = new CustomerFixtures();
$fixture->setAmount(1)->setIsVisible(true);
$this->importFixture($em, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));
/** @var Timesheet $entry */
foreach($timesheets as $entry) {
$this->assertEquals(1, $entry->getProject()->getCustomer()->getId());
}
$this->request($client, '/admin/customer/1/delete');
$this->assertTrue($client->getResponse()->isSuccessful());
$form = $client->getCrawler()->filter('form[name=form]')->form();
$this->assertStringEndsWith($this->createUrl('/admin/customer/1/delete'), $form->getUri());
$client->submit($form, [
'form' => [
'customer' => 2
]
]);
$this->assertIsRedirect($client, $this->createUrl('/admin/customer/'));
$client->followRedirect();
$this->assertHasDataTable($client);
$this->assertHasFlashSuccess($client);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));
/** @var Timesheet $entry */
foreach($timesheets as $entry) {
$this->assertEquals(2, $entry->getProject()->getCustomer()->getId());
}
$this->request($client, '/admin/customer/1/edit');
$this->assertFalse($client->getResponse()->isSuccessful());
}