Files
kimai/tests/WorkingTime/Model/MonthTest.php
Kevin Papst 677f8d776c [3.0] Update Symfony to 7.4 and dependencies, removed deprecated code, removed API password (#5622)
* deactivate deprecated auto-mapping
* use native month-picker with fallback on old browser
* bump dependencies to new major versions
* replace deprecated ARRAY column type with JSON
* named arguments
* nullable arguments
* native lazy ghosts
* update routes to use php config
* disable PHP < 8.4
* use static RTL configuration
* new qr code package
* clear out env file
* recipe updates
* fix deprecations
* preset new env variable if not existing
* bump maria db version examples
* remove deprecated api-token support
* fix validator deprecations
* remove timesheet category column
* fix broken validator autoconfiguration
* stabilize tests
* fix migration syntax compatibility
* fix doctrine deprecation
* fix datetime format
* remove constructor dependency
* only include visible preferences in invoice templates
* fix test container dependency
* removed ProjectConstraint multi-constraint logic
* allow to disable plugins in certain environments
* refactor TimesheetConstraint to non-service
* activate new interface methods
* prevent update issues with .env
* improved customer fixture
* removed $user->isExportDecimal()
2026-01-04 15:04:25 +01:00

77 lines
2.8 KiB
PHP

<?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\Month;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(Month::class)]
class MonthTest extends TestCase
{
public function testDefaults(): void
{
$user = new User();
$user->setUserIdentifier('foo-bar');
$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, $user);
self::assertEquals(\sprintf('2020-%s-25', $monthKey), $month->getMonth()->format('Y-m-d'));
self::assertCount($days, $month->getDays());
self::assertFalse($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::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());
}
self::assertFalse($month->isLocked());
foreach ($month->getDays() as $day) {
$workingTime = $day->getWorkingTime();
self::assertNotNull($workingTime);
$workingTime->setApprovedAt(new \DateTimeImmutable());
}
self::assertTrue($month->isLocked());
$day = $month->getDays()[5];
$wt = $day->getWorkingTime();
self::assertNotNull($wt);
$day->setWorkingTime(null);
self::assertFalse($month->isLocked());
$day->setWorkingTime($wt);
self::assertTrue($month->isLocked());
$wt->setApprovedAt(null);
self::assertFalse($month->isLocked());
}
}
}