Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -14,9 +14,10 @@ use App\Entity\Configuration;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\TimesheetMeta;
|
||||
use App\Entity\User;
|
||||
use App\Form\Type\DateRangeType;
|
||||
use App\Repository\ConfigurationRepository;
|
||||
use App\Repository\TagRepository;
|
||||
use App\Tests\DataFixtures\ActivityFixtures;
|
||||
use App\Tests\DataFixtures\TagFixtures;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use App\Tests\Mocks\TimesheetTestMetaFieldSubscriberMock;
|
||||
use App\Timesheet\DateTimeFactory;
|
||||
@@ -26,12 +27,12 @@ use App\Timesheet\DateTimeFactory;
|
||||
*/
|
||||
class TimesheetControllerTest extends ControllerBaseTest
|
||||
{
|
||||
public function testIsSecure()
|
||||
public function testIsSecure(): void
|
||||
{
|
||||
$this->assertUrlIsSecured('/timesheet/');
|
||||
}
|
||||
|
||||
public function testIndexAction()
|
||||
public function testIndexAction(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser();
|
||||
$this->request($client, '/timesheet/');
|
||||
@@ -40,15 +41,12 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
// there are no records by default in the test database
|
||||
$this->assertHasNoEntriesWithFilter($client);
|
||||
$this->assertPageActions($client, [
|
||||
'search' => '#',
|
||||
'visibility' => '#',
|
||||
'download toolbar-action modal-ajax-form' => $this->createUrl('/timesheet/export/'),
|
||||
'download modal-ajax-form' => $this->createUrl('/timesheet/export/'),
|
||||
'create modal-ajax-form' => $this->createUrl('/timesheet/create'),
|
||||
'help' => 'https://www.kimai.org/documentation/timesheet.html'
|
||||
]);
|
||||
}
|
||||
|
||||
public function testIndexActionWithQuery()
|
||||
public function testIndexActionWithQuery(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$start = new \DateTime('first day of this month');
|
||||
@@ -63,7 +61,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->request($client, '/timesheet/');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$dateRange = ($start)->format('Y-m-d') . DateRangeType::DATE_SPACER . (new \DateTime('last day of this month'))->format('Y-m-d');
|
||||
$dateRange = $this->formatDateRange($start, new \DateTime('last day of this month'));
|
||||
|
||||
$form = $client->getCrawler()->filter('form.searchform')->form();
|
||||
$client->submit($form, [
|
||||
@@ -84,7 +82,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
self::assertEquals(2, $node->count());
|
||||
}
|
||||
|
||||
public function testIndexActionWithSearchTermQuery()
|
||||
public function testIndexActionWithSearchTermQuery(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$start = new \DateTime('first day of this month');
|
||||
@@ -109,8 +107,6 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->request($client, '/timesheet/');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$dateRange = ($start)->format('Y-m-d') . DateRangeType::DATE_SPACER . (new \DateTime('last day of this month'))->format('Y-m-d');
|
||||
|
||||
$form = $client->getCrawler()->filter('form.searchform')->form();
|
||||
$client->submit($form, [
|
||||
'searchTerm' => 'location:homeoffice foobar',
|
||||
@@ -121,10 +117,23 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertDataTableRowCount($client, 'datatable_timesheet', 5);
|
||||
}
|
||||
|
||||
public function testExportAction()
|
||||
public function testExportAction(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser();
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(15);
|
||||
$fixture->setUser($this->getUserByRole(User::ROLE_USER));
|
||||
$fixture->setCallback(function (Timesheet $timesheet) {
|
||||
$duration = rand(3600, 36000);
|
||||
$begin = new \DateTime('-15 days');
|
||||
$end = clone $begin;
|
||||
$end->modify('+' . $duration . ' seconds');
|
||||
$timesheet->setBegin($begin);
|
||||
$timesheet->setEnd($end);
|
||||
});
|
||||
$this->importFixture($fixture);
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(5);
|
||||
$fixture->setUser($this->getUserByRole(User::ROLE_USER));
|
||||
@@ -134,14 +143,12 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->request($client, '/timesheet/export/');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$dateRange = (new \DateTime('-10 days'))->format('Y-m-d') . DateRangeType::DATE_SPACER . (new \DateTime())->format('Y-m-d');
|
||||
$dateRange = $this->formatDateRange(new \DateTime('-10 days'), new \DateTime());
|
||||
|
||||
$client->submitForm('export-btn-print', [
|
||||
'export' => [
|
||||
'state' => 1,
|
||||
'daterange' => $dateRange,
|
||||
'customers' => [],
|
||||
]
|
||||
'state' => 1,
|
||||
'daterange' => $dateRange,
|
||||
'customers' => [],
|
||||
]);
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
@@ -155,7 +162,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(5, \count($result));
|
||||
}
|
||||
|
||||
public function testCreateAction()
|
||||
public function testCreateAction(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser();
|
||||
$this->request($client, '/timesheet/create');
|
||||
@@ -168,8 +175,8 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
// begin is always pre-filled with the current datetime
|
||||
// 'begin' => null,
|
||||
// end must be allowed to be null, to start a record
|
||||
// there was a bug with end begin required, so we manually set this field to be empty
|
||||
'end' => null,
|
||||
// there was a bug with end a mandatory field, so we manually set this field to be empty
|
||||
'end_time' => null,
|
||||
'project' => 1,
|
||||
'activity' => 1,
|
||||
]
|
||||
@@ -194,7 +201,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
/**
|
||||
* @dataProvider getTestDataForDurationValues
|
||||
*/
|
||||
public function testCreateActionWithDurationValues($begin, $end, $duration, $expectedDuration, $expectedEnd)
|
||||
public function testCreateActionWithDurationValues($beginDate, $beginTime, $end, $duration, $expectedDuration, $expectedEnd): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser();
|
||||
$this->request($client, '/timesheet/create');
|
||||
@@ -204,8 +211,9 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$client->submit($form, [
|
||||
'timesheet_edit_form' => [
|
||||
'description' => 'Testing is fun!',
|
||||
'begin' => $begin,
|
||||
'end' => $end,
|
||||
'begin_date' => $beginDate,
|
||||
'begin_time' => $beginTime,
|
||||
'end_time' => $end,
|
||||
'duration' => $duration,
|
||||
'project' => 1,
|
||||
'activity' => 1,
|
||||
@@ -227,32 +235,32 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals('Testing is fun!', $timesheet->getDescription());
|
||||
}
|
||||
|
||||
public function getTestDataForDurationValues()
|
||||
public function getTestDataForDurationValues(): \Generator
|
||||
{
|
||||
// duration is ignored, because end is set and the duration might come from a rounding rule (by default seconds are rounded down with 1)
|
||||
yield ['2018-12-31 00:00:00', '2018-12-31 02:10:10', '01:00', 7800, '2018-12-31 02:10:00'];
|
||||
yield ['2018-12-31 00:00:00', '2018-12-31 02:09:59', '01:00', 7740, '2018-12-31 02:09:00'];
|
||||
// if seconds are given, they are first rounded up (default for duration rounding is 1)
|
||||
yield ['2018-12-31 00:00:00', null, '01:00', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '01:00:10', 3660, '2018-12-31 01:01:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '1h', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '1h10m', 4200, '2018-12-31 01:10:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '1h10s', 3660, '2018-12-31 01:01:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '60m', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '60M1s', 3660, '2018-12-31 01:01:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '3600s', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '59m60s', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '1', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '1,0', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '1.0', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '1.5', 5400, '2018-12-31 01:30:00'];
|
||||
yield ['2018-12-31 00:00:00', null, '1,25', 4500, '2018-12-31 01:15:00'];
|
||||
yield ['12/31/2018', '12:00 AM', '02:10 AM', '01:00', 7800, '2018-12-31 02:10:00'];
|
||||
yield ['12/31/2018', '12:00 AM', '02:09 AM', '01:00', 7740, '2018-12-31 02:09:00'];
|
||||
// if seconds are given: they are first rounded up (default for duration rounding is 1)
|
||||
yield ['12/31/2018', '12:00 AM', null, '01:00', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '01:00:10', 3660, '2018-12-31 01:01:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '1h', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '1h10m', 4200, '2018-12-31 01:10:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '1h10s', 3660, '2018-12-31 01:01:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '60m', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '60M1s', 3660, '2018-12-31 01:01:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '3600s', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '59m60s', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '1', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '1,0', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '1.0', 3600, '2018-12-31 01:00:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '1.5', 5400, '2018-12-31 01:30:00'];
|
||||
yield ['12/31/2018', '12:00 AM', null, '1,25', 4500, '2018-12-31 01:15:00'];
|
||||
}
|
||||
|
||||
public function testCreateActionShowsMetaFields()
|
||||
public function testCreateActionShowsMetaFields(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser();
|
||||
static::$kernel->getContainer()->get('event_dispatcher')->addSubscriber(new TimesheetTestMetaFieldSubscriberMock());
|
||||
self::getContainer()->get('event_dispatcher')->addSubscriber(new TimesheetTestMetaFieldSubscriberMock());
|
||||
$this->request($client, '/timesheet/create');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
@@ -262,7 +270,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertFalse($form->has('timesheet_edit_form[metaFields][0][value]'));
|
||||
}
|
||||
|
||||
public function testCreateActionDoesNotShowRateFieldsForUser()
|
||||
public function testCreateActionDoesNotShowRateFieldsForUser(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser();
|
||||
$this->request($client, '/timesheet/create');
|
||||
@@ -273,7 +281,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertFalse($form->has('fixedRate'));
|
||||
}
|
||||
|
||||
public function testCreateActionWithFromAndToValues()
|
||||
public function testCreateActionWithFromAndToValues(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->request($client, '/timesheet/create?from=2018-08-02T20%3A00%3A00&to=2018-08-02T20%3A30%3A00');
|
||||
@@ -307,7 +315,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals($expected->format(\DateTimeInterface::ATOM), $timesheet->getEnd()->format(\DateTimeInterface::ATOM));
|
||||
}
|
||||
|
||||
public function testCreateActionWithFromAndToValuesTwice()
|
||||
public function testCreateActionWithFromAndToValuesTwice(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->request($client, '/timesheet/create?from=2018-08-02T20%3A00%3A00&to=2018-08-02T20%3A30%3A00');
|
||||
@@ -358,7 +366,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertHasFlashSuccess($client);
|
||||
}
|
||||
|
||||
public function testCreateActionWithFromAndToValuesTwiceFailsOnOverlappingRecord()
|
||||
public function testCreateActionWithFromAndToValuesTwiceFailsOnOverlappingRecord(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/system-config/');
|
||||
@@ -368,7 +376,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
'system_configuration_form_timesheet' => [
|
||||
'configuration' => [
|
||||
['name' => 'timesheet.mode', 'value' => 'default'],
|
||||
['name' => 'timesheet.active_entries.default_begin', 'value' => '08:00'],
|
||||
['name' => 'timesheet.default_begin', 'value' => '08:00'],
|
||||
['name' => 'timesheet.rules.allow_future_times', 'value' => true],
|
||||
['name' => 'timesheet.rules.allow_zero_duration', 'value' => true],
|
||||
['name' => 'timesheet.rules.allow_overlapping_records', 'value' => false],
|
||||
@@ -402,11 +410,11 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
'activity' => 1,
|
||||
]
|
||||
],
|
||||
['#timesheet_edit_form_begin']
|
||||
['#timesheet_edit_form_begin_date']
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateActionWithOverbookedActivity()
|
||||
public function testCreateActionWithOverbookedActivity(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
|
||||
@@ -448,8 +456,9 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
[
|
||||
'timesheet_edit_form' => [
|
||||
'hourlyRate' => 100,
|
||||
'begin' => '2020-02-18 01:00',
|
||||
'end' => '2020-02-18 02:10',
|
||||
'begin_date' => '02/18/2020',
|
||||
'begin_time' => '01:00 AM',
|
||||
'end_time' => '02:10 AM',
|
||||
'duration' => '01:10',
|
||||
'project' => 1,
|
||||
'activity' => $activity->getId(),
|
||||
@@ -459,7 +468,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateActionWithEmptyDuration()
|
||||
public function testCreateActionWithEmptyDuration(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
|
||||
@@ -501,8 +510,9 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
[
|
||||
'timesheet_edit_form' => [
|
||||
'hourlyRate' => 100,
|
||||
'begin' => '2020-02-18 01:00',
|
||||
'end' => '2020-02-18 01:00',
|
||||
'begin_date' => '02/18/2020',
|
||||
'begin_time' => '01:00 AM',
|
||||
'end_time' => '01:00 AM',
|
||||
'duration' => '00:00',
|
||||
'project' => 1,
|
||||
'activity' => $activity->getId(),
|
||||
@@ -512,9 +522,14 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateActionWithBeginAndEndAndTagValues()
|
||||
public function testCreateActionWithBeginAndEndAndTagValues(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
$fixture = new TagFixtures();
|
||||
$fixture->importAmount(TagRepository::MAX_AMOUNT_SELECT);
|
||||
$this->importFixture($fixture);
|
||||
|
||||
$this->request($client, '/timesheet/create?begin=2018-08-02&end=2018-08-02&tags=one,two,three');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
@@ -548,7 +563,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(['one', 'two', 'three'], $timesheet->getTagsAsArray());
|
||||
}
|
||||
|
||||
public function testCreateActionWithDescription()
|
||||
public function testCreateActionWithDescription(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
@@ -575,7 +590,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals('Lorem Ipsum', $timesheet->getDescription());
|
||||
}
|
||||
|
||||
public function testCreateActionWithDescriptionHtmlInjection()
|
||||
public function testCreateActionWithDescriptionHtmlInjection(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
@@ -602,10 +617,12 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals('Some text"><bold>HelloWorld</bold>', $timesheet->getDescription());
|
||||
}
|
||||
|
||||
public function testEditAction()
|
||||
public function testEditAction(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser();
|
||||
|
||||
$this->setSystemConfiguration('timesheet.rules.long_running_duration', '1440');
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(1);
|
||||
$fixture->setUser($this->getUserByRole(User::ROLE_USER));
|
||||
@@ -613,6 +630,10 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$timesheets = $this->importFixture($fixture);
|
||||
$id = $timesheets[0]->getId();
|
||||
|
||||
$fixture = new TagFixtures();
|
||||
$fixture->importAmount(TagRepository::MAX_AMOUNT_SELECT);
|
||||
$this->importFixture($fixture);
|
||||
|
||||
$this->request($client, '/timesheet/' . $id . '/edit');
|
||||
|
||||
$response = $client->getResponse();
|
||||
@@ -643,7 +664,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals('foo-bar', $timesheet->getDescription());
|
||||
}
|
||||
|
||||
public function testMultiDeleteAction()
|
||||
public function testMultiDeleteAction(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
|
||||
@@ -670,7 +691,6 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
|
||||
$client->submit($form, [
|
||||
'multi_update_table' => [
|
||||
'action' => $this->createUrl('/timesheet/multi-delete'),
|
||||
'entities' => implode(',', $ids)
|
||||
]
|
||||
]);
|
||||
@@ -681,7 +701,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
self::assertEquals(0, $em->getRepository(Timesheet::class)->count([]));
|
||||
}
|
||||
|
||||
public function testMultiUpdate()
|
||||
public function testMultiUpdate(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
|
||||
@@ -691,6 +711,10 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$fixture->setUser($user);
|
||||
$this->importFixture($fixture);
|
||||
|
||||
$fixture = new TagFixtures();
|
||||
$fixture->importAmount(TagRepository::MAX_AMOUNT_SELECT);
|
||||
$this->importFixture($fixture);
|
||||
|
||||
$this->assertAccessIsGranted($client, '/timesheet/');
|
||||
|
||||
$form = $client->getCrawler()->filter('form[name=multi_update_table]')->form();
|
||||
@@ -707,10 +731,9 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
self::assertFalse($timesheet->isExported());
|
||||
$ids[] = $timesheet->getId();
|
||||
}
|
||||
|
||||
// FIXME
|
||||
$client->submit($form, [
|
||||
'multi_update_table' => [
|
||||
'action' => $this->createUrl('/timesheet/multi-update'),
|
||||
'entities' => implode(',', $ids)
|
||||
]
|
||||
]);
|
||||
@@ -737,7 +760,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
}
|
||||
}
|
||||
|
||||
public function testDuplicateAction()
|
||||
public function testDuplicateAction(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$dateTime = new DateTimeFactory(new \DateTimeZone('Europe/London'));
|
||||
|
||||
Reference in New Issue
Block a user