API begin and end fields for Admins (#5134)

This commit is contained in:
Kevin Papst
2024-10-25 10:47:58 +02:00
committed by GitHub
parent 31bae44f3c
commit dcc52f1a95
12 changed files with 161 additions and 47 deletions

View File

@@ -16,18 +16,22 @@ use App\Tests\Mocks\SystemConfigurationFactory;
use App\Timesheet\TrackingMode\DurationFixedBeginMode;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* @covers \App\Timesheet\TrackingMode\DurationFixedBeginMode
*/
class DurationFixedBeginModeTest extends TestCase
{
protected function createSut($default = '13:47')
private function createSut(string $default = '13:47', bool $allowApiTimes = false): DurationFixedBeginMode
{
$loader = new TestConfigLoader([]);
$configuration = SystemConfigurationFactory::create($loader, ['timesheet' => ['default_begin' => $default]]);
return new DurationFixedBeginMode($configuration);
$auth = $this->createMock(AuthorizationCheckerInterface::class);
$auth->method('isGranted')->willReturn($allowApiTimes);
return new DurationFixedBeginMode($configuration, $auth);
}
public function testDefaultValues(): void
@@ -42,6 +46,18 @@ class DurationFixedBeginModeTest extends TestCase
self::assertEquals('duration_fixed_begin', $sut->getId());
}
public function testValuesForAdmin(): void
{
$sut = $this->createSut('now', true);
self::assertFalse($sut->canEditBegin());
self::assertFalse($sut->canEditEnd());
self::assertTrue($sut->canEditDuration());
self::assertTrue($sut->canUpdateTimesWithAPI());
self::assertFalse($sut->canSeeBeginAndEndTimes());
self::assertEquals('duration_fixed_begin', $sut->getId());
}
public function testNow(): void
{
$seconds = (new \DateTime())->getTimestamp();