‪TYPO3CMS  9.5
ConjunctionValidatorTest.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 
18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19 
23 class ‪ConjunctionValidatorTest extends UnitTestCase
24 {
29  {
30  $proxyClassName = $this->buildAccessibleProxy(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ConjunctionValidator::class);
31  $conjunctionValidator = new $proxyClassName([]);
32  $mockValidator = $this->createMock(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class);
33  $conjunctionValidator->addValidator($mockValidator);
34  $this->assertTrue($conjunctionValidator->_get('validators')->contains($mockValidator));
35  }
36 
41  {
42  $validatorConjunction = new \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator([]);
43  $validatorObject = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class)
44  ->setMethods(['validate', 'getOptions'])
45  ->getMock();
46  $validatorObject->expects($this->once())->method('validate')->will($this->returnValue(new \‪TYPO3\CMS\‪Extbase\‪Error\‪Result()));
47  ‪$errors = new \TYPO3\CMS\Extbase\Error\Result();
48  ‪$errors->addError(new \‪TYPO3\CMS\‪Extbase\‪Error\‪Error('Error', 123));
49  $secondValidatorObject = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class)
50  ->setMethods(['validate', 'getOptions'])
51  ->getMock();
52  $secondValidatorObject->expects($this->once())->method('validate')->will($this->returnValue(‪$errors));
53  $thirdValidatorObject = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class)
54  ->setMethods(['validate', 'getOptions'])
55  ->getMock();
56  $thirdValidatorObject->expects($this->once())->method('validate')->will($this->returnValue(new \‪TYPO3\CMS\‪Extbase\‪Error\‪Result()));
57  $validatorConjunction->addValidator($validatorObject);
58  $validatorConjunction->addValidator($secondValidatorObject);
59  $validatorConjunction->addValidator($thirdValidatorObject);
60  $validatorConjunction->validate('some subject');
61  }
62 
67  {
68  $validatorConjunction = new \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator([]);
69  $validatorObject = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class)
70  ->setMethods(['validate', 'getOptions'])
71  ->getMock();
72  $validatorObject->expects($this->any())->method('validate')->will($this->returnValue(new \‪TYPO3\CMS\‪Extbase\‪Error\‪Result()));
73  $secondValidatorObject = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class)
74  ->setMethods(['validate', 'getOptions'])
75  ->getMock();
76  $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue(new \‪TYPO3\CMS\‪Extbase\‪Error\‪Result()));
77  $validatorConjunction->addValidator($validatorObject);
78  $validatorConjunction->addValidator($secondValidatorObject);
79  $this->assertFalse($validatorConjunction->validate('some subject')->hasErrors());
80  }
81 
86  {
87  $validatorConjunction = new \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator([]);
88  $validatorObject = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class)
89  ->setMethods(['validate', 'getOptions'])
90  ->getMock();
91  ‪$errors = new \TYPO3\CMS\Extbase\Error\Result();
92  ‪$errors->addError(new \‪TYPO3\CMS\‪Extbase\‪Error\‪Error('Error', 123));
93  $validatorObject->expects($this->any())->method('validate')->will($this->returnValue(‪$errors));
94  $validatorConjunction->addValidator($validatorObject);
95  $this->assertTrue($validatorConjunction->validate('some subject')->hasErrors());
96  }
97 
102  {
104  $validatorConjunction = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ConjunctionValidator::class, ['dummy'], [[]], '', true);
105  $validator1 = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class)
106  ->setMethods(['validate', 'getOptions'])
107  ->getMock();
108  $validator2 = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class)
109  ->setMethods(['validate', 'getOptions'])
110  ->getMock();
111  $validatorConjunction->addValidator($validator1);
112  $validatorConjunction->addValidator($validator2);
113  $validatorConjunction->removeValidator($validator1);
114  $this->assertFalse($validatorConjunction->_get('validators')->contains($validator1));
115  $this->assertTrue($validatorConjunction->_get('validators')->contains($validator2));
116  }
117 
122  {
123  $this->expectException(NoSuchValidatorException::class);
124  $this->expectExceptionCode(1207020177);
125  $validatorConjunction = new \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator([]);
126  ‪$validator = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class)
127  ->setMethods(['validate', 'getOptions'])
128  ->getMock();
129  $validatorConjunction->removeValidator(‪$validator);
130  }
131 
136  {
137  $validatorConjunction = new \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator([]);
138  $validator1 = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class)
139  ->setMethods(['validate', 'getOptions'])
140  ->getMock();
141  $validator2 = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface::class)
142  ->setMethods(['validate', 'getOptions'])
143  ->getMock();
144  $this->assertSame(0, count($validatorConjunction));
145  $validatorConjunction->addValidator($validator1);
146  $validatorConjunction->addValidator($validator2);
147  $this->assertSame(2, count($validatorConjunction));
148  }
149 }
‪TYPO3\CMS\Extbase\Validation\Exception\NoSuchValidatorException
Definition: NoSuchValidatorException.php:21
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\ConjunctionValidatorTest\addingValidatorsToAJunctionValidatorWorks
‪addingValidatorsToAJunctionValidatorWorks()
Definition: ConjunctionValidatorTest.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\ConjunctionValidatorTest\validatorConjunctionReturnsNoErrorsIfAllJunctionedValidatorsReturnNoErrors
‪validatorConjunctionReturnsNoErrorsIfAllJunctionedValidatorsReturnNoErrors()
Definition: ConjunctionValidatorTest.php:66
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\ConjunctionValidatorTest\allValidatorsInTheConjunctionAreCalledEvenIfOneReturnsError
‪allValidatorsInTheConjunctionAreCalledEvenIfOneReturnsError()
Definition: ConjunctionValidatorTest.php:40
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\ConjunctionValidatorTest\countReturnesTheNumberOfValidatorsContainedInTheConjunction
‪countReturnesTheNumberOfValidatorsContainedInTheConjunction()
Definition: ConjunctionValidatorTest.php:135
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\ConjunctionValidatorTest\removingAValidatorOfTheValidatorConjunctionWorks
‪removingAValidatorOfTheValidatorConjunctionWorks()
Definition: ConjunctionValidatorTest.php:101
‪TYPO3\CMS\Extbase\Error\Result
Definition: Result.php:20
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\ConjunctionValidatorTest\validatorConjunctionReturnsErrorsIfOneValidatorReturnsErrors
‪validatorConjunctionReturnsErrorsIfOneValidatorReturnsErrors()
Definition: ConjunctionValidatorTest.php:85
‪TYPO3\CMS\Extbase\Error\Error
Definition: Error.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\ConjunctionValidatorTest\removingANotExistingValidatorIndexThrowsException
‪removingANotExistingValidatorIndexThrowsException()
Definition: ConjunctionValidatorTest.php:121
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\ConjunctionValidatorTest
Definition: ConjunctionValidatorTest.php:24
‪$errors
‪$errors
Definition: annotationChecker.php:115
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator
Definition: AbstractCompositeValidatorTest.php:2