[TASK] Remove closing PHP tags
[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 $this->markTestSkipped('Needs a bugfix of Flow first.');
36 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
37 $validatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
38 $validatorObject->expects($this->once())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
39 $errors = new \TYPO3\CMS\Extbase\Error\Result();
40 $errors->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', 123));
41 $secondValidatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
42 $secondValidatorObject->expects($this->exactly(1))->method('validate')->will($this->returnValue($errors));
43 $validatorDisjunction->addValidator($validatorObject);
44 $validatorDisjunction->addValidator($secondValidatorObject);
45 $validatorDisjunction->validate('some subject');
46 }
47
48 /**
49 * @test
50 * @author Christopher Hlubek <hlubek@networkteam.com>
51 */
52 public function validateReturnsNoErrorsIfOneValidatorReturnsNoError() {
53 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
54 $validatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
55 $validatorObject->expects($this->any())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
56 $errors = new \TYPO3\CMS\Extbase\Error\Result();
57 $errors->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', 123));
58 $secondValidatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
59 $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors));
60 $validatorDisjunction->addValidator($validatorObject);
61 $validatorDisjunction->addValidator($secondValidatorObject);
62 $this->assertFalse($validatorDisjunction->validate('some subject')->hasErrors());
63 }
64
65 /**
66 * @test
67 * @author Christopher Hlubek <hlubek@networkteam.com>
68 */
69 public function validateReturnsAllErrorsIfAllValidatorsReturnErrrors() {
70 $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator(array());
71 $error1 = new \TYPO3\CMS\Extbase\Error\Error('Error', 123);
72 $error2 = new \TYPO3\CMS\Extbase\Error\Error('Error2', 123);
73 $errors1 = new \TYPO3\CMS\Extbase\Error\Result();
74 $errors1->addError($error1);
75 $validatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
76 $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors1));
77 $errors2 = new \TYPO3\CMS\Extbase\Error\Result();
78 $errors2->addError($error2);
79 $secondValidatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
80 $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors2));
81 $validatorDisjunction->addValidator($validatorObject);
82 $validatorDisjunction->addValidator($secondValidatorObject);
83 $this->assertEquals(array($error1, $error2), $validatorDisjunction->validate('some subject')->getErrors());
84 }
85 }