DigiComp.SettingValidator/Tests/Functional/SettingsValidatorTest.php

80 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2017-06-02 21:58:33 +02:00
<?php
2020-03-10 14:48:57 +01:00
2022-05-02 09:56:09 +02:00
declare(strict_types=1);
2017-06-02 21:58:33 +02:00
namespace DigiComp\SettingValidator\Tests\Functional;
use DigiComp\SettingValidator\Tests\Functional\Fixtures\TestObject;
use DigiComp\SettingValidator\Tests\Functional\Fixtures\TestValidationGroupsCustomObject;
use DigiComp\SettingValidator\Tests\Functional\Fixtures\TestValidationGroupsDefaultObject;
2017-06-02 21:58:33 +02:00
use DigiComp\SettingValidator\Validation\Validator\SettingsValidator;
use Neos\Flow\Tests\FunctionalTestCase;
2020-05-14 14:43:09 +02:00
use Neos\Flow\Validation\Exception\InvalidValidationConfigurationException;
use Neos\Flow\Validation\Exception\InvalidValidationOptionsException;
use Neos\Flow\Validation\Exception\NoSuchValidatorException;
2017-06-02 21:58:33 +02:00
use Neos\Flow\Validation\ValidatorResolver;
class SettingsValidatorTest extends FunctionalTestCase
{
/**
* @test
2020-05-14 14:43:09 +02:00
* @throws InvalidValidationOptionsException
2017-06-02 21:58:33 +02:00
*/
2020-07-22 17:22:46 +02:00
public function ifNoNameIsGivenClassNameIsUsed(): void
2017-06-02 21:58:33 +02:00
{
2022-04-04 22:36:48 +02:00
$result = $this->objectManager->get(SettingsValidator::class)->validate(new TestObject());
2022-04-20 17:36:29 +02:00
self::assertTrue($result->hasErrors());
self::assertCount(1, $result->getFlattenedErrors());
self::assertCount(1, $result->forProperty('shouldBeFalse')->getErrors());
2017-06-02 21:58:33 +02:00
}
/**
* @test
2020-05-14 14:43:09 +02:00
* @throws InvalidValidationConfigurationException
* @throws InvalidValidationOptionsException
* @throws NoSuchValidatorException
2017-06-02 21:58:33 +02:00
*/
2020-07-22 17:22:46 +02:00
public function conjunctionValidationWorksAsExpected(): void
2017-06-02 21:58:33 +02:00
{
2022-04-04 22:36:48 +02:00
$result = $this->objectManager
->get(ValidatorResolver::class)
->getBaseValidatorConjunction(TestObject::class)
->validate(new TestObject());
2022-04-20 17:36:29 +02:00
self::assertTrue($result->hasErrors());
self::assertCount(1, $result->getFlattenedErrors());
2024-09-04 15:58:08 +02:00
self::assertCount(1, $result->forProperty('shouldBeTrueAndValidatedByAnnotation')->getErrors());
2017-06-02 21:58:33 +02:00
}
/**
* @test
2020-05-14 14:43:09 +02:00
* @throws InvalidValidationOptionsException
*/
2020-07-22 17:22:46 +02:00
public function defaultValidationGroupWorks(): void
{
2022-04-04 22:36:48 +02:00
$result = $this->objectManager
->get(SettingsValidator::class, ['validationGroups' => ['Default']])
->validate(new TestValidationGroupsDefaultObject());
2022-04-20 17:36:29 +02:00
self::assertTrue($result->hasErrors(), 'No errors for validation group "Default"');
self::assertCount(1, $result->getFlattenedErrors(), 'Got a non expected number of errors for group "Default"');
self::assertCount(1, $result->forProperty('shouldBeTrue')->getErrors(), 'Got no error for property');
}
/**
* @test
2020-05-14 14:43:09 +02:00
* @throws InvalidValidationOptionsException
*/
2020-07-22 17:22:46 +02:00
public function customValidationGroupWorks(): void
{
2022-04-04 22:36:48 +02:00
$result = $this->objectManager
->get(SettingsValidator::class, ['validationGroups' => ['Custom']])
->validate(new TestValidationGroupsCustomObject());
2022-04-20 17:36:29 +02:00
self::assertTrue($result->hasErrors(), 'No errors for validation group "Custom"');
self::assertCount(1, $result->getFlattenedErrors(), 'Got a non expected number of errors for group "Custom"');
self::assertCount(1, $result->forProperty('shouldBeFalse')->getErrors(), 'Got no error for property');
}
2017-06-02 21:58:33 +02:00
}