mirror of
https://github.com/kevinpapst/kimai2.git
synced 2025-04-07 22:45:50 +00:00
do not trigger export validation on new timesheets
This commit is contained in:
parent
c040af8983
commit
42e6b7818b
2 changed files with 21 additions and 2 deletions
src/Validator/Constraints
tests/Validator/Constraints
|
@ -38,6 +38,10 @@ final class TimesheetExportedValidator extends ConstraintValidator
|
|||
throw new UnexpectedTypeException($timesheet, TimesheetEntity::class);
|
||||
}
|
||||
|
||||
if ($timesheet->getId() === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$timesheet->isExported()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -66,8 +66,9 @@ class TimesheetExportedValidatorTest extends ConstraintValidatorTestCase
|
|||
$this->validator = $this->createMyValidator(false);
|
||||
$this->validator->initialize($this->context);
|
||||
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet->setExported(true);
|
||||
$timesheet = $this->createMock(Timesheet::class);
|
||||
$timesheet->method('isExported')->willReturn(true);
|
||||
$timesheet->method('getId')->willReturn(1);
|
||||
|
||||
$this->validator->validate($timesheet, new TimesheetExported());
|
||||
|
||||
|
@ -77,6 +78,20 @@ class TimesheetExportedValidatorTest extends ConstraintValidatorTestCase
|
|||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testNotTriggersOnNewTimesheet()
|
||||
{
|
||||
$this->validator = $this->createMyValidator(false);
|
||||
$this->validator->initialize($this->context);
|
||||
|
||||
$timesheet = $this->createMock(Timesheet::class);
|
||||
$timesheet->method('isExported')->willReturn(true);
|
||||
$timesheet->method('getId')->willReturn(null);
|
||||
|
||||
$this->validator->validate($timesheet, new TimesheetExported());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testDoesNotTriggerWithPermission()
|
||||
{
|
||||
$this->validator = $this->createMyValidator(true);
|
||||
|
|
Loading…
Add table
Reference in a new issue