‪TYPO3CMS  10.4
DisjunctionValidatorTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪DisjunctionValidatorTest extends UnitTestCase
28 {
29 
34  {
35  $validatorDisjunction = new ‪DisjunctionValidator([]);
36  $validatorObject = $this->getMockBuilder(ValidatorInterface::class)
37  ->setMethods(['validate', 'getOptions'])
38  ->getMock();
39  $validatorObject->expects(self::any())->method('validate')->willReturn(new ‪Result());
40  ‪$errors = new ‪Result();
41  ‪$errors->addError(new ‪Error('Error', 123));
42  $secondValidatorObject = $this->getMockBuilder(ValidatorInterface::class)
43  ->setMethods(['validate', 'getOptions'])
44  ->getMock();
45  $secondValidatorObject->expects(self::any())->method('validate')->willReturn(‪$errors);
46  $validatorDisjunction->addValidator($validatorObject);
47  $validatorDisjunction->addValidator($secondValidatorObject);
48  self::assertFalse($validatorDisjunction->validate('some subject')->hasErrors());
49  }
50 
55  {
56  $validatorDisjunction = new ‪DisjunctionValidator([]);
57  $error1 = new ‪Error('Error', 123);
58  $error2 = new ‪Error('Error2', 123);
59  $errors1 = new ‪Result();
60  $errors1->addError($error1);
61  $validatorObject = $this->getMockBuilder(ValidatorInterface::class)
62  ->setMethods(['validate', 'getOptions'])
63  ->getMock();
64  $validatorObject->expects(self::any())->method('validate')->willReturn($errors1);
65  $errors2 = new ‪Result();
66  $errors2->addError($error2);
67  $secondValidatorObject = $this->getMockBuilder(ValidatorInterface::class)
68  ->setMethods(['validate', 'getOptions'])
69  ->getMock();
70  $secondValidatorObject->expects(self::any())->method('validate')->willReturn($errors2);
71  $validatorDisjunction->addValidator($validatorObject);
72  $validatorDisjunction->addValidator($secondValidatorObject);
73  self::assertEquals([$error1, $error2], $validatorDisjunction->validate('some subject')->getErrors());
74  }
75 }
‪TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator
Definition: DisjunctionValidator.php:24
‪TYPO3\CMS\Extbase\Error\Result
Definition: Result.php:24
‪TYPO3\CMS\Extbase\Error\Error
Definition: Error.php:25
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\DisjunctionValidatorTest\validateReturnsNoErrorsIfOneValidatorReturnsNoError
‪validateReturnsNoErrorsIfOneValidatorReturnsNoError()
Definition: DisjunctionValidatorTest.php:33
‪$errors
‪$errors
Definition: annotationChecker.php:121
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\DisjunctionValidatorTest
Definition: DisjunctionValidatorTest.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator
Definition: AbstractCompositeValidatorTest.php:16
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\DisjunctionValidatorTest\validateReturnsAllErrorsIfAllValidatorsReturnErrors
‪validateReturnsAllErrorsIfAllValidatorsReturnErrors()
Definition: DisjunctionValidatorTest.php:54
‪TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface
Definition: ValidatorInterface.php:22