TYPO3 CMS  TYPO3_7-6
DisjunctionValidatorTest.php
Go to the documentation of this file.
1 <?php
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 
28 {
33  {
34  $this->markTestSkipped('Needs a bugfix of Flow first.');
35  $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator([]);
36  $validatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, ['validate', 'getOptions']);
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::class, ['validate', 'getOptions']);
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 
51  {
52  $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator([]);
53  $validatorObject = $this->getMock(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, ['validate', 'getOptions']);
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::class, ['validate', 'getOptions']);
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 
68  {
69  $validatorDisjunction = new \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator([]);
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::class, ['validate', 'getOptions']);
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::class, ['validate', 'getOptions']);
79  $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors2));
80  $validatorDisjunction->addValidator($validatorObject);
81  $validatorDisjunction->addValidator($secondValidatorObject);
82  $this->assertEquals([$error1, $error2], $validatorDisjunction->validate('some subject')->getErrors());
83  }
84 }