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

@@ -9,6 +9,7 @@
namespace App\Tests\Controller;
use App\Entity\Tag;
use App\Entity\User;
use App\Tests\DataFixtures\TagFixtures;
@@ -95,4 +96,35 @@ class TagControllerTest extends ControllerBaseTest
$editForm = $client->getCrawler()->filter('form[name=tag_edit_form]')->form();
$this->assertEquals('Test 2 updated', $editForm->get('tag_edit_form[name]')->getValue());
}
public function testMultiDeleteAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->assertAccessIsGranted($client, '/admin/tags/');
$form = $client->getCrawler()->filter('form[name=multi_update_table]')->form();
$node = $form->getFormNode();
$node->setAttribute('action', $this->createUrl('/admin/tags/multi-delete'));
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
/** @var Tag[] $tags */
$tags = $em->getRepository(Tag::class)->findAll();
self::assertCount(10, $tags);
$ids = [];
foreach ($tags as $tag) {
$ids[] = $tag->getId();
}
$client->submit($form, [
'multi_update_table' => [
'action' => $this->createUrl('/admin/tags/multi-delete'),
'entities' => implode(',', $ids)
]
]);
$this->assertIsRedirect($client, $this->createUrl('/admin/tags/'));
$client->followRedirect();
$em->clear(Tag::class);
self::assertEquals(0, $em->getRepository(Tag::class)->count([]));
}
}

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());
}
}
}

View File

@@ -240,4 +240,102 @@ class TimesheetTeamControllerTest extends ControllerBaseTest
$this->assertEquals('foo-bar', $timesheet->getDescription());
$this->assertEquals($teamlead->getId(), $timesheet->getUser()->getId());
}
public function testMultiDeleteAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$user = $this->getUserByRole($em, User::ROLE_TEAMLEAD);
$fixture = new TimesheetFixtures();
$fixture->setAmount(10);
$fixture->setUser($user);
$this->importFixture($em, $fixture);
$this->assertAccessIsGranted($client, '/team/timesheet/');
$form = $client->getCrawler()->filter('form[name=multi_update_table]')->form();
$node = $form->getFormNode();
$node->setAttribute('action', $this->createUrl('/team/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('/team/timesheet/multi-delete'),
'entities' => implode(',', $ids)
]
]);
$this->assertIsRedirect($client, $this->createUrl('/team/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_TEAMLEAD);
$fixture = new TimesheetFixtures();
$fixture->setAmount(10);
$fixture->setUser($user);
$this->importFixture($em, $fixture);
$this->assertAccessIsGranted($client, '/team/timesheet/');
$form = $client->getCrawler()->filter('form[name=multi_update_table]')->form();
$node = $form->getFormNode();
$node->setAttribute('action', $this->createUrl('/team/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::assertFalse($timesheet->isExported());
self::assertEquals($user->getId(), $timesheet->getUser()->getId());
$ids[] = $timesheet->getId();
}
$client->submit($form, [
'multi_update_table' => [
'action' => $this->createUrl('/team/timesheet/multi-update'),
'entities' => implode(',', $ids)
]
]);
$this->assertTrue($client->getResponse()->isSuccessful());
$newUser = $this->getUserByRole($em, User::ROLE_USER);
$form = $client->getCrawler()->filter('form[name=timesheet_multi_update]')->form();
$client->submit($form, [
'timesheet_multi_update' => [
'user' => $newUser->getId(),
'exported' => true,
'replaceTags' => true,
'tags' => 'test, foo-bar, tralalala'
]
]);
$em->clear(Timesheet::class);
/** @var Timesheet[] $timesheets */
$timesheets = $em->getRepository(Timesheet::class)->findAll();
self::assertCount(10, $timesheets);
foreach ($timesheets as $timesheet) {
self::assertCount(3, $timesheet->getTags());
self::assertEquals($newUser->getId(), $timesheet->getUser()->getId());
self::assertTrue($timesheet->isExported());
}
}
}

View File

@@ -164,9 +164,9 @@ class UserControllerTest extends ControllerBaseTest
$this->assertHasFlashDeleteSuccess($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));
// $em->clear(Timesheet::class);
// $timesheets = $em->getRepository(Timesheet::class)->count([]);
// $this->assertEquals(0, $timesheets);
$this->request($client, '/admin/user/' . $user->getId() . '/edit');
$this->assertFalse($client->getResponse()->isSuccessful());