TYPO3 CMS  TYPO3_6-2
ConjunctionValidatorTest.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 
34  $proxyClassName = $this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator');
35  $conjunctionValidator = new $proxyClassName(array());
36  $mockValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface');
37  $conjunctionValidator->addValidator($mockValidator);
38  $this->assertTrue($conjunctionValidator->_get('validators')->contains($mockValidator));
39  }
40 
48  $validatorConjunction = new \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator(array());
49  $validatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
50  $validatorObject->expects($this->once())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
51  $errors = new \TYPO3\CMS\Extbase\Error\Result();
52  $errors->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', 123));
53  $secondValidatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
54  $secondValidatorObject->expects($this->once())->method('validate')->will($this->returnValue($errors));
55  $thirdValidatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
56  $thirdValidatorObject->expects($this->once())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
57  $validatorConjunction->addValidator($validatorObject);
58  $validatorConjunction->addValidator($secondValidatorObject);
59  $validatorConjunction->addValidator($thirdValidatorObject);
60  $validatorConjunction->validate('some subject');
61  }
62 
68  $validatorConjunction = new \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator(array());
69  $validatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
70  $validatorObject->expects($this->any())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
71  $secondValidatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
72  $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue(new \TYPO3\CMS\Extbase\Error\Result()));
73  $validatorConjunction->addValidator($validatorObject);
74  $validatorConjunction->addValidator($secondValidatorObject);
75  $this->assertFalse($validatorConjunction->validate('some subject')->hasErrors());
76  }
77 
84  $validatorConjunction = new \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator(array());
85  $validatorObject = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
86  $errors = new \TYPO3\CMS\Extbase\Error\Result();
87  $errors->addError(new \TYPO3\CMS\Extbase\Error\Error('Error', 123));
88  $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors));
89  $validatorConjunction->addValidator($validatorObject);
90  $this->assertTrue($validatorConjunction->validate('some subject')->hasErrors());
91  }
92 
97  public function removingAValidatorOfTheValidatorConjunctionWorks() {
99  $validatorConjunction = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array('dummy'), array(array()), '', TRUE);
100  $validator1 = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
101  $validator2 = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
102  $validatorConjunction->addValidator($validator1);
103  $validatorConjunction->addValidator($validator2);
104  $validatorConjunction->removeValidator($validator1);
105  $this->assertFalse($validatorConjunction->_get('validators')->contains($validator1));
106  $this->assertTrue($validatorConjunction->_get('validators')->contains($validator2));
107  }
108 
115  $validatorConjunction = new \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator(array());
116  $validator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
117  $validatorConjunction->removeValidator($validator);
118  }
119 
125  $validatorConjunction = new \TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator(array());
126  $validator1 = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
127  $validator2 = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array('validate'));
128  $this->assertSame(0, count($validatorConjunction));
129  $validatorConjunction->addValidator($validator1);
130  $validatorConjunction->addValidator($validator2);
131  $this->assertSame(2, count($validatorConjunction));
132  }
133 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)