[TASK] Merge submodule linkvalidator into core
[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 * Testcase for the Disjunction Validator
25 *
26 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
27 */
28 class DisjunctionValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
29
30 /**
31 * @test
32 * @author Christopher Hlubek <hlubek@networkteam.com>
33 */
34 public function allValidatorsInTheDisjunctionAreCalledEvenIfOneReturnsNoError() {
35 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
36 $validatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
37 $validatorObject->expects($this->once())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
38 $errors = new \TYPO3\CMS\Extbase\Error\Result();
39 $errors->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', 123));
40 $secondValidatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
41 $secondValidatorObject->expects($this->exactly(1))->method('validate')->will($this->returnValue($errors));
42 $validatorDisjunction->addValidator($validatorObject);
43 $validatorDisjunction->addValidator($secondValidatorObject);
44 $validatorDisjunction->validate('some subject');
45 }
46
47 /**
48 * @test
49 * @author Christopher Hlubek <hlubek@networkteam.com>
50 */
51 public function validateReturnsNoErrorsIfOneValidatorReturnsNoError() {
52 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
53 $validatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
54 $validatorObject->expects($this->any())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
55 $errors = new \TYPO3\CMS\Extbase\Error\Result();
56 $errors->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', 123));
57 $secondValidatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
58 $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors));
59 $validatorDisjunction->addValidator($validatorObject);
60 $validatorDisjunction->addValidator($secondValidatorObject);
61 $this->assertFalse($validatorDisjunction->validate('some subject')->hasErrors());
62 }
63
64 /**
65 * @test
66 * @author Christopher Hlubek <hlubek@networkteam.com>
67 */
68 public function validateReturnsAllErrorsIfAllValidatorsReturnErrrors() {
69 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
70 $error1 = new \TYPO3\CMS\Extbase\Error\Error('Error', 123);
71 $error2 = new \TYPO3\CMS\Extbase\Error\Error('Error2', 123);
72 $errors1 = new \TYPO3\CMS\Extbase\Error\Result();
73 $errors1->addError($error1);
74 $validatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
75 $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors1));
76 $errors2 = new \TYPO3\CMS\Extbase\Error\Result();
77 $errors2->addError($error2);
78 $secondValidatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
79 $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors2));
80 $validatorDisjunction->addValidator($validatorObject);
81 $validatorDisjunction->addValidator($secondValidatorObject);
82 $this->assertEquals(array($error1, $error2), $validatorDisjunction->validate('some subject')->getErrors());
83 }
84 }
85
86 ?>