2017-06-02 21:58:33 +02:00
|
|
|
<?php
|
2020-03-10 14:48:57 +01:00
|
|
|
|
2017-06-02 21:58:33 +02:00
|
|
|
namespace DigiComp\SettingValidator\Tests\Functional;
|
|
|
|
|
|
|
|
use DigiComp\SettingValidator\Tests\Functional\Fixtures\TestObject;
|
2017-07-03 10:11:18 +02:00
|
|
|
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
|
|
|
*/
|
|
|
|
public function ifNoNameIsGivenClassNameIsUsed()
|
|
|
|
{
|
|
|
|
$validator = $this->objectManager->get(SettingsValidator::class);
|
|
|
|
$result = $validator->validate(new TestObject());
|
|
|
|
$this->assertTrue($result->hasErrors());
|
|
|
|
$this->assertCount(1, $result->getFlattenedErrors());
|
|
|
|
$this->assertCount(1, $result->forProperty('shouldBeFalse')->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2020-05-14 14:43:09 +02:00
|
|
|
* @throws InvalidValidationConfigurationException
|
|
|
|
* @throws InvalidValidationOptionsException
|
|
|
|
* @throws NoSuchValidatorException
|
2017-06-02 21:58:33 +02:00
|
|
|
*/
|
|
|
|
public function conjunctionValidationWorksAsExpected()
|
|
|
|
{
|
|
|
|
$validatorResolver = $this->objectManager->get(ValidatorResolver::class);
|
|
|
|
$validator = $validatorResolver->getBaseValidatorConjunction(TestObject::class);
|
|
|
|
$result = $validator->validate(new TestObject());
|
|
|
|
$this->assertTrue($result->hasErrors());
|
|
|
|
$this->assertCount(1, $result->getFlattenedErrors());
|
|
|
|
}
|
2017-07-03 10:11:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2020-05-14 14:43:09 +02:00
|
|
|
* @throws InvalidValidationOptionsException
|
2017-07-03 10:11:18 +02:00
|
|
|
*/
|
2017-07-19 12:54:29 +02:00
|
|
|
public function defaultValidationGroupWorks()
|
2017-07-03 10:11:18 +02:00
|
|
|
{
|
2017-07-19 12:54:29 +02:00
|
|
|
$validator = $this->objectManager->get(SettingsValidator::class, ['validationGroups' => ['Default']]);
|
2017-07-03 10:11:18 +02:00
|
|
|
$result = $validator->validate(new TestValidationGroupsDefaultObject());
|
|
|
|
$this->assertTrue($result->hasErrors(), 'No Errors for validation group "Default"');
|
|
|
|
$this->assertCount(1, $result->getFlattenedErrors(), 'Got a non expected number of errors for group "Default"');
|
2017-07-19 12:55:31 +02:00
|
|
|
$this->assertCount(1, $result->forProperty('shouldBeTrue')->getErrors(), 'Got no error for property');
|
2017-07-19 12:54:29 +02:00
|
|
|
}
|
2017-07-03 10:11:18 +02:00
|
|
|
|
2017-07-19 12:54:29 +02:00
|
|
|
/**
|
|
|
|
* @test
|
2020-05-14 14:43:09 +02:00
|
|
|
* @throws InvalidValidationOptionsException
|
2017-07-19 12:54:29 +02:00
|
|
|
*/
|
|
|
|
public function customValidationGroupWorks()
|
|
|
|
{
|
|
|
|
$validator = $this->objectManager->get(SettingsValidator::class, ['validationGroups' => ['Custom']]);
|
2017-07-03 10:11:18 +02:00
|
|
|
$result = $validator->validate(new TestValidationGroupsCustomObject());
|
|
|
|
$this->assertTrue($result->hasErrors(), 'No Errors for validation group "Custom"');
|
|
|
|
$this->assertCount(1, $result->getFlattenedErrors(), 'Got a non expected number of errors for group "Custom"');
|
2017-07-19 12:55:31 +02:00
|
|
|
$this->assertCount(1, $result->forProperty('shouldBeFalse')->getErrors(), 'Got no error for property');
|
2017-07-03 10:11:18 +02:00
|
|
|
}
|
2017-06-02 21:58:33 +02:00
|
|
|
}
|