Update and delete multi timesheets and tags (#1240)

This commit is contained in:
Kevin Papst
2019-11-15 01:25:31 +01:00
committed by GitHub
parent b4739f8f03
commit 94c28ebbc5
49 changed files with 1836 additions and 307 deletions

View File

@@ -324,4 +324,98 @@ class TimesheetControllerTest extends ControllerBaseTest
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$this->assertEquals('foo-bar', $timesheet->getDescription());
}
public function testMultiDeleteAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$user = $this->getUserByRole($em, User::ROLE_USER);
$fixture = new TimesheetFixtures();
$fixture->setAmount(10);
$fixture->setUser($user);
$this->importFixture($em, $fixture);
$this->assertAccessIsGranted($client, '/timesheet/');
$form = $client->getCrawler()->filter('form[name=multi_update_table]')->form();
$node = $form->getFormNode();
$node->setAttribute('action', $this->createUrl('/timesheet/multi-delete'));
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
/** @var Timesheet[] $timesheets */
$timesheets = $em->getRepository(Timesheet::class)->findAll();
self::assertCount(10, $timesheets);
$ids = [];
foreach ($timesheets as $timesheet) {
$ids[] = $timesheet->getId();
}
$client->submit($form, [
'multi_update_table' => [
'action' => $this->createUrl('/timesheet/multi-delete'),
'entities' => implode(',', $ids)
]
]);
$this->assertIsRedirect($client, $this->createUrl('/timesheet/'));
$client->followRedirect();
$em->clear(Timesheet::class);
self::assertEquals(0, $em->getRepository(Timesheet::class)->count([]));
}
public function testMultiUpdate()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$user = $this->getUserByRole($em, User::ROLE_SUPER_ADMIN);
$fixture = new TimesheetFixtures();
$fixture->setAmount(10);
$fixture->setUser($user);
$this->importFixture($em, $fixture);
$this->assertAccessIsGranted($client, '/timesheet/');
$form = $client->getCrawler()->filter('form[name=multi_update_table]')->form();
$node = $form->getFormNode();
$node->setAttribute('action', $this->createUrl('/timesheet/multi-update'));
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
/** @var Timesheet[] $timesheets */
$timesheets = $em->getRepository(Timesheet::class)->findAll();
self::assertCount(10, $timesheets);
$ids = [];
foreach ($timesheets as $timesheet) {
self::assertEmpty($timesheet->getTags());
self::assertFalse($timesheet->isExported());
$ids[] = $timesheet->getId();
}
$client->submit($form, [
'multi_update_table' => [
'action' => $this->createUrl('/timesheet/multi-update'),
'entities' => implode(',', $ids)
]
]);
$this->assertTrue($client->getResponse()->isSuccessful());
$form = $client->getCrawler()->filter('form[name=timesheet_multi_update]')->form();
$client->submit($form, [
'timesheet_multi_update' => [
'exported' => true,
'tags' => 'test, foo-bar'
]
]);
$em->clear(Timesheet::class);
/** @var Timesheet[] $timesheets */
$timesheets = $em->getRepository(Timesheet::class)->findAll();
self::assertCount(10, $timesheets);
foreach ($timesheets as $timesheet) {
self::assertCount(2, $timesheet->getTags());
self::assertTrue($timesheet->isExported());
}
}
}