[TASK] Remove @author lines
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / DisjunctionValidatorTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
3
4 /* *
5 * This script belongs to the Extbase framework. *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License as published by the *
9 * Free Software Foundation, either version 3 of the License, or (at your *
10 * option) any later version. *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 /**
25 * Test case
26 */
27 class DisjunctionValidatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
28
29 /**
30 * @test
31 */
32 public function allValidatorsInTheDisjunctionAreCalledEvenIfOneReturnsNoError() {
33 $this->markTestSkipped('Needs a bugfix of Flow first.');
34 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
35 $validatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
36 $validatorObject->expects($this->once())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
37 $errors = new \TYPO3\CMS\Extbase\Error\Result();
38 $errors->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', 123));
39 $secondValidatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
40 $secondValidatorObject->expects($this->exactly(1))->method('validate')->will($this->returnValue($errors));
41 $validatorDisjunction->addValidator($validatorObject);
42 $validatorDisjunction->addValidator($secondValidatorObject);
43 $validatorDisjunction->validate('some subject');
44 }
45
46 /**
47 * @test
48 */
49 public function validateReturnsNoErrorsIfOneValidatorReturnsNoError() {
50 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
51 $validatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
52 $validatorObject->expects($this->any())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
53 $errors = new \TYPO3\CMS\Extbase\Error\Result();
54 $errors->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', 123));
55 $secondValidatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
56 $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors));
57 $validatorDisjunction->addValidator($validatorObject);
58 $validatorDisjunction->addValidator($secondValidatorObject);
59 $this->assertFalse($validatorDisjunction->validate('some subject')->hasErrors());
60 }
61
62 /**
63 * @test
64 */
65 public function validateReturnsAllErrorsIfAllValidatorsReturnErrrors() {
66 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
67 $error1 = new \TYPO3\CMS\Extbase\Error\Error('Error', 123);
68 $error2 = new \TYPO3\CMS\Extbase\Error\Error('Error2', 123);
69 $errors1 = new \TYPO3\CMS\Extbase\Error\Result();
70 $errors1->addError($error1);
71 $validatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
72 $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors1));
73 $errors2 = new \TYPO3\CMS\Extbase\Error\Result();
74 $errors2->addError($error2);
75 $secondValidatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
76 $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors2));
77 $validatorDisjunction->addValidator($validatorObject);
78 $validatorDisjunction->addValidator($secondValidatorObject);
79 $this->assertEquals(array($error1, $error2), $validatorDisjunction->validate('some subject')->getErrors());
80 }
81
82 }