[CLEANUP] Rework/simplify copyright header and remove @package
[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 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 /**
18 * Test case
19 */
20 class DisjunctionValidatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @test
24 * @author Christopher Hlubek <hlubek@networkteam.com>
25 */
26 public function allValidatorsInTheDisjunctionAreCalledEvenIfOneReturnsNoError() {
27 $this->markTestSkipped('Needs a bugfix of Flow first.');
28 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
29 $validatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
30 $validatorObject->expects($this->once())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
31 $errors = new \TYPO3\CMS\Extbase\Error\Result();
32 $errors->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', 123));
33 $secondValidatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
34 $secondValidatorObject->expects($this->exactly(1))->method('validate')->will($this->returnValue($errors));
35 $validatorDisjunction->addValidator($validatorObject);
36 $validatorDisjunction->addValidator($secondValidatorObject);
37 $validatorDisjunction->validate('some subject');
38 }
39
40 /**
41 * @test
42 * @author Christopher Hlubek <hlubek@networkteam.com>
43 */
44 public function validateReturnsNoErrorsIfOneValidatorReturnsNoError() {
45 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
46 $validatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
47 $validatorObject->expects($this->any())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
48 $errors = new \TYPO3\CMS\Extbase\Error\Result();
49 $errors->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', 123));
50 $secondValidatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
51 $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors));
52 $validatorDisjunction->addValidator($validatorObject);
53 $validatorDisjunction->addValidator($secondValidatorObject);
54 $this->assertFalse($validatorDisjunction->validate('some subject')->hasErrors());
55 }
56
57 /**
58 * @test
59 * @author Christopher Hlubek <hlubek@networkteam.com>
60 */
61 public function validateReturnsAllErrorsIfAllValidatorsReturnErrrors() {
62 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
63 $error1 = new \TYPO3\CMS\Extbase\Error\Error('Error', 123);
64 $error2 = new \TYPO3\CMS\Extbase\Error\Error('Error2', 123);
65 $errors1 = new \TYPO3\CMS\Extbase\Error\Result();
66 $errors1->addError($error1);
67 $validatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
68 $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors1));
69 $errors2 = new \TYPO3\CMS\Extbase\Error\Result();
70 $errors2->addError($error2);
71 $secondValidatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, array('validate', 'getOptions'));
72 $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors2));
73 $validatorDisjunction->addValidator($validatorObject);
74 $validatorDisjunction->addValidator($secondValidatorObject);
75 $this->assertEquals(array($error1, $error2), $validatorDisjunction->validate('some subject')->getErrors());
76 }
77
78 }