diff --git a/config/validator/validation.yaml b/config/validator/validation.yaml index a562bbb5..4fc00841 100644 --- a/config/validator/validation.yaml +++ b/config/validator/validation.yaml @@ -10,11 +10,12 @@ App\Entity\Alias: maxLength: 24 App\Entity\Domain: + constraints: + - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: name properties: name: - NotNull: ~ - NotBlank: ~ - - App\Validator\Constraints\Domain: ~ App\Entity\User: properties: diff --git a/default_translations/de/validators.de.yml b/default_translations/de/validators.de.yml index 050a3f53..e93707c3 100644 --- a/default_translations/de/validators.de.yml +++ b/default_translations/de/validators.de.yml @@ -9,7 +9,6 @@ form: werden. registration-recovery-token-noack: Dieses Feld muss ausgewählt werden. invalid-token: Der Code hat ein ungültiges Format. - already-exists: "Existiert bereits." registration: voucher-invalid: Der Einladungscode ist ungültig. diff --git a/default_translations/en/validators.en.yml b/default_translations/en/validators.en.yml index 3c3c9c6a..5f87d8fc 100644 --- a/default_translations/en/validators.en.yml +++ b/default_translations/en/validators.en.yml @@ -11,7 +11,6 @@ form: invalid-token: "This token has an invalid format." twofactor-secret-invalid: "The verification code is not valid." twofactor-backup-ack-missing: "This needs to be checked." - already-exists: "Already exists." registration: voucher-invalid: "The invite code is invalid." diff --git a/src/Validator/Constraints/Domain.php b/src/Validator/Constraints/Domain.php deleted file mode 100644 index 45ff34ca..00000000 --- a/src/Validator/Constraints/Domain.php +++ /dev/null @@ -1,9 +0,0 @@ -domainRepository = $manager->getRepository(Domain::class); - } - - public function validate($value, Constraint $constraint): void - { - if (!is_string($value)) { - throw new UnexpectedTypeException($value, 'string'); - } - - if ($this->domainRepository->findByName($value) !== null) { - $this->context->addViolation('form.already-exists'); - } - } -} diff --git a/tests/Validator/Constraints/DomainValidatorTest.php b/tests/Validator/Constraints/DomainValidatorTest.php deleted file mode 100644 index d07de0de..00000000 --- a/tests/Validator/Constraints/DomainValidatorTest.php +++ /dev/null @@ -1,56 +0,0 @@ -getMockBuilder(DomainRepository::class) - ->disableOriginalConstructor() - ->getMock(); - $domainRepository->method('findByName')->willReturnCallback(function ($name) { - if ($name === $this->domain) { - return new DomainEntity(); - } - - return null; - }); - $manager = $this->getMockBuilder(EntityManagerInterface::class)->getMock(); - $manager->method('getRepository')->willReturnMap([ - [DomainEntity::class, $domainRepository], - ]); - - return new DomainValidator($manager); - } - - public function testIsNotString() - { - $this->expectException(UnexpectedTypeException::class); - - $this->validator->validate(42, new Domain()); - } - - public function testIsValid() - { - $this->validator->validate('example.com', new Domain()); - - $this->assertNoViolation(); - } - - public function testIsNotUnique() - { - $this->validator->validate($this->domain, new Domain()); - - $this->buildViolation('form.already-exists') - ->assertRaised(); - } -}