added API for handling work contract times (#4016)
This commit is contained in:
45
tests/Controller/ContractControllerTest.php
Normal file
45
tests/Controller/ContractControllerTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class ContractControllerTest extends ControllerBaseTest
|
||||
{
|
||||
public function testIsSecure(): void
|
||||
{
|
||||
$this->assertUrlIsSecured('/contract');
|
||||
}
|
||||
|
||||
public function testIndexAction(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/contract');
|
||||
$content = $client->getResponse()->getContent();
|
||||
self::assertNotFalse($content);
|
||||
self::assertStringContainsString('No target hours have been configured', $content);
|
||||
$node = $client->getCrawler()->filter('select#user');
|
||||
self::assertEquals(0, $node->count());
|
||||
}
|
||||
|
||||
public function testAdminCanChangeUser(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/contract');
|
||||
$content = $client->getResponse()->getContent();
|
||||
self::assertNotFalse($content);
|
||||
self::assertStringContainsString('No target hours have been configured', $content);
|
||||
$node = $client->getCrawler()->filter('select#user');
|
||||
self::assertEquals(1, $node->count());
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class PermissionControllerTest extends ControllerBaseTest
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/permissions');
|
||||
$this->assertHasDataTable($client);
|
||||
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 129);
|
||||
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 130);
|
||||
$this->assertPageActions($client, [
|
||||
'create modal-ajax-form' => $this->createUrl('/admin/permissions/roles/create'),
|
||||
]);
|
||||
|
||||
@@ -541,4 +541,56 @@ class ProfileControllerTest extends ControllerBaseTest
|
||||
{
|
||||
$this->assertUrlIsSecured('/profile/' . UserFixtures::USERNAME_USER . '/2fa_deactivate', 'POST');
|
||||
}
|
||||
|
||||
public function testContractActionIsSecured(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$this->request($client, '/profile/' . UserFixtures::USERNAME_USER . '/contract');
|
||||
$this->assertFalse($client->getResponse()->isSuccessful());
|
||||
}
|
||||
|
||||
public function testContractAction(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->request($client, '/profile/' . UserFixtures::USERNAME_USER . '/contract');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$user = $this->getUserByRole(User::ROLE_USER);
|
||||
|
||||
$this->assertEquals(0, $user->getWorkHoursMonday());
|
||||
$this->assertEquals(0, $user->getWorkHoursTuesday());
|
||||
$this->assertEquals(0, $user->getWorkHoursWednesday());
|
||||
$this->assertEquals(0, $user->getWorkHoursThursday());
|
||||
$this->assertEquals(0, $user->getWorkHoursFriday());
|
||||
$this->assertEquals(0, $user->getWorkHoursSaturday());
|
||||
$this->assertEquals(0, $user->getWorkHoursSunday());
|
||||
|
||||
$form = $client->getCrawler()->filter('form[name=user_contract]')->form();
|
||||
|
||||
$client->submit($form, [
|
||||
'user_contract[workHoursMonday]' => '1:00',
|
||||
'user_contract[workHoursTuesday]' => '2:00',
|
||||
'user_contract[workHoursWednesday]' => '3:00',
|
||||
'user_contract[workHoursThursday]' => '4:30',
|
||||
'user_contract[workHoursFriday]' => '5:12',
|
||||
'user_contract[workHoursSaturday]' => '6:59',
|
||||
'user_contract[workHoursSunday]' => '0:01',
|
||||
]);
|
||||
|
||||
$this->assertIsRedirect($client, $this->createUrl('/profile/' . urlencode(UserFixtures::USERNAME_USER) . '/contract'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$this->assertHasFlashSuccess($client);
|
||||
|
||||
$user = $this->getUserByRole(User::ROLE_USER);
|
||||
|
||||
$this->assertEquals(3600, $user->getWorkHoursMonday());
|
||||
$this->assertEquals(7200, $user->getWorkHoursTuesday());
|
||||
$this->assertEquals(10800, $user->getWorkHoursWednesday());
|
||||
$this->assertEquals(16200, $user->getWorkHoursThursday());
|
||||
$this->assertEquals(18720, $user->getWorkHoursFriday());
|
||||
$this->assertEquals(25140, $user->getWorkHoursSaturday());
|
||||
$this->assertEquals(60, $user->getWorkHoursSunday());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,9 +67,52 @@ class UserTest extends TestCase
|
||||
|
||||
$user->setAccountNumber('A-058375');
|
||||
self::assertEquals('A-058375', $user->getAccountNumber());
|
||||
|
||||
self::assertEquals(0, $user->getWorkHoursMonday());
|
||||
self::assertEquals(0, $user->getWorkHoursTuesday());
|
||||
self::assertEquals(0, $user->getWorkHoursWednesday());
|
||||
self::assertEquals(0, $user->getWorkHoursThursday());
|
||||
self::assertEquals(0, $user->getWorkHoursFriday());
|
||||
self::assertEquals(0, $user->getWorkHoursSaturday());
|
||||
self::assertEquals(0, $user->getWorkHoursSunday());
|
||||
self::assertEquals(0, $user->getHolidaysPerYear());
|
||||
self::assertFalse($user->hasWorkHourConfiguration());
|
||||
}
|
||||
|
||||
public function testColor()
|
||||
public function testWorkContract(): void
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$user->setWorkHoursMonday(7200);
|
||||
self::assertTrue($user->hasWorkHourConfiguration());
|
||||
$user->setWorkHoursTuesday(7300);
|
||||
$user->setWorkHoursWednesday(7400);
|
||||
$user->setWorkHoursThursday(7500);
|
||||
$user->setWorkHoursFriday(7600);
|
||||
$user->setWorkHoursSaturday(7700);
|
||||
$user->setWorkHoursSunday(7800);
|
||||
$user->setHolidaysPerYear(10);
|
||||
self::assertTrue($user->hasWorkHourConfiguration());
|
||||
|
||||
self::assertEquals(7200, $user->getWorkHoursMonday());
|
||||
self::assertEquals(7300, $user->getWorkHoursTuesday());
|
||||
self::assertEquals(7400, $user->getWorkHoursWednesday());
|
||||
self::assertEquals(7500, $user->getWorkHoursThursday());
|
||||
self::assertEquals(7600, $user->getWorkHoursFriday());
|
||||
self::assertEquals(7700, $user->getWorkHoursSaturday());
|
||||
self::assertEquals(7800, $user->getWorkHoursSunday());
|
||||
self::assertEquals(10, $user->getHolidaysPerYear());
|
||||
|
||||
self::assertEquals(7200, $user->getWorkHoursForDay(new \DateTime('2023-05-08 12:00:00', new \DateTimeZone('Europe/Berlin'))));
|
||||
self::assertEquals(7300, $user->getWorkHoursForDay(new \DateTime('2023-05-09 12:00:00', new \DateTimeZone('Europe/Berlin'))));
|
||||
self::assertEquals(7400, $user->getWorkHoursForDay(new \DateTime('2023-05-10 12:00:00', new \DateTimeZone('Europe/Berlin'))));
|
||||
self::assertEquals(7500, $user->getWorkHoursForDay(new \DateTime('2023-05-11 12:00:00', new \DateTimeZone('Europe/Berlin'))));
|
||||
self::assertEquals(7600, $user->getWorkHoursForDay(new \DateTime('2023-05-12 12:00:00', new \DateTimeZone('Europe/Berlin'))));
|
||||
self::assertEquals(7700, $user->getWorkHoursForDay(new \DateTime('2023-05-13 12:00:00', new \DateTimeZone('Europe/Berlin'))));
|
||||
self::assertEquals(7800, $user->getWorkHoursForDay(new \DateTime('2023-05-14 12:00:00', new \DateTimeZone('Europe/Berlin'))));
|
||||
}
|
||||
|
||||
public function testColor(): void
|
||||
{
|
||||
$sut = new User();
|
||||
self::assertNull($sut->getColor());
|
||||
|
||||
54
tests/Entity/WorkingTimeTest.php
Normal file
54
tests/Entity/WorkingTimeTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\WorkingTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\WorkingTime
|
||||
*/
|
||||
class WorkingTimeTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues(): void
|
||||
{
|
||||
$user = new User();
|
||||
$user->setUsername('bar');
|
||||
$date = new \DateTime();
|
||||
$sut = new WorkingTime($user, $date);
|
||||
|
||||
self::assertSame($user, $sut->getUser());
|
||||
self::assertSame($date, $sut->getDate());
|
||||
|
||||
self::assertNull($sut->getId());
|
||||
|
||||
self::assertEquals(0, $sut->getActualTime());
|
||||
self::assertEquals(0, $sut->getExpectedTime());
|
||||
self::assertNull($sut->getApprovedAt());
|
||||
self::assertNull($sut->getApprovedBy());
|
||||
self::assertFalse($sut->isApproved());
|
||||
|
||||
$approvedAt = new \DateTime('2023-01-01 12:00:00', new \DateTimeZone('Europe/Vienna'));
|
||||
$approvedBy = new User();
|
||||
$approvedBy->setUsername('foo');
|
||||
|
||||
$sut->setApprovedAt($approvedAt);
|
||||
$sut->setApprovedBy($approvedBy);
|
||||
$sut->setActualTime(5600);
|
||||
$sut->setExpectedTime(8600);
|
||||
|
||||
self::assertSame(5600, $sut->getActualTime());
|
||||
self::assertSame(8600, $sut->getExpectedTime());
|
||||
self::assertSame($approvedAt, $sut->getApprovedAt());
|
||||
self::assertSame($approvedBy, $sut->getApprovedBy());
|
||||
self::assertTrue($sut->isApproved());
|
||||
}
|
||||
}
|
||||
36
tests/Event/WorkContractDetailControllerEventTest.php
Normal file
36
tests/Event/WorkContractDetailControllerEventTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Event;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Event\WorkContractDetailControllerEvent;
|
||||
use App\WorkingTime\Model\Year;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Event\WorkContractDetailControllerEvent
|
||||
*/
|
||||
class WorkContractDetailControllerEventTest extends TestCase
|
||||
{
|
||||
public function testGetter(): void
|
||||
{
|
||||
$user = new User();
|
||||
$date = new \DateTime('2023-02-10');
|
||||
$year = new Year($date, $user);
|
||||
$sut = new WorkContractDetailControllerEvent($year);
|
||||
|
||||
self::assertSame($year, $sut->getYear());
|
||||
self::assertEquals([], $sut->getController());
|
||||
|
||||
$sut->addController('foo');
|
||||
$sut->addController('bar');
|
||||
self::assertEquals(['foo', 'bar'], $sut->getController());
|
||||
}
|
||||
}
|
||||
43
tests/Event/WorkingTimeYearSummaryEventTest.php
Normal file
43
tests/Event/WorkingTimeYearSummaryEventTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Event;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Event\WorkingTimeYearSummaryEvent;
|
||||
use App\WorkingTime\Model\Year;
|
||||
use App\WorkingTime\Model\YearPerUserSummary;
|
||||
use App\WorkingTime\Model\YearSummary;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Event\WorkingTimeYearSummaryEvent
|
||||
*/
|
||||
class WorkingTimeYearSummaryEventTest extends TestCase
|
||||
{
|
||||
public function testGetter(): void
|
||||
{
|
||||
$user = new User();
|
||||
$date = new \DateTime('2023-02-10');
|
||||
$year = new Year($date, $user);
|
||||
$until = new \DateTimeImmutable();
|
||||
$yearPerUser = new YearPerUserSummary($year);
|
||||
$sut = new WorkingTimeYearSummaryEvent($yearPerUser, $until);
|
||||
|
||||
self::assertSame($year, $sut->getYear());
|
||||
self::assertSame($until, $sut->getUntil());
|
||||
|
||||
$month = new \DateTime('2023-04-10');
|
||||
$holiday = new YearSummary($month, 'holiday');
|
||||
$sut->addSummary($holiday);
|
||||
$sickness = new YearSummary($month, 'sickness');
|
||||
$sut->addSummary($sickness);
|
||||
self::assertEquals([$holiday, $sickness], $yearPerUser->getSummaries());
|
||||
}
|
||||
}
|
||||
26
tests/Model/DayTest.php
Normal file
26
tests/Model/DayTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Model\Day;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Day
|
||||
*/
|
||||
class DayTest extends TestCase
|
||||
{
|
||||
public function testDefaults(): void
|
||||
{
|
||||
$date = new \DateTimeImmutable('2023-07-21');
|
||||
$sut = new Day($date);
|
||||
self::assertSame($date, $sut->getDay());
|
||||
}
|
||||
}
|
||||
32
tests/Model/MonthTest.php
Normal file
32
tests/Model/MonthTest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Model\Month;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Month
|
||||
*/
|
||||
class MonthTest extends TestCase
|
||||
{
|
||||
public function testDefaults(): void
|
||||
{
|
||||
$months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
||||
foreach($months as $key => $days) {
|
||||
$index = ++$key;
|
||||
$monthKey = ($index < 10) ? '0' . $index : $index;
|
||||
$date = new \DateTimeImmutable(sprintf('2020-%s-25 13:00:00', $monthKey));
|
||||
$month = new Month($date);
|
||||
self::assertEquals(sprintf('2020-%s-25', $monthKey), $month->getMonth()->format('Y-m-d'));
|
||||
self::assertCount($days, $month->getDays());
|
||||
}
|
||||
}
|
||||
}
|
||||
35
tests/Model/YearTest.php
Normal file
35
tests/Model/YearTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Model\Year;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Year
|
||||
*/
|
||||
class YearTest extends TestCase
|
||||
{
|
||||
public function testDefaults(): void
|
||||
{
|
||||
$date = new \DateTimeImmutable('2020-03-14 13:00:00');
|
||||
$sut = new Year($date);
|
||||
self::assertCount(12, $sut->getMonths());
|
||||
self::assertSame($date, $sut->getYear());
|
||||
$months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
||||
foreach($months as $key => $days) {
|
||||
$index = ++$key;
|
||||
$monthKey = ($index < 10) ? '0' . $index : $index;
|
||||
$month = $sut->getMonth(new \DateTimeImmutable(sprintf('2020-%s-13 13:00:00', $monthKey)));
|
||||
self::assertEquals(sprintf('2020-%s-01', $monthKey), $month->getMonth()->format('Y-m-d'));
|
||||
self::assertCount($days, $month->getDays());
|
||||
}
|
||||
}
|
||||
}
|
||||
37
tests/WorkingTime/Model/BoxConfigurationTest.php
Normal file
37
tests/WorkingTime/Model/BoxConfigurationTest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\WorkingTime\Model;
|
||||
|
||||
use App\WorkingTime\Model\BoxConfiguration;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\WorkingTime\Model\BoxConfiguration
|
||||
*/
|
||||
class BoxConfigurationTest extends TestCase
|
||||
{
|
||||
public function testDefaults(): void
|
||||
{
|
||||
$sut = new BoxConfiguration();
|
||||
self::assertFalse($sut->isDecimal());
|
||||
self::assertFalse($sut->isCollapsed());
|
||||
}
|
||||
|
||||
public function testSetter(): void
|
||||
{
|
||||
$sut = new BoxConfiguration();
|
||||
$sut->setDecimal(true);
|
||||
self::assertTrue($sut->isDecimal());
|
||||
self::assertFalse($sut->isCollapsed());
|
||||
$sut->setCollapsed(true);
|
||||
self::assertTrue($sut->isDecimal());
|
||||
self::assertTrue($sut->isCollapsed());
|
||||
}
|
||||
}
|
||||
35
tests/WorkingTime/Model/DayTest.php
Normal file
35
tests/WorkingTime/Model/DayTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\WorkingTime\Model;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\WorkingTime;
|
||||
use App\WorkingTime\Model\Day;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\WorkingTime\Model\Day
|
||||
*/
|
||||
class DayTest extends TestCase
|
||||
{
|
||||
public function testDefaults(): void
|
||||
{
|
||||
$sut = new Day(new \DateTimeImmutable());
|
||||
self::assertNull($sut->getWorkingTime());
|
||||
}
|
||||
|
||||
public function testSetter(): void
|
||||
{
|
||||
$sut = new Day(new \DateTimeImmutable());
|
||||
$workingTime = new WorkingTime(new User(), new \DateTimeImmutable());
|
||||
$sut->setWorkingTime($workingTime);
|
||||
self::assertSame($workingTime, $sut->getWorkingTime());
|
||||
}
|
||||
}
|
||||
35
tests/WorkingTime/Model/MonthSummaryTest.php
Normal file
35
tests/WorkingTime/Model/MonthSummaryTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\WorkingTime\Model;
|
||||
|
||||
use App\WorkingTime\Model\MonthSummary;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\WorkingTime\Model\MonthSummary
|
||||
*/
|
||||
class MonthSummaryTest extends TestCase
|
||||
{
|
||||
public function testDefaults(): void
|
||||
{
|
||||
$sut = new MonthSummary(new \DateTimeImmutable());
|
||||
self::assertEquals(0, $sut->getExpectedTime());
|
||||
self::assertEquals(0, $sut->getActualTime());
|
||||
}
|
||||
|
||||
public function testSetter(): void
|
||||
{
|
||||
$sut = new MonthSummary(new \DateTimeImmutable());
|
||||
$sut->setExpectedTime(98765);
|
||||
$sut->setActualTime(123456);
|
||||
self::assertEquals(98765, $sut->getExpectedTime());
|
||||
self::assertEquals(123456, $sut->getActualTime());
|
||||
}
|
||||
}
|
||||
56
tests/WorkingTime/Model/MonthTest.php
Normal file
56
tests/WorkingTime/Model/MonthTest.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\WorkingTime\Model;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\WorkingTime;
|
||||
use App\WorkingTime\Model\Day;
|
||||
use App\WorkingTime\Model\Month;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\WorkingTime\Model\Month
|
||||
*/
|
||||
class MonthTest extends TestCase
|
||||
{
|
||||
public function testDefaults(): void
|
||||
{
|
||||
$months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
||||
foreach($months as $key => $days) {
|
||||
$index = ++$key;
|
||||
$monthKey = ($index < 10) ? '0' . $index : $index;
|
||||
$date = new \DateTimeImmutable(sprintf('2020-%s-25 13:00:00', $monthKey));
|
||||
$month = new Month($date);
|
||||
self::assertEquals(sprintf('2020-%s-25', $monthKey), $month->getMonth()->format('Y-m-d'));
|
||||
self::assertCount($days, $month->getDays());
|
||||
self::assertTrue($month->isLocked());
|
||||
self::assertEquals(0, $month->getActualTime());
|
||||
self::assertEquals(0, $month->getExpectedTime(new \DateTimeImmutable('2035-01-02')));
|
||||
self::assertNull($month->getLockDate());
|
||||
self::assertNull($month->getLockedBy());
|
||||
foreach ($month->getDays() as $day) {
|
||||
self::assertInstanceOf(Day::class, $day);
|
||||
self::assertNull($day->getWorkingTime());
|
||||
|
||||
$duration = rand(0, 28000);
|
||||
$expected = rand(0, 28000);
|
||||
|
||||
$workingTime = new WorkingTime(new User(), $day->getDay());
|
||||
$workingTime->setExpectedTime($expected);
|
||||
$workingTime->setActualTime($duration);
|
||||
$day->setWorkingTime($workingTime);
|
||||
|
||||
self::assertSame($workingTime, $day->getWorkingTime());
|
||||
self::assertEquals($expected, $day->getWorkingTime()->getExpectedTime());
|
||||
self::assertEquals($duration, $day->getWorkingTime()->getActualTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
65
tests/WorkingTime/Model/YearPerUserSummaryTest.php
Normal file
65
tests/WorkingTime/Model/YearPerUserSummaryTest.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\WorkingTime\Model;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\WorkingTime\Model\Year;
|
||||
use App\WorkingTime\Model\YearPerUserSummary;
|
||||
use App\WorkingTime\Model\YearSummary;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\WorkingTime\Model\YearPerUserSummary
|
||||
*/
|
||||
class YearPerUserSummaryTest extends TestCase
|
||||
{
|
||||
public function testDefaults(): void
|
||||
{
|
||||
$monthDate = new \DateTimeImmutable();
|
||||
$user = new User();
|
||||
$user->setUserIdentifier('foooo');
|
||||
$year = new Year($monthDate, $user);
|
||||
$sut = new YearPerUserSummary($year);
|
||||
|
||||
self::assertSame($year, $sut->getYear());
|
||||
self::assertSame($user, $sut->getUser());
|
||||
self::assertEquals(0, $sut->getExpectedTime());
|
||||
self::assertEquals(0, $sut->getActualTime());
|
||||
self::assertEquals(0, $sut->count());
|
||||
self::assertEquals([], $sut->getSummaries());
|
||||
}
|
||||
|
||||
public function testWithSummary(): void
|
||||
{
|
||||
$monthDate = new \DateTimeImmutable();
|
||||
$user = new User();
|
||||
$user->setUserIdentifier('foooo');
|
||||
$year = new Year($monthDate, $user);
|
||||
$sut = new YearPerUserSummary($year);
|
||||
|
||||
$summary = new YearSummary($monthDate, 'Foo-Bar');
|
||||
|
||||
$monthSummary = $summary->getMonth(new \DateTimeImmutable('2020-04-27'));
|
||||
$monthSummary->setActualTime(35679);
|
||||
$monthSummary->setExpectedTime(135679);
|
||||
|
||||
$monthSummary = $summary->getMonth(new \DateTimeImmutable('2020-07-27'));
|
||||
$monthSummary->setActualTime(95679);
|
||||
$monthSummary->setExpectedTime(235679);
|
||||
|
||||
$sut->addSummary($summary);
|
||||
|
||||
self::assertEquals(131358, $sut->getActualTime());
|
||||
self::assertEquals(371358, $sut->getExpectedTime());
|
||||
self::assertEquals(1, $sut->count());
|
||||
self::assertEquals([$summary], $sut->getSummaries());
|
||||
self::assertInstanceOf(\Traversable::class, $sut->getIterator());
|
||||
}
|
||||
}
|
||||
45
tests/WorkingTime/Model/YearSummaryTest.php
Normal file
45
tests/WorkingTime/Model/YearSummaryTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\WorkingTime\Model;
|
||||
|
||||
use App\WorkingTime\Model\YearSummary;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\WorkingTime\Model\YearSummary
|
||||
*/
|
||||
class YearSummaryTest extends TestCase
|
||||
{
|
||||
public function testDefaults(): void
|
||||
{
|
||||
$monthDate = new \DateTimeImmutable();
|
||||
$sut = new YearSummary($monthDate, 'Foo-Bar');
|
||||
self::assertEquals('Foo-Bar', $sut->getTitle());
|
||||
self::assertEquals(0, $sut->getExpectedTime());
|
||||
self::assertEquals(0, $sut->getActualTime());
|
||||
}
|
||||
|
||||
public function testWithSummary(): void
|
||||
{
|
||||
$monthDate = new \DateTimeImmutable('2020-01-01');
|
||||
$sut = new YearSummary($monthDate, 'Foo-Bar');
|
||||
|
||||
$monthSummary = $sut->getMonth(new \DateTimeImmutable('2020-04-27'));
|
||||
$monthSummary->setActualTime(35679);
|
||||
$monthSummary->setExpectedTime(135679);
|
||||
|
||||
$monthSummary = $sut->getMonth(new \DateTimeImmutable('2020-07-27'));
|
||||
$monthSummary->setActualTime(95679);
|
||||
$monthSummary->setExpectedTime(235679);
|
||||
|
||||
self::assertEquals(131358, $sut->getActualTime());
|
||||
self::assertEquals(371358, $sut->getExpectedTime());
|
||||
}
|
||||
}
|
||||
70
tests/WorkingTime/Model/YearTest.php
Normal file
70
tests/WorkingTime/Model/YearTest.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\WorkingTime\Model;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\WorkingTime;
|
||||
use App\WorkingTime\Model\Year;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\WorkingTime\Model\Year
|
||||
*/
|
||||
class YearTest extends TestCase
|
||||
{
|
||||
public function testDefaults(): void
|
||||
{
|
||||
$year = new \DateTimeImmutable('2020-02-02');
|
||||
$user = new User();
|
||||
$user->setUserIdentifier('foooo');
|
||||
$sut = new Year($year, $user);
|
||||
|
||||
$until = new \DateTimeImmutable('2020-09-25');
|
||||
|
||||
self::assertSame($user, $sut->getUser());
|
||||
self::assertEquals(0, $sut->getActualTime());
|
||||
self::assertEquals(0, $sut->getExpectedTime($until));
|
||||
}
|
||||
|
||||
public function testWithSummary(): void
|
||||
{
|
||||
$year = new \DateTimeImmutable('2020-02-02');
|
||||
$user = new User();
|
||||
$user->setUserIdentifier('foooo');
|
||||
$sut = new Year($year, $user);
|
||||
|
||||
$until = new \DateTimeImmutable('2020-09-25');
|
||||
|
||||
self::assertSame($user, $sut->getUser());
|
||||
self::assertEquals(0, $sut->getActualTime());
|
||||
self::assertEquals(0, $sut->getExpectedTime($until));
|
||||
|
||||
$workingTime = new WorkingTime(new User(), new \DateTimeImmutable('2020-04-14'));
|
||||
$workingTime->setExpectedTime(54321);
|
||||
$workingTime->setActualTime(12345);
|
||||
$day = $sut->getMonth(new \DateTimeImmutable('2020-04-25'))->getDays()[13];
|
||||
$day->setWorkingTime($workingTime);
|
||||
|
||||
self::assertEquals(12345, $sut->getActualTime());
|
||||
self::assertEquals(54321, $sut->getExpectedTime($until));
|
||||
|
||||
$workingTime = new WorkingTime(new User(), new \DateTimeImmutable('2020-06-20'));
|
||||
$workingTime->setExpectedTime(9843);
|
||||
$workingTime->setActualTime(777);
|
||||
$day = $sut->getMonth(new \DateTimeImmutable('2020-06-25'))->getDays()[19];
|
||||
$day->setWorkingTime($workingTime);
|
||||
|
||||
self::assertEquals(13122, $sut->getActualTime());
|
||||
self::assertEquals(64164, $sut->getExpectedTime($until));
|
||||
|
||||
self::assertEquals(54321, $sut->getExpectedTime(new \DateTimeImmutable('2020-04-25')));
|
||||
self::assertEquals(0, $sut->getExpectedTime(new \DateTimeImmutable('2020-03-25')));
|
||||
}
|
||||
}
|
||||
@@ -4782,11 +4782,6 @@ parameters:
|
||||
count: 1
|
||||
path: Entity/UserTest.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Tests\\\\Entity\\\\UserTest\\:\\:testColor\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: Entity/UserTest.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Tests\\\\Entity\\\\UserTest\\:\\:testDatetime\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
|
||||
Reference in New Issue
Block a user