added API for handling work contract times (#4016)
This commit is contained in:
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')));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user