make sure that timezone is properly validated (#2663)

This commit is contained in:
Kevin Papst
2021-07-13 23:23:18 +02:00
committed by GitHub
parent 43a31efeac
commit 7d052eba00
9 changed files with 68 additions and 62 deletions

View File

@@ -7,7 +7,7 @@
* file that was distributed with this source code.
*/
namespace App\Tests\Validator;
namespace App\Tests\Validator\Constraints;
use App\Activity\ActivityStatisticService;
use App\Configuration\SystemConfiguration;
@@ -25,16 +25,16 @@ use App\Repository\TimesheetRepository;
use App\Timesheet\Rate;
use App\Timesheet\RateService;
use App\Timesheet\RateServiceInterface;
use App\Validator\Constraints\TimesheetBudgetUsedConstraint;
use App\Validator\TimesheetBudgetUsedValidator;
use App\Validator\Constraints\TimesheetBudgetUsed;
use App\Validator\Constraints\TimesheetBudgetUsedValidator;
use DateTime;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
* @covers \App\Validator\Constraints\TimesheetBudgetUsedConstraint
* @covers \App\Validator\TimesheetBudgetUsedValidator
* @covers \App\Validator\Constraints\TimesheetBudgetUsed
* @covers \App\Validator\Constraints\TimesheetBudgetUsedValidator
*/
class TimesheetBudgetUsedValidatorTest extends ConstraintValidatorTestCase
{
@@ -83,7 +83,7 @@ class TimesheetBudgetUsedValidatorTest extends ConstraintValidatorTestCase
$this->validator->initialize($this->context);
$this->context->addViolation('FOOOOOOOOO');
$this->validator->validate(new Timesheet(), new TimesheetBudgetUsedConstraint());
$this->validator->validate(new Timesheet(), new TimesheetBudgetUsed());
$this->buildViolation('FOOOOOOOOO')->assertRaised();
}
@@ -91,7 +91,7 @@ class TimesheetBudgetUsedValidatorTest extends ConstraintValidatorTestCase
{
$this->expectException(UnexpectedTypeException::class);
$this->validator->validate('foo', new TimesheetBudgetUsedConstraint());
$this->validator->validate('foo', new TimesheetBudgetUsed());
}
public function testWithMissingEnd()
@@ -99,7 +99,7 @@ class TimesheetBudgetUsedValidatorTest extends ConstraintValidatorTestCase
$timesheet = new Timesheet();
$timesheet->setBegin(new DateTime());
$this->validator->validate($timesheet, new TimesheetBudgetUsedConstraint());
$this->validator->validate($timesheet, new TimesheetBudgetUsed());
$this->assertNoViolation();
}
@@ -109,7 +109,7 @@ class TimesheetBudgetUsedValidatorTest extends ConstraintValidatorTestCase
$timesheet->setBegin(new DateTime());
$timesheet->setEnd(new DateTime());
$this->validator->validate($timesheet, new TimesheetBudgetUsedConstraint());
$this->validator->validate($timesheet, new TimesheetBudgetUsed());
$this->assertNoViolation();
}
@@ -120,7 +120,7 @@ class TimesheetBudgetUsedValidatorTest extends ConstraintValidatorTestCase
$timesheet->setEnd(new DateTime());
$timesheet->setUser(new User());
$this->validator->validate($timesheet, new TimesheetBudgetUsedConstraint());
$this->validator->validate($timesheet, new TimesheetBudgetUsed());
$this->assertNoViolation();
}
@@ -135,7 +135,7 @@ class TimesheetBudgetUsedValidatorTest extends ConstraintValidatorTestCase
$timesheet->setUser(new User());
$timesheet->setProject($project);
$this->validator->validate($timesheet, new TimesheetBudgetUsedConstraint());
$this->validator->validate($timesheet, new TimesheetBudgetUsed());
$this->assertNoViolation();
}
@@ -161,7 +161,7 @@ class TimesheetBudgetUsedValidatorTest extends ConstraintValidatorTestCase
$timesheet->setProject($project);
$timesheet->setActivity($activity);
$this->validator->validate($timesheet, new TimesheetBudgetUsedConstraint());
$this->validator->validate($timesheet, new TimesheetBudgetUsed());
$this->assertNoViolation();
}
@@ -372,7 +372,7 @@ class TimesheetBudgetUsedValidatorTest extends ConstraintValidatorTestCase
$this->validator = $this->createValidator(false, $activityStatistic, $projectStatistic, $customerStatistic, $rawData, $rate);
$this->validator->initialize($this->context);
$this->validator->validate($timesheet, new TimesheetBudgetUsedConstraint());
$this->validator->validate($timesheet, new TimesheetBudgetUsed());
if (null === $used && null === $budget && null === $free && $path === null) {
$this->assertNoViolation();

View File

@@ -12,10 +12,11 @@ namespace App\Tests\Validator\Constraints;
use App\Configuration\ConfigLoaderInterface;
use App\Configuration\SystemConfiguration;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Timesheet\LockdownService;
use App\Validator\Constraints\TimesheetLockdown;
use App\Validator\Constraints\TimesheetLockdownValidator;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
@@ -32,7 +33,8 @@ class TimesheetLockdownValidatorTest extends ConstraintValidatorTestCase
protected function createMyValidator(bool $allowOverwriteFull, bool $allowOverwriteGrace, ?string $start, ?string $end, ?string $grace)
{
$auth = $this->createMock(AuthorizationCheckerInterface::class);
$auth = $this->createMock(Security::class);
$auth->method('getUser')->willReturn(new User());
$auth->method('isGranted')->willReturnCallback(
function ($attributes, $subject = null) use ($allowOverwriteFull, $allowOverwriteGrace) {
switch ($attributes) {

View File

@@ -13,11 +13,12 @@ use App\Entity\Activity;
use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Tests\Mocks\TrackingModeServiceFactory;
use App\Validator\Constraints\TimesheetOverlapping;
use App\Validator\Constraints\TimesheetRestart;
use App\Validator\Constraints\TimesheetRestartValidator;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
@@ -34,12 +35,13 @@ class TimesheetRestartValidatorTest extends ConstraintValidatorTestCase
protected function createMyValidator(bool $allowed, string $trackingMode)
{
$auth = $this->createMock(AuthorizationCheckerInterface::class);
$auth = $this->createMock(Security::class);
$auth->method('getUser')->willReturn(new User());
$auth->method('isGranted')->willReturn($allowed);
$service = (new TrackingModeServiceFactory($this))->create($trackingMode);
return new TimesheetRestartValidator($service, $auth);
return new TimesheetRestartValidator($auth, $service);
}
public function testConstraintIsInvalid()