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